The Gaudi Framework  v30r3 (a5ef0a68)
SystemWin32.cpp
Go to the documentation of this file.
1 
2 // System include(s):
3 #include <cstring>
4 #include <sstream>
5 #include <windows.h>
6 
7 // Local include(s):
8 #include "SystemWin32.h"
9 
10 // Disable warning C4996 triggered by C standard library calls
11 #pragma warning( disable : 4996 )
12 
13 namespace System
14 {
15  namespace Win32
16  {
17 
19  {
20 
21  // The result object:
23 
24  // For compatibility with UNIX we CANNOT use strtok!
25  // If we would use strtok, options like -g="My world" at
26  // the command line level would result on NT in TWO options
27  // instead in one as in UNIX.
28  char exe[1024];
29  char *next, *tmp1, *tmp2;
30  for ( LPTSTR cmd = ::GetCommandLine(); *cmd; cmd = next ) {
31  ::memset( exe, 0, sizeof( exe ) );
32  while ( *cmd == ' ' ) cmd++;
33  next = ::strchr( cmd, ' ' );
34  if ( !next ) next = cmd + ::strlen( cmd );
35  if ( ( tmp1 = ::strchr( cmd, '\"' ) ) > 0 && tmp1 < next ) {
36  tmp2 = ::strchr( ++tmp1, '\"' );
37  if ( tmp2 > 0 ) {
38  next = ++tmp2;
39  if ( cmd < tmp1 ) ::strncpy( exe, cmd, tmp1 - cmd - 1 );
40  ::strncpy( &exe[strlen( exe )], tmp1, tmp2 - tmp1 - 1 );
41  } else {
42  std::cout << "Mismatched \" in command line arguments" << std::endl;
43  return std::vector<std::string>();
44  }
45  } else {
46  ::strncpy( exe, cmd, next - cmd );
47  }
48  result.push_back( exe );
49  }
50 
51  return result;
52  }
53 
54  std::string typeinfoName( const char* class_name )
55  {
56 
57  // The result variable:
58  std::string result;
59 
60  long off = 0;
61  if (::strncmp( class_name, "class ", 6 ) == 0 ) {
62  // The returned name is prefixed with "class "
63  off = 6;
64  }
65  if (::strncmp( class_name, "struct ", 7 ) == 0 ) {
66  // The returned name is prefixed with "struct "
67  off = 7;
68  }
69  if ( off > 0 ) {
70  std::string tmp = class_name + off;
71  long loc = 0;
72  while ( ( loc = tmp.find( "class " ) ) > 0 ) {
73  tmp.erase( loc, 6 );
74  }
75  loc = 0;
76  while ( ( loc = tmp.find( "struct " ) ) > 0 ) {
77  tmp.erase( loc, 7 );
78  }
79  result = tmp;
80  } else {
81  result = class_name;
82  }
83  // Change any " *" to "*"
84  while ( ( off = result.find( " *" ) ) != std::string::npos ) {
85  result.replace( off, 2, "*" );
86  }
87  // Change any " &" to "&"
88  while ( ( off = result.find( " &" ) ) != std::string::npos ) {
89  result.replace( off, 2, "&" );
90  }
91 
92  return result;
93  }
94 
96  {
97 
98  static const size_t STRING_SIZE = 512;
99  char hname[STRING_SIZE];
100  size_t strlen = STRING_SIZE;
101  if ( !::GetComputerName( hname, &strlen ) ) {
102  return "UNKNOWN";
103  }
104  return std::string( hname );
105  }
106 
107  std::string osName() { return "Windows"; }
108 
110  {
111 
112  OSVERSIONINFO ut;
113  ut.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
114  if ( !::GetVersionEx( &ut ) ) {
115  return "UNKNOWN";
116  }
117  std::ostringstream ver;
118  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
119  return ver.str();
120  }
121 
123  {
124 
125  SYSTEM_INFO ut;
126  ::GetSystemInfo( &ut );
127  std::ostringstream arch;
128  arch << ut.wProcessorArchitecture;
129  return arch.str();
130  }
131 
133  {
134 
135  static const size_t STRING_SIZE = 512;
136  char uname[STRING_SIZE];
137  size_t strlen = STRING_SIZE;
138  if ( !::GetUserName( uname, &strlen ) ) {
139  return "UNKNOWN";
140  }
141  return std::string( uname );
142  }
143 
144  } // namespace Win32
145 } // namespace System
std::string hostName()
Get the system&#39;s host name.
Definition: SystemWin32.cpp:95
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
T endl(T...args)
std::string typeinfoName(const char *class_name)
Get the human readable type name from a typeinfo name.
Definition: SystemWin32.cpp:54
STL class.
T push_back(T...args)
std::string machineType()
Get the runner machine&#39;s type.
T replace(T...args)
std::string osName()
Get the operating system&#39;s name.
T erase(T...args)
T find(T...args)
std::string accountName()
Get the account name of the current user.
std::string osVersion()
Get the operating system&#39;s version.
std::vector< std::string > cmdLineArgs()
Get the command line arguments of the process.
Definition: SystemWin32.cpp:18