STLSoft - ... Robust, Lightweight, Cross-platform, Template Software ... ATLSTL - Template Software for the Active Template Library COMSTL - The Standard Template Library meets the Component Object Model .netSTL - Standard Template Library meets the Microsoft.NET Common Language Runtime InetSTL - The Standard Template Library meets WinInet MFCSTL - Template Software for the Microsoft Foundation Classes UNIXSTL - Template Software for the UNIX Operating System WinSTL - where the Standard Template Library meets the Win32 API

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

winstl_system_info.h

Go to the documentation of this file.
00001 /* 
00002  * File:        winstl_system_info.h
00003  *
00004  * Purpose:     Contains the basic_system_info class, which provides information
00005  *              regarding the host system, such as number of processors and
00006  *              page size.
00007  *
00008  * Created:     7th February 2002
00009  * Updated:     11th September 2004
00010  *
00011  * Home:        http://stlsoft.org/
00012  *
00013  * Copyright (c) 2002-2004, Matthew Wilson and Synesis Software
00014  * All rights reserved.
00015  *
00016  * Redistribution and use in source and binary forms, with or without
00017  * modification, are permitted provided that the following conditions are met:
00018  *
00019  * - Redistributions of source code must retain the above copyright notice, this
00020  *   list of conditions and the following disclaimer.
00021  * - Redistributions in binary form must reproduce the above copyright notice,
00022  *   this list of conditions and the following disclaimer in the documentation
00023  *   and/or other materials provided with the distribution.
00024  * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of
00025  *   any contributors may be used to endorse or promote products derived from
00026  *   this software without specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00029  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00032  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00033  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00034  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00035  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00036  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00037  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00038  * POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  * 
00041 
00042 
00046 
00047 #ifndef WINSTL_INCL_H_WINSTL_SYSTEM_INFO
00048 #define WINSTL_INCL_H_WINSTL_SYSTEM_INFO
00049 
00050 #ifndef __STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_H_WINSTL_SYSTEM_INFO_MAJOR      2
00052 # define WINSTL_VER_H_WINSTL_SYSTEM_INFO_MINOR      0
00053 # define WINSTL_VER_H_WINSTL_SYSTEM_INFO_REVISION   1
00054 # define WINSTL_VER_H_WINSTL_SYSTEM_INFO_EDIT       33
00055 #endif /* !__STLSOFT_DOCUMENTATION_SKIP_SECTION */
00056 
00057 /* 
00058  * Includes
00059  */
00060 
00061 #include <winstl.h>             // Include the WinSTL root header
00062 
00063 /* 
00064  * Namespace
00065  */
00066 
00067 #ifndef _WINSTL_NO_NAMESPACE
00068 # if defined(_STLSOFT_NO_NAMESPACE) || \
00069      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00070 /* There is no stlsoft namespace, so must define ::winstl */
00071 namespace winstl
00072 {
00073 # else
00074 /* Define stlsoft::winstl_project */
00075 
00076 namespace stlsoft
00077 {
00078 
00079 namespace winstl_project
00080 {
00081 
00082 # endif /* _STLSOFT_NO_NAMESPACE */
00083 #endif /* !_WINSTL_NO_NAMESPACE */
00084 
00085 /* 
00086 
00089 
00093 
00098 
00099 /* 
00100  * Classes
00101  */
00102 
00109 class system_info
00110 {
00111 public:
00112     typedef system_info class_type;
00113 
00114 // Construction
00115 private:
00116     system_info();
00117     ~system_info();
00118 
00119 // Operations
00120 public:
00122     static ws_uint32_t number_of_processors()
00123     {
00124         return _get_systeminfo().dwNumberOfProcessors;
00125     }
00126 
00128     static ws_size_t page_size()
00129     {
00130         return _get_systeminfo().dwPageSize;
00131     }
00132 
00134     static ws_size_t allocation_granularity()
00135     {
00136         return _get_systeminfo().dwAllocationGranularity;
00137     }
00138 
00140     static const SYSTEM_INFO &get_systeminfo()
00141     {
00142         return _get_systeminfo();
00143     }
00144 
00145 // Implementation
00146 private:
00150     static SYSTEM_INFO &_get_systeminfo()
00151     {
00152         static SYSTEM_INFO  s_systeminfo;
00153 #ifdef __STLSOFT_COMPILER_IS_BORLAND
00154         /* WSCB: Borland has an internal compiler error if use ws_bool_t */
00155         static ws_int_t     s_init = (::GetSystemInfo(&s_systeminfo), ws_true_v);
00156 #else
00157         static ws_bool_t    s_init = (::GetSystemInfo(&s_systeminfo), ws_true_v);
00158 #endif /* __STLSOFT_COMPILER_IS_BORLAND */
00159 
00160         STLSOFT_SUPPRESS_UNUSED(s_init);
00161 
00162         return s_systeminfo;
00163     }
00164 };
00165 
00167 // Unit-testing
00168 
00169 #ifdef STLSOFT_UNITTEST
00170 
00171 namespace unittest
00172 {
00173     ss_bool_t test_winstl_system_info(unittest_reporter *r)
00174     {
00175         using stlsoft::unittest::unittest_initialiser;
00176 
00177         ss_bool_t               bSuccess    =   true;
00178 
00179         unittest_initialiser    init(r, "WinSTL", "system_info", __FILE__);
00180 
00181 #if 0
00182         if(<<TODO>>)
00183         {
00184             r->report("<<TODO>> failed ", __LINE__);
00185             bSuccess = false;
00186         }
00187 #endif /* 0 */
00188 
00189         return bSuccess;
00190     }
00191 
00192     unittest_registrar    unittest_winstl_system_info(test_winstl_system_info);
00193 
00194 } // namespace unittest
00195 
00196 #endif /* STLSOFT_UNITTEST */
00197 
00198 /* 
00199 
00200 #ifndef _WINSTL_NO_NAMESPACE
00201 # if defined(_STLSOFT_NO_NAMESPACE) || \
00202      defined(__STLSOFT_DOCUMENTATION_SKIP_SECTION)
00203 } // namespace winstl
00204 # else
00205 } // namespace winstl_project
00206 } // namespace stlsoft
00207 # endif /* _STLSOFT_NO_NAMESPACE */
00208 #endif /* !_WINSTL_NO_NAMESPACE */
00209 
00210 /* 
00211 
00212 #endif /* WINSTL_INCL_H_WINSTL_SYSTEM_INFO */
00213 
00214 /* 

STLSoft Libraries documentation © Synesis Software Pty Ltd, 2001-2004