Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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  namespace Win32 {
15 
17 
18  // The result object:
20 
21  // For compatibility with UNIX we CANNOT use strtok!
22  // If we would use strtok, options like -g="My world" at
23  // the command line level would result on NT in TWO options
24  // instead in one as in UNIX.
25  char exe[1024];
26  char *next, *tmp1, *tmp2;
27  for ( LPTSTR cmd = ::GetCommandLine(); *cmd; cmd = next ) {
28  ::memset( exe, 0, sizeof( exe ) );
29  while ( *cmd == ' ' ) cmd++;
30  next = ::strchr( cmd, ' ' );
31  if ( !next ) next = cmd + ::strlen( cmd );
32  if ( ( tmp1 = ::strchr( cmd, '\"' ) ) > 0 && tmp1 < next ) {
33  tmp2 = ::strchr( ++tmp1, '\"' );
34  if ( tmp2 > 0 ) {
35  next = ++tmp2;
36  if ( cmd < tmp1 ) ::strncpy( exe, cmd, tmp1 - cmd - 1 );
37  ::strncpy( &exe[strlen( exe )], tmp1, tmp2 - tmp1 - 1 );
38  } else {
39  std::cout << "Mismatched \" in command line arguments" << std::endl;
40  return std::vector<std::string>();
41  }
42  } else {
43  ::strncpy( exe, cmd, next - cmd );
44  }
45  result.push_back( exe );
46  }
47 
48  return result;
49  }
50 
51  std::string typeinfoName( const char* class_name ) {
52 
53  // The result variable:
54  std::string result;
55 
56  long off = 0;
57  if ( ::strncmp( class_name, "class ", 6 ) == 0 ) {
58  // The returned name is prefixed with "class "
59  off = 6;
60  }
61  if ( ::strncmp( class_name, "struct ", 7 ) == 0 ) {
62  // The returned name is prefixed with "struct "
63  off = 7;
64  }
65  if ( off > 0 ) {
66  std::string tmp = class_name + off;
67  long loc = 0;
68  while ( ( loc = tmp.find( "class " ) ) > 0 ) { tmp.erase( loc, 6 ); }
69  loc = 0;
70  while ( ( loc = tmp.find( "struct " ) ) > 0 ) { tmp.erase( loc, 7 ); }
71  result = tmp;
72  } else {
73  result = class_name;
74  }
75  // Change any " *" to "*"
76  while ( ( off = result.find( " *" ) ) != std::string::npos ) { result.replace( off, 2, "*" ); }
77  // Change any " &" to "&"
78  while ( ( off = result.find( " &" ) ) != std::string::npos ) { result.replace( off, 2, "&" ); }
79 
80  return result;
81  }
82 
84 
85  static const size_t STRING_SIZE = 512;
86  char hname[STRING_SIZE];
87  size_t strlen = STRING_SIZE;
88  if ( !::GetComputerName( hname, &strlen ) ) { return "UNKNOWN"; }
89  return std::string( hname );
90  }
91 
92  std::string osName() { return "Windows"; }
93 
95 
96  OSVERSIONINFO ut;
97  ut.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
98  if ( !::GetVersionEx( &ut ) ) { return "UNKNOWN"; }
100  ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
101  return ver.str();
102  }
103 
105 
106  SYSTEM_INFO ut;
107  ::GetSystemInfo( &ut );
108  std::ostringstream arch;
109  arch << ut.wProcessorArchitecture;
110  return arch.str();
111  }
112 
114 
115  static const size_t STRING_SIZE = 512;
116  char uname[STRING_SIZE];
117  size_t strlen = STRING_SIZE;
118  if ( !::GetUserName( uname, &strlen ) ) { return "UNKNOWN"; }
119  return std::string( uname );
120  }
121 
122  } // namespace Win32
123 } // namespace System
std::string hostName()
Get the system&#39;s host name.
Definition: SystemWin32.cpp:83
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:51
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.
Definition: SystemWin32.cpp:92
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.
Definition: SystemWin32.cpp:94
std::vector< std::string > cmdLineArgs()
Get the command line arguments of the process.
Definition: SystemWin32.cpp:16