The Gaudi Framework  master (37c0b60a)
SystemWin32.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 
12 // System include(s):
13 #include <cstring>
14 #include <sstream>
15 #include <windows.h>
16 
17 // Local include(s):
18 #include "SystemWin32.h"
19 
20 // Disable warning C4996 triggered by C standard library calls
21 #pragma warning( disable : 4996 )
22 
23 namespace System {
24  namespace Win32 {
25 
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  }
60 
61  std::string typeinfoName( const char* class_name ) {
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  }
92 
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  }
101 
102  std::string osName() { return "Windows"; }
103 
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  }
113 
115 
116  SYSTEM_INFO ut;
117  ::GetSystemInfo( &ut );
118  std::ostringstream arch;
119  arch << ut.wProcessorArchitecture;
120  return arch.str();
121  }
122 
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  }
131 
132  } // namespace Win32
133 } // namespace System
std::string
STL class.
System::Win32::hostName
std::string hostName()
Get the system's host name.
Definition: SystemWin32.cpp:93
std::vector< std::string >
std::string::find
T find(T... args)
System::Win32::machineType
std::string machineType()
Get the runner machine's type.
Definition: SystemWin32.cpp:114
std::string::replace
T replace(T... args)
SystemWin32.h
std::vector::push_back
T push_back(T... args)
std::cout
std::string::erase
T erase(T... args)
System::Win32::accountName
std::string accountName()
Get the account name of the current user.
Definition: SystemWin32.cpp:123
std::ostringstream
STL class.
std::endl
T endl(T... args)
System::Win32::cmdLineArgs
std::vector< std::string > cmdLineArgs()
Get the command line arguments of the process.
Definition: SystemWin32.cpp:26
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:29
System::Win32::osVersion
std::string osVersion()
Get the operating system's version.
Definition: SystemWin32.cpp:104
std::ostringstream::str
T str(T... args)
System::Win32::osName
std::string osName()
Get the operating system's name.
Definition: SystemWin32.cpp:102
System::Win32::typeinfoName
std::string typeinfoName(const char *class_name)
Get the human readable type name from a typeinfo name.
Definition: SystemWin32.cpp:61