Line data Source code
1 : #pragma once
2 : #include <string>
3 :
4 : #include <cstdlib>
5 : #include "str_utils.h"
6 :
7 :
8 : namespace Utils
9 : {
10 :
11 : #if defined(_WIN32) // or _MSC_VER
12 : # define IS_WINDOWS (1)
13 : #else
14 : # define IS_WINDOWS (0)
15 : #endif
16 :
17 : #if defined(__linux__)
18 : # define IS_LINUX (1)
19 : #else
20 : # define IS_LINUX (0)
21 : #endif
22 :
23 : #if defined(__APPLE__)
24 : # define IS_APPLE (1)
25 : #else
26 : # define IS_APPLE (0)
27 : #endif
28 :
29 : #if defined(__unix__)
30 : # define IS_UNIX (1)
31 : #else
32 : # define IS_UNIX (0)
33 : #endif
34 :
35 : constexpr static inline bool IsWindows()
36 : {
37 : #if IS_WINDOWS
38 : return true;
39 : #else
40 : return false;
41 : #endif
42 : }
43 :
44 : constexpr static inline bool IsApple()
45 : {
46 : #if IS_APPLE
47 : return true;
48 : #else
49 : return false;
50 : #endif
51 : }
52 :
53 : constexpr static inline bool IsLinux()
54 : {
55 : #if IS_LINUX
56 : return true;
57 : #else
58 : return false;
59 : #endif
60 : }
61 :
62 : constexpr static inline bool IsUnix()
63 : {
64 : #if IS_UNIX
65 : return true;
66 : #else
67 : return false;
68 : #endif
69 : }
70 :
71 0 : constexpr static inline bool IsDebug()
72 : {
73 : #if defined(_DEBUG)
74 : return true;
75 : #else
76 0 : return false;
77 : #endif
78 : }
79 :
80 : constexpr static inline bool IsRelease()
81 : {
82 : return !IsDebug();
83 : }
84 :
85 : constexpr static const char ENVIRONMENT_VARIABLE[] = "Environment";
86 :
87 0 : static inline bool IsEnvironment(const std::string& environmentName)
88 : {
89 0 : auto envValue = std::getenv(ENVIRONMENT_VARIABLE);
90 0 : if (envValue == nullptr) return false;
91 :
92 0 : return Utils::str_to_lower_copy(envValue) ==
93 0 : Utils::str_to_lower_copy(environmentName);
94 : }
95 :
96 0 : static inline bool IsLocal()
97 : {
98 0 : return IsEnvironment("Local");
99 : }
100 :
101 : static inline bool IsDevelopment()
102 : {
103 : return IsEnvironment("Development");
104 : }
105 :
106 : static inline bool IsTesting()
107 : {
108 : return IsEnvironment("Testing");
109 : }
110 :
111 : static inline bool IsStaging()
112 : {
113 : return IsEnvironment("Staging");
114 : }
115 :
116 : static inline bool IsProduction()
117 : {
118 : return IsEnvironment("Production");
119 : }
120 :
121 :
122 : #ifndef ARRAY_COUNT
123 : # define ARRAY_COUNT(array_) (sizeof(array_)/sizeof((array_)[0]))
124 : #endif
125 :
126 : #ifndef CSTR_COUNT
127 : # define CSTR_COUNT(cstr_) (ARRAY_COUNT(cstr_)-1)
128 : #endif
129 :
130 : }
|