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> |
32 #if !defined(_MSC_VER) && !defined(__cdecl) |
33 #include <functional> |
33 # define __cdecl |
|
34 #endif |
34 |
35 |
35 #define FUNCTION auto |
|
36 #define STATIC |
|
37 #define METHOD auto |
|
38 #define MACRO_TO_STRING_2(A) #A |
36 #define MACRO_TO_STRING_2(A) #A |
39 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A) |
37 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A) |
40 |
38 |
41 class String; |
39 // The Windows SDK appears to use identifiers that conflicts with the identifiers defined in ZFC, |
|
40 // so they have to be put in a namespace. |
|
41 #define BEGIN_ZFC_NAMESPACE namespace zfc { |
|
42 #define END_ZFC_NAMESPACE } |
42 |
43 |
43 using std::swap; |
44 // Goddamnit, MSVC |
44 using std::min; |
45 #ifdef _MSC_VER |
45 using std::max; |
46 # define and && |
46 |
47 # define or || |
47 template<typename Signature> |
48 # define not ! |
48 using Function = std::function<Signature>; |
49 #endif |
49 |
|
50 // ------------------------------------------------------------------------------------------------- |
|
51 // |
|
52 enum Color |
|
53 { |
|
54 BLACK, |
|
55 RED, |
|
56 GREEN, |
|
57 YELLOW, |
|
58 BLUE, |
|
59 MAGENTA, |
|
60 CYAN, |
|
61 WHITE, |
|
62 DEFAULT, |
|
63 |
|
64 NUM_COLORS |
|
65 }; |
|
66 |
50 |
67 #define TEXTCOLOR_Escape "\x1C" |
51 #define TEXTCOLOR_Escape "\x1C" |
68 #define TEXTCOLOR_Black TEXTCOLOR_Escape "M" |
52 #define TEXTCOLOR_Black TEXTCOLOR_Escape "M" |
69 #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U" |
53 #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U" |
70 #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C" |
54 #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C" |
79 #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N" |
63 #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N" |
80 #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T" |
64 #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T" |
81 #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V" |
65 #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V" |
82 #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-" |
66 #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-" |
83 |
67 |
84 // ------------------------------------------------------------------------------------------------- |
68 #undef min |
85 // |
69 #undef max |
86 FUNCTION print_to_console (String a) -> void; |
|
87 |
70 |
88 // ------------------------------------------------------------------------------------------------- |
71 BEGIN_ZFC_NAMESPACE |
89 // |
72 |
90 template<typename T> inline FUNCTION |
73 template<typename T> |
91 clamp (T a, T b, T c) -> T |
74 T min (T a, T b) |
|
75 { |
|
76 return (a < b) ? a : b; |
|
77 } |
|
78 |
|
79 template<typename T> |
|
80 T max (T a, T b) |
|
81 { |
|
82 return (a > b) ? a : b; |
|
83 } |
|
84 |
|
85 template<typename T> |
|
86 T clamp (T a, T b, T c) |
92 { |
87 { |
93 return (a < b) ? b : (a > c) ? c : a; |
88 return (a < b) ? b : (a > c) ? c : a; |
94 } |
89 } |
95 |
90 |
96 // ------------------------------------------------------------------------------------------------- |
|
97 // |
|
98 struct Exitception {}; |
91 struct Exitception {}; |
|
92 |
|
93 END_ZFC_NAMESPACE |