| The Gaudi Framework v32r1 (f65d50dc)

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
16 std::vector<std::string> cmdLineArgs() {
17
18 // The result object:
19 std::vector<std::string> result;
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
83 std::string hostName() {
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
94 std::string osVersion() {
95
96 OSVERSIONINFO ut;
97 ut.dwOSVersionInfoSize = sizeof( OSVERSIONINFO );
98 if ( !::GetVersionEx( &ut ) ) { return "UNKNOWN"; }
99 std::ostringstream ver;
100 ver << ut.dwMajorVersion << '.' << ut.dwMinorVersion;
101 return ver.str();
102 }
103
104 std::string machineType() {
105
106 SYSTEM_INFO ut;
107 ::GetSystemInfo( &ut );
108 std::ostringstream arch;
109 arch << ut.wProcessorArchitecture;
110 return arch.str();
111 }
112
113 std::string accountName() {
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
System::Win32::hostName
std::string hostName()
Get the system's host name.
Definition: SystemWin32.cpp:83
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
std::endl
T endl(T... args)
System::Win32::typeinfoName
std::string typeinfoName(const char *class_name)
Get the human readable type name from a typeinfo name.
Definition: SystemWin32.cpp:51
std::string
STL class.
std::vector::push_back
T push_back(T... args)
System::Win32::machineType
std::string machineType()
Get the runner machine's type.
Definition: SystemWin32.cpp:104
std::string::replace
T replace(T... args)
std::ostringstream
STL class.
System::Win32::osName
std::string osName()
Get the operating system's name.
Definition: SystemWin32.cpp:92
std::string::erase
T erase(T... args)
std::ostringstream::str
T str(T... args)
std::string::find
T find(T... args)
std::vector< std::string >
System::Win32::accountName
std::string accountName()
Get the account name of the current user.
Definition: SystemWin32.cpp:113
System::Win32::osVersion
std::string osVersion()
Get the operating system's version.
Definition: SystemWin32.cpp:94
SystemWin32.h
System::Win32::cmdLineArgs
std::vector< std::string > cmdLineArgs()
Get the command line arguments of the process.
Definition: SystemWin32.cpp:16
std::cout