BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdls_osutil.h
Go to the documentation of this file.
1/// @file bdls_osutil.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bdls_osutil.h -*-C++-*-
8#ifndef INCLUDED_BDLS_OSUTIL
9#define INCLUDED_BDLS_OSUTIL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bdls_osutil bdls_osutil
15/// @brief Provide utilities related to the operating system.
16/// @addtogroup bdl
17/// @{
18/// @addtogroup bdls
19/// @{
20/// @addtogroup bdls_osutil
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bdls_osutil-purpose"> Purpose</a>
25/// * <a href="#bdls_osutil-classes"> Classes </a>
26/// * <a href="#bdls_osutil-description"> Description </a>
27/// * <a href="#bdls_osutil-usage"> Usage </a>
28/// * <a href="#bdls_osutil-example-1-display-os-name-version-and-patch-level"> Example 1: Display OS Name, Version and Patch Level </a>
29///
30/// # Purpose {#bdls_osutil-purpose}
31/// Provide utilities related to the operating system.
32///
33/// # Classes {#bdls_osutil-classes}
34///
35/// - bdls::OsUtil: namespace for operating system information utilities
36///
37/// @see
38///
39/// # Description {#bdls_osutil-description}
40/// This component provides a namespace, `bdls::OsUtil`,
41/// containing utility functions for retrieving information at runtime about the
42/// operating system in which this task is running.
43///
44/// ## Usage {#bdls_osutil-usage}
45///
46///
47/// This section illustrates intended use of this component.
48///
49/// ### Example 1: Display OS Name, Version and Patch Level {#bdls_osutil-example-1-display-os-name-version-and-patch-level}
50///
51///
52/// The following example demonstrates using `getOsInfo` to obtain information
53/// about the operating system at runtime and writing it to the console.
54///
55/// First, we create strings for the operating system name (`osName`), version
56/// (`osVersion`), and patch (`osPatch`), and then call `getOsInfo` to load
57/// these strings with values for the operating system the task is executing in:
58/// @code
59/// bsl::string name;
60/// bsl::string version;
61/// bsl::string patch;
62/// @endcode
63/// Then, we use the standard streams to write the operating system version
64/// information to the console, or an error message of failure:
65/// @code
66/// const int rc = bdls::OsUtil::getOsInfo(&name, &version, &patch);
67/// if (rc == 0) {
68/// bsl::cout << "OS Name: " << name << "\n"
69/// << "Version: " << version << "\n"
70/// << "Patch: " << patch << "\n";
71/// } else {
72/// bsl::cout << "Cannot determine OS name and version\n";
73/// }
74/// @endcode
75/// Finally, the resulting console output on the Red Hat Enterprise Linux Server
76/// 5.5 would be
77/// @code
78/// OS Name: Linux
79/// Version: 2.6.18-194.32.1.el5
80/// Patch: #1 SMP Mon Dec 20 10:52:42 EST 2010
81/// @endcode
82/// On Windows 7 SP1, the display would be
83/// @code
84/// OS Name: Windows
85/// Version: 6.1
86/// Patch: Service Pack 1
87/// @endcode
88/// @}
89/** @} */
90/** @} */
91
92/** @addtogroup bdl
93 * @{
94 */
95/** @addtogroup bdls
96 * @{
97 */
98/** @addtogroup bdls_osutil
99 * @{
100 */
101
102#include <bsl_string.h>
103
104#include <bsls_libraryfeatures.h>
105
106#include <string>
107
108
109namespace bdls {
110
111 // =============
112 // struct OsUtil
113 // =============
114
115/// This `struct` provides a namespace for utility functions retrieving
116/// information about the operating system.
117struct OsUtil {
118
119 // CLASS METHODS
120
121 static int getOsInfo(bsl::string *osName,
122 bsl::string *osVersion,
123 bsl::string *osPatch);
124 /// Load the operating system name, version name and patch name into the
125 /// specified `osName`, `osVersion` and `osPatch` respectively. Return
126 /// 0 on success and a non-zero value otherwise. The loaded values may
127 /// represent an emulation provided for the current process (see
128 /// "manifest-based behavior" in Windows programming documentation for
129 /// an example) and therefore are not suitable for determining supported
130 /// features or the real environment/version. If you need to determine
131 /// the presence of certain features please consult the documentation of
132 /// the operating systems you need to support.
133 static int getOsInfo(std::string *osName,
134 std::string *osVersion,
135 std::string *osPatch);
136#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
137 static int getOsInfo(std::pmr::string *osName,
138 std::pmr::string *osVersion,
139 std::pmr::string *osPatch);
140#endif
141};
142
143} // close package namespace
144
145
146#endif
147
148// ----------------------------------------------------------------------------
149// Copyright 2015 Bloomberg Finance L.P.
150//
151// Licensed under the Apache License, Version 2.0 (the "License");
152// you may not use this file except in compliance with the License.
153// You may obtain a copy of the License at
154//
155// http://www.apache.org/licenses/LICENSE-2.0
156//
157// Unless required by applicable law or agreed to in writing, software
158// distributed under the License is distributed on an "AS IS" BASIS,
159// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
160// See the License for the specific language governing permissions and
161// limitations under the License.
162// ----------------------------- END-OF-FILE ----------------------------------
163
164/** @} */
165/** @} */
166/** @} */
Definition bslstl_string.h:1281
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdls_fdstreambuf.h:412
Definition bdls_osutil.h:117
static int getOsInfo(bsl::string *osName, bsl::string *osVersion, bsl::string *osPatch)
static int getOsInfo(std::string *osName, std::string *osVersion, std::string *osPatch)