OpenMPCD
HostInformation.cpp
2 
4 
5 #include <boost/asio/ip/host_name.hpp>
6 
7 #include <ctime>
8 
9 namespace OpenMPCD
10 {
11 namespace Utility
12 {
13 namespace HostInformation
14 {
15 
16 const std::string getHostname()
17 {
18  return boost::asio::ip::host_name();
19 }
20 
21 const std::string getCurrentUTCTimeAsString()
22 {
23  static const std::size_t bufferSize = 32;
24 
25  const std::time_t t = std::time(0);
26 
27  char buffer[bufferSize + 1] = {0};
28 
29  const std::size_t ret =
30  std::strftime(buffer, bufferSize, "%Y-%m-%dT%H:%M:%S", std::gmtime(&t));
31 
32  if(ret == 0)
33  OPENMPCD_THROW(Exception, "Call to `std::strftime` failed.");
34 
35  return buffer;
36 }
37 
38 } //namespace HostInformation
39 } //namespace Utility
40 } //namespace OpenMPCD
HostInformation.hpp
Exceptions.hpp
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::Utility::HostInformation::getCurrentUTCTimeAsString
const std::string getCurrentUTCTimeAsString()
Returns the current time in UTC as a string, formatted as YYYY-MM-DDTHH:MM:SS.
Definition: HostInformation.cpp:21
OpenMPCD::Utility::HostInformation::getHostname
const std::string getHostname()
Returns the hostname of the machine this program is being executed on.
Definition: HostInformation.cpp:16
OpenMPCD::Exception
The base exception class for OpenMPCD.
Definition: Exceptions.hpp:37