HoverRace  2.0
OS.h
Go to the documentation of this file.
1 
2 // OS.h
3 //
4 // Copyright (c) 2009, 2014-2016 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include <locale>
25 #include <set>
26 #include <string>
27 #include <vector>
28 
29 #include <boost/filesystem.hpp>
30 
31 #include "MR_Types.h"
32 
33 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
34 # ifdef MR_ENGINE
35 # define MR_DllDeclare __declspec( dllexport )
36 # else
37 # define MR_DllDeclare __declspec( dllimport )
38 # endif
39 #else
40 # define MR_DllDeclare
41 #endif
42 
43 namespace HoverRace {
44 namespace Util {
45 
50 namespace OS {
51 
52 extern std::locale locale;
53 extern const std::locale &stdLocale;
54 
56 
57 using path_t = boost::filesystem::path;
58 using dirIter_t = boost::filesystem::directory_iterator;
59 using dirEnt_t = boost::filesystem::directory_entry;
60 
61 using fs_error_t = boost::filesystem::filesystem_error;
62 
63 using pstr_t = path_t::value_type*;
64 using cpstr_t = const path_t::value_type*;
65 
66 void SetEnv(const char *key, const char *val);
67 const std::locale &SetLocale(const path_t &path, const std::string &domain,
68  const std::string &reqLocale = {});
69 
70 std::string StrError(int errnum);
71 
72 void TimeInit();
74 
82 constexpr inline timestamp_t TimeDiff(timestamp_t laterTs,
83  timestamp_t earlierTs) noexcept
84 {
85  // We assume that signed 64-bit values won't have to deal with
86  // wraparound.
87  return laterTs - earlierTs;
88 }
89 
90 std::string FileTimeString();
91 void TimeShutdown();
92 
93 bool OpenLink(const std::string &url);
94 bool OpenPath(const path_t &path);
95 
96 FILE *FOpen(const path_t &path, const char *mode);
97 
98 void ShowMessage(const std::string &s, bool error = false);
99 
101 
102 std::string GetUsername();
103 
104 } // namespace OS
105 
106 } // namespace Util
107 } // namespace HoverRace
108 
109 #undef MR_DllDeclare
boost::filesystem::filesystem_error fs_error_t
Definition: OS.h:61
constexpr timestamp_t TimeDiff(timestamp_t laterTs, timestamp_t earlierTs) noexcept
Calculate the difference between two timestamps.
Definition: OS.h:82
std::locale locale
Global reference to the current locale.
Definition: OS.cpp:98
FILE * FOpen(const path_t &path, const char *mode)
Open a file using the OS-specific path format.
Definition: OS.cpp:348
boost::filesystem::path path_t
Definition: OS.h:57
std::string StrError(int errnum)
Convert an error number to a string.
Definition: OS.cpp:198
boost::filesystem::directory_iterator dirIter_t
Definition: OS.h:58
void TimeInit()
Initialize the OS time source.
Definition: OS.cpp:206
const std::locale & SetLocale(const path_t &path, const std::string &domain, const std::string &reqLocale={})
Set the locale based on the current environment.
Definition: OS.cpp:156
void ShowMessage(const std::string &s, bool error=false)
Display a simple error message to the user.
Definition: OS.cpp:371
void SetEnv(const char *key, const char *val)
Set an environment variable.
Definition: OS.cpp:109
std::string FileTimeString()
Generate a string representing the current timestamp, suitable for filenames.
Definition: OS.cpp:238
timestamp_t Time()
Retrieve a timestamp.
Definition: OS.cpp:217
path_t::value_type * pstr_t
Definition: OS.h:63
const path_t::value_type * cpstr_t
Definition: OS.h:64
std::string GetUsername()
Get the username of the current OS user.
Definition: OS.cpp:418
OS::path_t FindExePath()
Find the path of the executable itself.
Definition: OS.cpp:386
bool OpenLink(const std::string &url)
Open a URL.
Definition: OS.cpp:276
boost::filesystem::directory_entry dirEnt_t
Definition: OS.h:59
luabind::object val
Definition: Rulebook.cpp:52
bool OpenPath(const path_t &path)
Open a filesystem path.
Definition: OS.cpp:317
Definition: Announcement.h:24
int64_t MR_Int64
Definition: MR_Types.h:45
const std::locale & stdLocale
The standard "C" locale for things that should be not be affected by locale.
Definition: OS.cpp:101
void TimeShutdown()
Shutdown the OS time source.
Definition: OS.cpp:266
Definition: Symbol.h:253
MR_Int64 timestamp_t
Definition: OS.h:55