libcommonc++  0.7
System.h++
Go to the documentation of this file.
1 /* ---------------------------------------------------------------------------
2  commonc++ - A C++ Common Class Library
3  Copyright (C) 2005-2014 Mark A Lindner
4 
5  This file is part of commonc++.
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public
18  License along with this library; if not, write to the Free
19  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  ---------------------------------------------------------------------------
21 */
22 
23 #ifndef __ccxx_System_hxx
24 #define __ccxx_System_hxx
25 
26 #include <commonc++/Common.h++>
27 #include <commonc++/Mutex.h++>
29 #include <commonc++/String.h++>
30 
31 #include <time.h>
32 #include <memory>
33 
34 namespace ccxx {
35 
42 {
43  public:
44 
46  static time_s_t currentTime();
47 
49  static time_ms_t currentTimeMillis();
50 
58  static void setSystemTime(const time_ms_t& time);
59 
67  static String getEnvVariable(const String& name);
68 
76  static bool setEnvVariable(const String& name, const String& value);
77 
84  static bool delEnvVariable(const String& name);
85 
87  static String getUserName();
88 
90  static String getOSName();
91 
93  static String getOSVersion();
94 
96  static String getArchitecture();
97 
99  static String getHostName();
100 
102  static String getHomeDir();
103 
105  static String getTempDir();
106 
109  static inline void lockGlobalMutex()
110  { _globalLock.lock(); }
111 
112  static inline void unlockGlobalMutex()
113  { _globalLock.unlock(); }
114 
123  static String getErrorString(const String& text = String::null);
124 
126  static size_t getPageSize();
127 
129  static void roundToPageSize(size_t& size);
130 
132  static void printStackTrace(uint_t maxFrames = 20);
133 
135  static bool isPOSIX();
136 
138  static bool isMacOSX();
139 
141  static bool isWindows();
142 
143  private:
144 
145  static void _getSystemInfo();
146  static Mutex _globalLock;
147 
148  static String _username;
149  static String _osname;
150  static String _osver;
151  static String _arch;
152  static String _hostname;
153  static String _homedir;
154  static String _tempdir;
155  static bool _inited;
156 
158 };
159 
160 } // namespace ccxx
161 
162 #endif // __ccxx_System_hxx
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
int32_t time_s_t
A time expressed in seconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:85
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
A mutual-exclusion lock.
Definition: Mutex.h++:49
#define COMMONCPP_API
Definition: Common.h++:126
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
Various system-level utility functions.
Definition: System.h++:41
static const String null
The null string.
Definition: String.h++:1128
Definition: AllocationMap.c++:25