The Gaudi Framework  master (37c0b60a)
System::Win32 Namespace Reference

Namespace holding Windows specific functions. More...

Functions

std::vector< std::stringcmdLineArgs ()
 Get the command line arguments of the process. More...
 
std::string typeinfoName (const char *name)
 Get the human readable type name from a typeinfo name. More...
 
std::string hostName ()
 Get the system's host name. More...
 
std::string osName ()
 Get the operating system's name. More...
 
std::string osVersion ()
 Get the operating system's version. More...
 
std::string machineType ()
 Get the runner machine's type. More...
 
std::string accountName ()
 Get the account name of the current user. More...
 

Detailed Description

Namespace holding Windows specific functions.

Function Documentation

◆ accountName()

std::string System::Win32::accountName ( )

Get the account name of the current user.

Definition at line 123 of file SystemWin32.cpp.

123  {
124 
125  static const size_t STRING_SIZE = 512;
126  char uname[STRING_SIZE];
127  size_t strlen = STRING_SIZE;
128  if ( !::GetUserName( uname, &strlen ) ) { return "UNKNOWN"; }
129  return std::string( uname );
130  }

◆ cmdLineArgs()

std::vector< std::string > System::Win32::cmdLineArgs ( )

Get the command line arguments of the process.

Definition at line 26 of file SystemWin32.cpp.

26  {
27 
28  // The result object:
30 
31  // For compatibility with UNIX we CANNOT use strtok!
32  // If we would use strtok, options like -g="My world" at
33  // the command line level would result on NT in TWO options
34  // instead in one as in UNIX.
35  char exe[1024];
36  char *next, *tmp1, *tmp2;
37  for ( LPTSTR cmd = ::GetCommandLine(); *cmd; cmd = next ) {
38  ::memset( exe, 0, sizeof( exe ) );
39  while ( *cmd == ' ' ) cmd++;
40  next = ::strchr( cmd, ' ' );
41  if ( !next ) next = cmd + ::strlen( cmd );
42  if ( ( tmp1 = ::strchr( cmd, '\"' ) ) > 0 && tmp1 < next ) {
43  tmp2 = ::strchr( ++tmp1, '\"' );
44  if ( tmp2 > 0 ) {
45  next = ++tmp2;
46  if ( cmd < tmp1 ) ::strncpy( exe, cmd, tmp1 - cmd - 1 );
47  ::strncpy( &exe[strlen( exe )], tmp1, tmp2 - tmp1 - 1 );
48  } else {
49  std::cout << "Mismatched \" in command line arguments" << std::endl;
50  return std::vector<std::string>();
51  }
52  } else {
53  ::strncpy( exe, cmd, next - cmd );
54  }
55  result.push_back( exe );
56  }
57 
58  return result;
59  }

◆ hostName()

std::string System::Win32::hostName ( )

Get the system's host name.

Definition at line 93 of file SystemWin32.cpp.

93  {
94 
95  static const size_t STRING_SIZE = 512;
96  char hname[STRING_SIZE];
97  size_t strlen = STRING_SIZE;
98  if ( !::GetComputerName( hname, &strlen ) ) { return "UNKNOWN"; }
99  return std::string( hname );
100  }

◆ machineType()

std::string System::Win32::machineType ( )

Get the runner machine's type.

Definition at line 114 of file SystemWin32.cpp.

114  {
115 
116  SYSTEM_INFO ut;
117  ::GetSystemInfo( &ut );
118  std::ostringstream arch;
119  arch << ut.wProcessorArchitecture;
120  return arch.str();
121  }

◆ osName()

std::string System::Win32::osName ( )

Get the operating system's name.

Definition at line 102 of file SystemWin32.cpp.

102 { return "Windows"; }

◆ osVersion()

std::string System::Win32::osVersion ( )

Get the operating system's version.

Definition at line 104 of file SystemWin32.cpp.

104  {
105 
106  OSVERSIONINFO ut;
107  ut.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
108  if ( !::GetVersionEx( &ut ) ) { return "UNKNOWN"; }
109  std::ostringstream ver;
110  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
111  return ver.str();
112  }

◆ typeinfoName()

std::string System::Win32::typeinfoName ( const char *  class_name)

Get the human readable type name from a typeinfo name.

Definition at line 61 of file SystemWin32.cpp.

61  {
62 
63  // The result variable:
64  std::string result;
65 
66  long off = 0;
67  if ( ::strncmp( class_name, "class ", 6 ) == 0 ) {
68  // The returned name is prefixed with "class "
69  off = 6;
70  }
71  if ( ::strncmp( class_name, "struct ", 7 ) == 0 ) {
72  // The returned name is prefixed with "struct "
73  off = 7;
74  }
75  if ( off > 0 ) {
76  std::string tmp = class_name + off;
77  long loc = 0;
78  while ( ( loc = tmp.find( "class " ) ) > 0 ) { tmp.erase( loc, 6 ); }
79  loc = 0;
80  while ( ( loc = tmp.find( "struct " ) ) > 0 ) { tmp.erase( loc, 7 ); }
81  result = tmp;
82  } else {
83  result = class_name;
84  }
85  // Change any " *" to "*"
86  while ( ( off = result.find( " *" ) ) != std::string::npos ) { result.replace( off, 2, "*" ); }
87  // Change any " &" to "&"
88  while ( ( off = result.find( " &" ) ) != std::string::npos ) { result.replace( off, 2, "&" ); }
89 
90  return result;
91  }
std::strlen
T strlen(T... args)
std::string
STL class.
std::vector< std::string >
std::string::find
T find(T... args)
std::string::replace
T replace(T... args)
std::vector::push_back
T push_back(T... args)
std::strchr
T strchr(T... args)
std::cout
std::string::erase
T erase(T... args)
std::ostringstream
STL class.
std::strncmp
T strncmp(T... args)
std::endl
T endl(T... args)
std::ostringstream::str
T str(T... args)
std::next
T next(T... args)