NCBI C++ ToolKit
GBenchVersionInfo.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: GBenchVersionInfo.cpp 44795 2020-03-17 19:22:19Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: .......
27  *
28  * File Description:
29  * .......
30  *
31  * Remark:
32  * This code was originally generated by application DATATOOL
33  * using the following specifications:
34  * 'gbench_svc.asn'.
35  */
36 
37 // standard includes
38 #include <ncbi_pch.hpp>
39 
40 
41 #if defined(NCBI_OS_DARWIN)
42 #import <Foundation/Foundation.h>
43 #import <Foundation/NSProcessInfo.h>
44 #include <CoreServices/CoreServices.h>
45 
46 void GetOperatingSystemVersion(unsigned &major, unsigned &minor, unsigned &patch)
47 {
48  NSOperatingSystemVersion versionObj = [NSProcessInfo processInfo].operatingSystemVersion;
49 
50  major = (unsigned)versionObj.majorVersion;
51  minor = (unsigned)versionObj.minorVersion;
52  patch = (unsigned)versionObj.patchVersion;
53 }
54 #endif
55 
56 // generated includes
58 #include <gui/objects/OS_Ver.hpp>
59 
60 // generated classes
61 
63 
64 BEGIN_objects_SCOPE // namespace ncbi::objects::
65 
66 
67 int CGBenchVersionInfo::major = 0;//CPluginVersion::eMajor;
68 int CGBenchVersionInfo::minor = 0;//CPluginVersion::eMinor;
69 int CGBenchVersionInfo::patch = 0;//CPluginVersion::ePatchLevel;
72 
74 
75 void CGBenchVersionInfo::Initialize( size_t ver_major, size_t ver_minor, size_t ver_patch_level )
76 {
77  if( sInitialized ) return;
78 
79  CGBenchVersionInfo::major = (int)ver_major;
80  CGBenchVersionInfo::minor = (int)ver_minor;
81  CGBenchVersionInfo::patch = (int)ver_patch_level;
82 
83 #if defined(NCBI_OS_MSWIN)
84  ///
85  /// determine the OS version
86  ///
88 
89  OSVERSIONINFOEXW osinfo;
90  memset(&osinfo, 0, sizeof(osinfo));
91  osinfo.dwOSVersionInfoSize = sizeof(osinfo);
92 
93  typedef LONG(WINAPI *PRtlGetVersion)(LPOSVERSIONINFOEXW);
94  PRtlGetVersion pRtlGetVersion = (PRtlGetVersion)GetProcAddress(GetModuleHandle(TEXT("ntdll.dll")), "RtlGetVersion");
95  LONG status = -1;
96  if (pRtlGetVersion)
97  status = pRtlGetVersion(&osinfo);
98 
99  if (status != 0) {
100  memset(&osinfo, 0, sizeof(osinfo));
101  osinfo.dwOSVersionInfoSize = sizeof(osinfo);
102 
103 #ifdef _MSC_VER
104 #pragma warning(push)
105 #pragma warning(disable:4996) // 'xxx': was declared deprecated
106 #endif
107  GetVersionExW((LPOSVERSIONINFOW)&osinfo);
108 #ifdef _MSC_VER
109 #pragma warning(pop)
110 #endif
111 
112  }
113 
114  switch( osinfo.dwMajorVersion ){
115  default:
116  break;
117 
118  case 3:
120  break;
121 
122  case 4:
123  switch( osinfo.dwMinorVersion ){
124  case 0:
126  break;
127 
128  case 10:
130  break;
131 
132  case 90:
134  break;
135 
136  default:
138  break;
139  }
140  break;
141 
142  case 5:
143  switch( osinfo.dwMinorVersion ){
144  case 0:
145  default:
147  break;
148 
149  case 1:
151  break;
152 
153  case 2:
155  // SMSERVERR2 is not defined; it is needed for distinction of R2
156  break;
157  }
158  break;
159 
160  case 6:
161  switch( osinfo.dwMinorVersion ){
162  case 0:
163  default:
165  (osinfo.wProductType == VER_NT_WORKSTATION)
168  ;
169  break;
170 
171  case 1:
173  (osinfo.wProductType == VER_NT_WORKSTATION)
176  ;
177  break;
178  case 2:
180  (osinfo.wProductType == VER_NT_WORKSTATION)
183  ;
184  break;
185  case 3:
187  (osinfo.wProductType == VER_NT_WORKSTATION)
190  ;
191  break;
192  }
193  break;
194  case 10:
196  (osinfo.wProductType == VER_NT_WORKSTATION)
199  ;
200  break;
201  }
202 
204  TOs_ver arch_flag = 0;
205 
206  SYSTEM_INFO sysinfo;
207  memset(&sysinfo, 0, sizeof(sysinfo));
208 
209  typedef void (WINAPI *PGetSysInfo)(SYSTEM_INFO*);
210 
211  PGetSysInfo pGetSysInfo = (PGetSysInfo) GetProcAddress( GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo" );
212  if( pGetSysInfo != NULL ){
213  pGetSysInfo( &sysinfo );
214  } else {
215  GetSystemInfo( &sysinfo );
216  }
217  switch( sysinfo.wProcessorArchitecture ){
218  case PROCESSOR_ARCHITECTURE_UNKNOWN:
219  default:
221  arch_flag = 0;
222  break;
223 
224  case PROCESSOR_ARCHITECTURE_INTEL:
226  arch_flag = eOS_Ver_intel_x32;
227  break;
228  case PROCESSOR_ARCHITECTURE_AMD64:
230  arch_flag = eOS_Ver_amd_x64;
231  break;
232  case PROCESSOR_ARCHITECTURE_IA64:
234  arch_flag = eOS_Ver_intel_x64;
235  break;
236  }
237  CGBenchVersionInfo::osver |= arch_flag;
238 
239 
240 #elif defined(NCBI_OS_DARWIN)
241 
242  // The call to get the architecture is deprecated, so it will be hard-coded until another process architecture becomes available
243  TOs_ver arch_flag = eOS_Ver_intel_x64;
244 
245  unsigned vers_maj;
246  unsigned vers_min;
247  unsigned vers_patch;
248 
249  GetOperatingSystemVersion(vers_maj, vers_min, vers_patch);
250 
251  switch (vers_min) {
252  case 1:
254  break;
255  case 2:
257  break;
258  case 3:
260  break;
261  case 4:
263  break;
264  case 5:
266  break;
267  case 6:
269  break;
270  case 7:
272  break;
273  case 8:
275  break;
276  case 9:
278  break;
279  case 10:
281  break;
282  case 11:
284  break;
285  case 12:
287  break;
288  case 13:
290  break;
291  case 14:
293  break;
294  case 15:
296  break;
297  }
298 
299 #elif defined(NCBI_OS_UNIX)
300 
302 #else
303 
305 #endif
306 
307  sInitialized = true;
308 }
309 
311 {
312  if( sInitialized ){
317 
318  // Commented out until cgi update on server
319  // SetOs_arch(CGBenchVersionInfo::osarch);
320  }
321 }
322 
323 // destructor
325 {
326 }
327 
328 
329 void CGBenchVersionInfo::GetLabel( string* str ) const
330 {
331  if( !str ){
332  return;
333  }
334 
336 
337  *str += " (";
338  AddOsString( str );
339  *str += ")";
340 
341  if (IsSetBuild_date()) {
342  *str += " [" + GetBuild_date().AsCTime().AsString() + "]";
343  }
344 }
345 
347 {
348  if( str ){
349  str->clear();
351  }
352 }
353 
355 {
357  *str += '.';
359  *str += '.';
361 }
362 
364 {
365  if( str ){
366  str->clear();
367  AddOsString( str );
368  }
369 }
370 
372 {
373  const char* os_name;
374  switch( GetOs_ver() & ~eOS_Ver_cpu_generic ){
376  os_name = "Windows";
377  break;
378  case eOS_Ver_windows_95:
379  os_name = "Windows 95";
380  break;
381  case eOS_Ver_windows_98:
382  os_name = "Windows 98";
383  break;
384  case eOS_Ver_windows_me:
385  os_name = "Windows ME";
386  break;
387  case eOS_Ver_windows_351:
388  os_name = "Windows NT 3.51";
389  break;
390  case eOS_Ver_windows_nt4:
391  os_name = "Windows NT 4.0";
392  break;
394  os_name = "Windows 2000";
395  break;
396  case eOS_Ver_windows_xp:
397  os_name = "Windows XP";
398  break;
400  os_name = "Windows 2003";
401  break;
403  os_name = "Windows 2003 R2";
404  break;
406  os_name = "Windows Vista";
407  break;
409  os_name = "Windows 2008";
410  break;
412  os_name = "Windows 2008 R2";
413  break;
415  os_name = "Windows 7";
416  break;
418  os_name = "Windows Server 2012";
419  break;
421  os_name = "Windows 8.0";
422  break;
424  os_name = "Windows Server 2012 R2";
425  break;
427  os_name = "Windows 8.1";
428  break;
430  os_name = "Windows Server 2016";
431  break;
432  case eOS_Ver_windows_ten:
433  os_name = "Windows 10";
434  break;
436  os_name = "MacOS X";
437  break;
438  case eOS_Ver_macosx_10_1:
439  os_name = "MacOS X 10.1";
440  break;
441  case eOS_Ver_macosx_10_2:
442  os_name = "MacOS X 10.2";
443  break;
444  case eOS_Ver_macosx_10_3:
445  os_name = "MacOS X 10.3";
446  break;
447  case eOS_Ver_macosx_10_4:
448  os_name = "MacOS X 10.4";
449  break;
450  case eOS_Ver_macosx_10_5:
451  os_name = "MacOS X 10.5";
452  break;
453  case eOS_Ver_macosx_10_6:
454  os_name = "MacOS X 10.6";
455  break;
456  case eOS_Ver_macosx_10_7:
457  os_name = "MacOS X 10.7";
458  break;
459  case eOS_Ver_macosx_10_8:
460  os_name = "MacOS X 10.8 Mountain Lion";
461  break;
462  case eOS_Ver_macosx_10_9:
463  os_name = "MacOS X 10.9 Mavericks";
464  break;
466  os_name = "MacOS X 10.10 Yosemite";
467  break;
469  os_name = "MacOS X 10.11 El Capitan";
470  break;
472  os_name = "MacOS X 10.12 Sierra";
473  break;
475  os_name = "MacOS X 10.13 High Sierra";
476  break;
478  os_name = "MacOS X 10.14 Mojave";
479  break;
481  os_name = "MacOS X 10.15 Catalina";
482  break;
483 
485  os_name = "Unix";
486  break;
487  case eOS_Ver_unix_linux:
488  os_name = "Unix/Linux";
489  break;
491  os_name = "Unix/Solaris 9";
492  break;
494  os_name = "Unix/Solaris 10";
495  break;
496 
497  default:
499  os_name = "Windows";
500  } else if( GetOs_ver() & eOS_Ver_macosx_generic ){
501  os_name = "MacOS X";
502  } else if( GetOs_ver() & eOS_Ver_unix_generic ){
503  os_name = "Unix";
504  } else {
505  os_name = "Unknown";
506  }
507  break;
508  }
509 
510  const char* arch_name = "";
511  switch( GetOs_ver() & eOS_Ver_cpu_generic ){
512  case eOS_Ver_intel_x32:
513  arch_name = " Intel-x32";
514  break;
515  case eOS_Ver_amd_x64:
516  arch_name = " AMD-x64";
517  break;
518  case eOS_Ver_intel_x64:
519  arch_name = " Intel-x64";
520  break;
521  case eOS_Ver_ppc:
522  arch_name = " PowerPC";
523  break;
524  case eOS_Ver_sparc:
525  arch_name = " Sparc";
526  break;
527  case eOS_Ver_mips:
528  arch_name = " MIPS";
529  break;
530  case eOS_Ver_alpha:
531  arch_name = " Alpha";
532  break;
533  }
534 
535  *str += os_name;
536  *str += arch_name;
537 }
538 
540 {
541  if (v1.GetVer_major() < v2.GetVer_major()) {
542  return true;
543  }
544  if (v2.GetVer_major() < v1.GetVer_major()) {
545  return false;
546  }
547 
548  if (v1.GetVer_minor() < v2.GetVer_minor()) {
549  return true;
550  }
551  if (v2.GetVer_minor() < v1.GetVer_minor()) {
552  return false;
553  }
554 
555  if (v1.GetVer_patch() < v2.GetVer_patch()) {
556  return true;
557  }
558  if (v2.GetVer_patch() < v1.GetVer_patch()) {
559  return false;
560  }
561 
562  return false;
563 }
564 
565 END_objects_SCOPE // namespace ncbi::objects::
566 
568 
569 /* Original file checksum: lines: 65, chars: 1911, CRC32: 1807b76f */
bool operator<(const CGBenchVersionInfo &v1, const CGBenchVersionInfo &v2)
User-defined methods of the data storage class.
User-defined methods of the data storage class.
CTime AsCTime(CTime::ETimeZone tz=CTime::eLocal) const
Definition: Date.cpp:70
static TVer_minor minor
static TVer_major major
static TVer_patch patch
void GetOsString(string *str) const
void AddOsString(string *str) const
void GetVersionString(string *str) const
retrieve just the version info
static void Initialize(size_t ver_major, size_t ver_minor, size_t ver_patch_level)
Forced to make this method public as far as friend declaration does not work on Linux.
void AddVersionString(string *str) const
void GetLabel(string *str) const
Format a label for this version.
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NULL
Definition: ncbistd.hpp:225
const CVect2< U > & v2
Definition: globals.hpp:440
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1511
TVer_major GetVer_major(void) const
Get the Ver_major member data.
TVer_minor & SetVer_minor(void)
Assign a value to Ver_minor data member.
const TBuild_date & GetBuild_date(void) const
Get the Build_date member data.
TVer_major & SetVer_major(void)
Assign a value to Ver_major data member.
TVer_patch & SetVer_patch(void)
Assign a value to Ver_patch data member.
TOs_ver & SetOs_ver(void)
Assign a value to Os_ver data member.
TVer_minor GetVer_minor(void) const
Get the Ver_minor member data.
TVer_patch GetVer_patch(void) const
Get the Ver_patch member data.
bool IsSetBuild_date(void) const
Check if a value has been assigned to Build_date data member.
TOs_ver GetOs_ver(void) const
Get the Os_ver member data.
@ eOS_Ver_cpu_generic
CPU attributes general mask (0xff000000)
Definition: OS_Ver_.hpp:108
@ eOS_Ver_ppc
any powerpc (0x04000000)
Definition: OS_Ver_.hpp:112
@ eOS_Ver_windows_nt4
0x5
Definition: OS_Ver_.hpp:73
@ eOS_Ver_sparc
any sparc (0x05000000)
Definition: OS_Ver_.hpp:113
@ eOS_Ver_macosx_10_7
0x700
Definition: OS_Ver_.hpp:95
@ eOS_Ver_intel_x64
any intel x64 (0x03000000)
Definition: OS_Ver_.hpp:111
@ eOS_Ver_macosx_10_15
0xF00
Definition: OS_Ver_.hpp:103
@ eOS_Ver_windows_2003
0x8
Definition: OS_Ver_.hpp:76
@ eOS_Ver_windows_2008
0xb
Definition: OS_Ver_.hpp:79
@ eOS_Ver_macosx_10_9
0x900
Definition: OS_Ver_.hpp:97
@ eOS_Ver_alpha
any alpha (0x07000000)
Definition: OS_Ver_.hpp:115
@ eOS_Ver_amd_x64
any amd x64 (0x02000000)
Definition: OS_Ver_.hpp:110
@ eOS_Ver_windows_98
0x2
Definition: OS_Ver_.hpp:70
@ eOS_Ver_windows_generic
bitmaks covering all Windows versions this corresponds to 0xff
Definition: OS_Ver_.hpp:68
@ eOS_Ver_unix_solaris_9
0x20000
Definition: OS_Ver_.hpp:106
@ eOS_Ver_unix_generic
bitmask for all linux and unix flavors this corresponds to 0xff0000
Definition: OS_Ver_.hpp:104
@ eOS_Ver_mips
any mips (0x06000000)
Definition: OS_Ver_.hpp:114
@ eOS_Ver_macosx_generic
bitmask covering all MacOS X versions this corresponds to 0xff00
Definition: OS_Ver_.hpp:88
@ eOS_Ver_macosx_10_14
0xE00
Definition: OS_Ver_.hpp:102
@ eOS_Ver_unix_solaris_10
0x30000
Definition: OS_Ver_.hpp:107
@ eOS_Ver_macosx_10_2
0x200
Definition: OS_Ver_.hpp:90
@ eOS_Ver_windows_2000
0x6
Definition: OS_Ver_.hpp:74
@ eOS_Ver_windows_eight
0xf
Definition: OS_Ver_.hpp:83
@ eOS_Ver_windows_me
0x3
Definition: OS_Ver_.hpp:71
@ eOS_Ver_macosx_10_6
0x600
Definition: OS_Ver_.hpp:94
@ eOS_Ver_macosx_10_3
0x300
Definition: OS_Ver_.hpp:91
@ eOS_Ver_windows_seven
0xd
Definition: OS_Ver_.hpp:81
@ eOS_Ver_windows_2016
0x12
Definition: OS_Ver_.hpp:86
@ eOS_Ver_macosx_10_1
specific MacOS X versions 0x100
Definition: OS_Ver_.hpp:89
@ eOS_Ver_macosx_10_11
0xB00
Definition: OS_Ver_.hpp:99
@ eOS_Ver_windows_95
specific windows versions 0x1
Definition: OS_Ver_.hpp:69
@ eOS_Ver_windows_xp
0x7
Definition: OS_Ver_.hpp:75
@ eOS_Ver_macosx_10_8
0x800
Definition: OS_Ver_.hpp:96
@ eOS_Ver_macosx_10_13
0xD00
Definition: OS_Ver_.hpp:101
@ eOS_Ver_macosx_10_4
0x400
Definition: OS_Ver_.hpp:92
@ eOS_Ver_windows_eight_one
0x11
Definition: OS_Ver_.hpp:85
@ eOS_Ver_macosx_10_5
0x500
Definition: OS_Ver_.hpp:93
@ eOS_Ver_unknown
Definition: OS_Ver_.hpp:67
@ eOS_Ver_windows_vista
0xa
Definition: OS_Ver_.hpp:78
@ eOS_Ver_windows_ten
0x13
Definition: OS_Ver_.hpp:87
@ eOS_Ver_windows_2012_R2
0x10
Definition: OS_Ver_.hpp:84
@ eOS_Ver_macosx_10_12
0xC00
Definition: OS_Ver_.hpp:100
@ eOS_Ver_unix_linux
specific supported versions 0x10000
Definition: OS_Ver_.hpp:105
@ eOS_Ver_windows_2012
0xe
Definition: OS_Ver_.hpp:82
@ eOS_Ver_windows_2003_R2
0x9
Definition: OS_Ver_.hpp:77
@ eOS_Ver_windows_2008_R2
0xc
Definition: OS_Ver_.hpp:80
@ eOS_Ver_macosx_10_10
0xA00
Definition: OS_Ver_.hpp:98
@ eOS_Ver_windows_351
0x4
Definition: OS_Ver_.hpp:72
@ eOS_Ver_intel_x32
any intel x32 (0x01000000)
Definition: OS_Ver_.hpp:109
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
Modified on Wed Apr 17 13:10:30 2024 by modify_doxy.py rev. 669887