The Gaudi Framework  v40r0 (475e45c1)
System::Win32 Namespace Reference

Namespace holding Windows specific functions. More...

Functions

std::vector< std::string > cmdLineArgs ()
 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 120 of file SystemWin32.cpp.

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

◆ cmdLineArgs()

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

Get the command line arguments of the process.

Definition at line 23 of file SystemWin32.cpp.

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

◆ hostName()

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

Get the system's host name.

Definition at line 90 of file SystemWin32.cpp.

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

◆ machineType()

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

Get the runner machine's type.

Definition at line 111 of file SystemWin32.cpp.

111  {
112 
113  SYSTEM_INFO ut;
114  ::GetSystemInfo( &ut );
115  std::ostringstream arch;
116  arch << ut.wProcessorArchitecture;
117  return arch.str();
118  }

◆ osName()

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

Get the operating system's name.

Definition at line 99 of file SystemWin32.cpp.

99 { return "Windows"; }

◆ osVersion()

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

Get the operating system's version.

Definition at line 101 of file SystemWin32.cpp.

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

◆ typeinfoName()

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

Get the human readable type name from a typeinfo name.

Definition at line 58 of file SystemWin32.cpp.

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