You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
7.8 KiB

  1. /* /////////////////////////////////////////////////////////////////////////
  2. * File: winstl/system/system_version.hpp
  3. *
  4. * Purpose: Contains the system_version class, which provides
  5. * information about the host system version.
  6. *
  7. * Created: 10th February 2002
  8. * Updated: 6th May 2010
  9. *
  10. * Home: http://stlsoft.org/
  11. *
  12. * Copyright (c) 2002-2010, Matthew Wilson and Synesis Software
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above copyright notice, this
  19. * list of conditions and the following disclaimer.
  20. * - Redistributions in binary form must reproduce the above copyright notice,
  21. * this list of conditions and the following disclaimer in the documentation
  22. * and/or other materials provided with the distribution.
  23. * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
  24. * any contributors may be used to endorse or promote products derived from
  25. * this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  28. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  29. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  30. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  31. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  32. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  33. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  34. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  35. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  36. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37. * POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. * ////////////////////////////////////////////////////////////////////// */
  40. /** \file winstl/system/system_version.hpp
  41. *
  42. * \brief [C++ only] Definition of the winstl::system_version class
  43. * template
  44. * (\ref group__library__system "System" Library).
  45. */
  46. #ifndef WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_VERSION
  47. #define WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_VERSION
  48. #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
  49. # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_VERSION_MAJOR 4
  50. # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_VERSION_MINOR 0
  51. # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_VERSION_REVISION 2
  52. # define WINSTL_VER_WINSTL_SYSTEM_HPP_SYSTEM_VERSION_EDIT 55
  53. #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */
  54. /* /////////////////////////////////////////////////////////////////////////
  55. * Includes
  56. */
  57. #ifndef WINSTL_INCL_WINSTL_H_WINSTL
  58. # include <winstl/winstl.h>
  59. #endif /* !WINSTL_INCL_WINSTL_H_WINSTL */
  60. /* /////////////////////////////////////////////////////////////////////////
  61. * Namespace
  62. */
  63. #ifndef _WINSTL_NO_NAMESPACE
  64. # if defined(_STLSOFT_NO_NAMESPACE) || \
  65. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  66. /* There is no stlsoft namespace, so must define ::winstl */
  67. namespace winstl
  68. {
  69. # else
  70. /* Define stlsoft::winstl_project */
  71. namespace stlsoft
  72. {
  73. namespace winstl_project
  74. {
  75. # endif /* _STLSOFT_NO_NAMESPACE */
  76. #endif /* !_WINSTL_NO_NAMESPACE */
  77. /* /////////////////////////////////////////////////////////////////////////
  78. * Classes
  79. */
  80. /** \brief Provides system version information
  81. *
  82. * \ingroup group__library__system
  83. *
  84. * This class wraps the GetSystemInfo() API function. Since the information that
  85. * this function provides is constant for any particular active system for its
  86. * lifetime, the function is called only once, as implemented via the
  87. * get_versioninfo_() method.
  88. */
  89. class system_version
  90. {
  91. public: // Member Types
  92. /// This type
  93. typedef system_version class_type;
  94. public: // Accessors
  95. public: // Accessors:Operating System Type
  96. /// Returns \c true if the operating system is one of the NT family (NT, 2000, XP, .NET)
  97. static ws_bool_t winnt();
  98. /// Returns \c true if the operating system is one of the 95 family (95, 98, ME)
  99. static ws_bool_t win9x();
  100. /// Returns \c true if the operating system is Win32s
  101. static ws_bool_t win32s();
  102. public: // Accessors:Operating System Version
  103. /// Returns the operating system major version
  104. static ws_uint_t major();
  105. /// Returns the operating system minor version
  106. static ws_uint_t minor();
  107. // Build number
  108. /// Returns the operating system build number
  109. static ws_uint32_t build_number();
  110. public: // Accessors
  111. /// Provides a non-mutable (const) reference to the \c OSVERSIONINFO instance
  112. static OSVERSIONINFO const& get_versioninfo();
  113. // Implementation
  114. private:
  115. static OSVERSIONINFO &get_versioninfo_();
  116. };
  117. ////////////////////////////////////////////////////////////////////////////
  118. // Unit-testing
  119. #ifdef STLSOFT_UNITTEST
  120. # include "./unittest/system_version_unittest_.h"
  121. #endif /* STLSOFT_UNITTEST */
  122. ////////////////////////////////////////////////////////////////////////////
  123. // Implementation
  124. inline /* static */ OSVERSIONINFO &system_version::get_versioninfo_()
  125. {
  126. /// Unfortunately, something in this technique scares the Borland compilers (5.5
  127. /// and 5.51) into Internal compiler errors so the s_init variable in
  128. /// get_versioninfo_() is int rather than bool when compiling for borland.
  129. #if !defined(STLSOFT_STRICT) && \
  130. defined(STLSOFT_COMPILER_IS_MSVC) && \
  131. _MSC_VER >= 1310
  132. # pragma warning(push)
  133. # pragma warning(disable : 4640) /* "construction of local static object is not thread-safe" - since it is here! (As long as one uses a 'conformant' allocator) - maybe use a spin_mutex in future */
  134. #endif /* compiler */
  135. static OSVERSIONINFO s_versioninfo;
  136. #if defined(STLSOFT_COMPILER_IS_BORLAND)
  137. /* WSCB: Borland has an internal compiler error if use ws_bool_t */
  138. static ws_int_t s_init = (s_versioninfo.dwOSVersionInfoSize = sizeof(s_versioninfo), ::GetVersionEx(&s_versioninfo), ws_true_v);
  139. #else /* ? compiler */
  140. static ws_bool_t s_init = (s_versioninfo.dwOSVersionInfoSize = sizeof(s_versioninfo), ::GetVersionEx(&s_versioninfo), ws_true_v);
  141. #endif /* compiler */
  142. #if !defined(STLSOFT_STRICT) && \
  143. defined(STLSOFT_COMPILER_IS_MSVC) && \
  144. _MSC_VER >= 1310
  145. # pragma warning(pop)
  146. #endif /* compiler */
  147. STLSOFT_SUPPRESS_UNUSED(s_init); // Placate GCC
  148. return s_versioninfo;
  149. }
  150. inline /* static */ ws_bool_t system_version::winnt()
  151. {
  152. return get_versioninfo_().dwPlatformId == VER_PLATFORM_WIN32_NT;
  153. }
  154. inline /* static */ ws_bool_t system_version::win9x()
  155. {
  156. return get_versioninfo_().dwPlatformId == VER_PLATFORM_WIN32_WINDOWS;
  157. }
  158. inline /* static */ ws_bool_t system_version::win32s()
  159. {
  160. return get_versioninfo_().dwPlatformId == VER_PLATFORM_WIN32s;
  161. }
  162. inline /* static */ ws_uint_t system_version::major()
  163. {
  164. return get_versioninfo_().dwMajorVersion;
  165. }
  166. inline /* static */ ws_uint_t system_version::minor()
  167. {
  168. return get_versioninfo_().dwMinorVersion;
  169. }
  170. inline /* static */ ws_uint32_t system_version::build_number()
  171. {
  172. return winnt() ? get_versioninfo_().dwBuildNumber : static_cast<WORD>(get_versioninfo_().dwBuildNumber);
  173. }
  174. inline /* static */ OSVERSIONINFO const& system_version::get_versioninfo()
  175. {
  176. return get_versioninfo_();
  177. }
  178. /* ////////////////////////////////////////////////////////////////////// */
  179. #ifndef _WINSTL_NO_NAMESPACE
  180. # if defined(_STLSOFT_NO_NAMESPACE) || \
  181. defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
  182. } // namespace winstl
  183. # else
  184. } // namespace winstl_project
  185. } // namespace stlsoft
  186. # endif /* _STLSOFT_NO_NAMESPACE */
  187. #endif /* !_WINSTL_NO_NAMESPACE */
  188. /* ////////////////////////////////////////////////////////////////////// */
  189. #endif /* WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_VERSION */
  190. /* ///////////////////////////// end of file //////////////////////////// */