sources/basics.h

Thu, 23 Jul 2015 00:16:47 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Thu, 23 Jul 2015 00:16:47 +0300
changeset 87
53c2aecb9704
parent 85
ed61569c501f
child 88
08ccaf26cffd
permissions
-rw-r--r--

some work on MSVC support (still doesn't work yet...)

1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
73
07dda51a7a8e Update license headers
Teemu Piippo <crimsondusk64@gmail.com>
parents: 70
diff changeset
2 Copyright 2014, 2015 Teemu Piippo
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 All rights reserved.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 Redistribution and use in source and binary forms, with or without
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 modification, are permitted provided that the following conditions
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 are met:
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 1. Redistributions of source code must retain the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 notice, this list of conditions and the following disclaimer.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 2. Redistributions in binary form must reproduce the above copyright
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 notice, this list of conditions and the following disclaimer in the
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 documentation and/or other materials provided with the distribution.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 3. Neither the name of the copyright holder nor the names of its
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 contributors may be used to endorse or promote products derived from
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 this software without specific prior written permission.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 */
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #pragma once
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 #include <algorithm>
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 #include <functional>
87
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
34 #include <cstdio>
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
35 #include <cstdlib>
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
36 #include <cstring>
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
37 #include <cctype>
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
87
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
39 #if !defined(_MSC_VER) && !defined(__cdecl)
85
ed61569c501f Fix compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
40 # define __cdecl
ed61569c501f Fix compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
41 #endif
ed61569c501f Fix compilation
Teemu Piippo <crimsondusk64@gmail.com>
parents: 73
diff changeset
42
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 #define MACRO_TO_STRING_2(A) #A
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A)
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
14
33b8f428bacb - begin work on interface - input line works for the most part :)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 5
diff changeset
46 class String;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 using std::swap;
5
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
48 using std::min;
146825d63b9a - code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1
diff changeset
49 using std::max;
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
60
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
51 // -------------------------------------------------------------------------------------------------
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
52 //
1
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 enum Color
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 {
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 BLACK,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 RED,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 GREEN,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 YELLOW,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 BLUE,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 MAGENTA,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 CYAN,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 WHITE,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 DEFAULT,
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 NUM_COLORS
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 };
4dd5bde4e777 - a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
70
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
68 #define TEXTCOLOR_Escape "\x1C"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
69 #define TEXTCOLOR_Black TEXTCOLOR_Escape "M"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
70 #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
71 #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
72 #define TEXTCOLOR_White TEXTCOLOR_Escape "J"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
73 #define TEXTCOLOR_Red TEXTCOLOR_Escape "R"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
74 #define TEXTCOLOR_BrightRed TEXTCOLOR_Escape "G"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
75 #define TEXTCOLOR_Green TEXTCOLOR_Escape "Q"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
76 #define TEXTCOLOR_BrightGreen TEXTCOLOR_Escape "D"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
77 #define TEXTCOLOR_Yellow TEXTCOLOR_Escape "K"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
78 #define TEXTCOLOR_BrightYellow TEXTCOLOR_Escape "F"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
79 #define TEXTCOLOR_Blue TEXTCOLOR_Escape "H"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
80 #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
81 #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
82 #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
83 #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-"
0e947b487b18 Yay colors
Teemu Piippo <crimsondusk64@gmail.com>
parents: 60
diff changeset
84
60
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
85 // -------------------------------------------------------------------------------------------------
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
86 //
87
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
87 template<typename T>
53c2aecb9704 some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents: 85
diff changeset
88 inline T clamp (T a, T b, T c)
17
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
89 {
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
90 return (a < b) ? b : (a > c) ? c : a;
50341dec533e - added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents: 15
diff changeset
91 }
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
92
60
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
93 // -------------------------------------------------------------------------------------------------
268721e6be20 - formatting
Teemu Piippo <crimsondusk64@gmail.com>
parents: 51
diff changeset
94 //
27
089e37c0887e - now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 17
diff changeset
95 struct Exitception {};

mercurial