BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SysUtils.cpp
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Base/Utils/SysUtils.cpp
6 //! @brief Implements various stuff in namespace Utils.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #include "Base/Utils/SysUtils.h"
16 #include <chrono>
17 #include <iomanip>
18 #include <iostream>
19 #include <sstream>
20 #include <stdexcept>
21 
23 {
24  using clock = std::chrono::system_clock;
25 
26  std::stringstream output;
27  std::time_t current_time = clock::to_time_t(clock::now());
28  output << std::put_time(std::gmtime(&current_time), "%Y-%b-%d %T");
29  return output.str();
30 }
31 
32 //! enables exception throw in the case of NaN, Inf
34 {
35 #ifdef DEBUG_FPE
36 #ifndef _WIN32
37  std::cout << "SysUtils::EnableFloatingPointExceptions() -> "
38  "Enabling floating point exception debugging\n";
39  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
40 // feenableexcept(-1);
41 #endif // _WIN32
42 #else
43  std::cout << "SysUtils::EnableFloatingPointExceptions() -> "
44  "Can't enable floating point exceptions. Available in debug mode only.\n";
45 #endif
46 }
47 
48 std::string SysUtils::getenv(const std::string& name)
49 {
50  if (char* c = std::getenv(name.c_str()))
51  return c;
52  else
53  return "";
54 }
55 
57 {
58 #ifdef _WIN32
59  return true;
60 #else
61  return false;
62 #endif
63 }
Defines various stuff in namespace Utils.
std::string getCurrentDateAndTime()
Definition: SysUtils.cpp:22
std::string getenv(const std::string &name)
Returns environment variable.
Definition: SysUtils.cpp:48
void enableFloatingPointExceptions()
Enables exception throw in the case of NaN, Inf.
Definition: SysUtils.cpp:33
bool isWindowsHost()
Returns true if operation system is Windows.
Definition: SysUtils.cpp:56