sources/basics.h

changeset 88
08ccaf26cffd
parent 87
53c2aecb9704
child 89
777b2a10b835
equal deleted inserted replaced
87:53c2aecb9704 88:08ccaf26cffd
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #pragma once 31 #pragma once
32 #include <algorithm>
33 #include <functional>
34 #include <cstdio>
35 #include <cstdlib>
36 #include <cstring>
37 #include <cctype>
38
39 #if !defined(_MSC_VER) && !defined(__cdecl) 32 #if !defined(_MSC_VER) && !defined(__cdecl)
40 # define __cdecl 33 # define __cdecl
41 #endif 34 #endif
42 35
43 #define MACRO_TO_STRING_2(A) #A 36 #define MACRO_TO_STRING_2(A) #A
44 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A) 37 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A)
45 38
39 #define BEGIN_ZFC_NAMESPACE namespace zfc {
40 #define END_ZFC_NAMESPACE }
41
42 BEGIN_ZFC_NAMESPACE
43
46 class String; 44 class String;
47 using std::swap;
48 using std::min;
49 using std::max;
50 45
51 // ------------------------------------------------------------------------------------------------- 46 // -------------------------------------------------------------------------------------------------
52 // 47 //
53 enum Color 48 enum Color
54 { 49 {
63 DEFAULT, 58 DEFAULT,
64 59
65 NUM_COLORS 60 NUM_COLORS
66 }; 61 };
67 62
63 // Goddamnit, MSVC
64 #ifdef _MSC_VER
65 # define and &&
66 # define or ||
67 # define not !
68 # define _CRT_SECURE_NO_WARNINGS
69 #endif
70
68 #define TEXTCOLOR_Escape "\x1C" 71 #define TEXTCOLOR_Escape "\x1C"
69 #define TEXTCOLOR_Black TEXTCOLOR_Escape "M" 72 #define TEXTCOLOR_Black TEXTCOLOR_Escape "M"
70 #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U" 73 #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U"
71 #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C" 74 #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C"
72 #define TEXTCOLOR_White TEXTCOLOR_Escape "J" 75 #define TEXTCOLOR_White TEXTCOLOR_Escape "J"
80 #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N" 83 #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N"
81 #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T" 84 #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T"
82 #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V" 85 #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V"
83 #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-" 86 #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-"
84 87
85 // -------------------------------------------------------------------------------------------------
86 //
87 template<typename T> 88 template<typename T>
88 inline T clamp (T a, T b, T c) 89 T min (T a, T b)
90 {
91 return (a < b) ? b : a;
92 }
93
94 template<typename T>
95 T max (T a, T b)
96 {
97 return (a > b) ? b : a;
98 }
99
100 template<typename T>
101 T clamp (T a, T b, T c)
89 { 102 {
90 return (a < b) ? b : (a > c) ? c : a; 103 return (a < b) ? b : (a > c) ? c : a;
91 } 104 }
92 105
93 // -------------------------------------------------------------------------------------------------
94 //
95 struct Exitception {}; 106 struct Exitception {};
107 END_ZFC_NAMESPACE

mercurial