Thu, 28 Jan 2021 11:39:48 +0200
merged with default
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
190 | 2 | Copyright 2014 - 2021 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 |
181
e254398fcc7c
removed Container classes in favor of std::vector
Teemu Piippo <teemu@hecknology.net>
parents:
179
diff
changeset
|
32 | #include <cassert> |
191
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
33 | #include <cstdlib> |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
161
diff
changeset
|
34 | #include <type_traits> |
114
0e7f3ecdf65a
Need to `#include <stdlib.h>` in basics.h or md5.cpp doesn't compile under Linux/Clang
Teemu Piippo <crimsondusk64@gmail.com>
parents:
113
diff
changeset
|
35 | |
87
53c2aecb9704
some work on MSVC support (still doesn't work yet...)
Teemu Piippo <tsapii@utu.fi>
parents:
85
diff
changeset
|
36 | #if !defined(_MSC_VER) && !defined(__cdecl) |
85 | 37 | # define __cdecl |
38 | #endif | |
39 | ||
1
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | #define MACRO_TO_STRING_2(A) #A |
4dd5bde4e777
- a whole lot of supplementary source code!!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | #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
|
42 | |
89
777b2a10b835
Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents:
88
diff
changeset
|
43 | // The Windows SDK appears to use identifiers that conflicts with the identifiers defined in ZFC, |
777b2a10b835
Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents:
88
diff
changeset
|
44 | // so they have to be put in a namespace. |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
45 | #define BEGIN_ZFC_NAMESPACE namespace zfc { |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
46 | #define END_ZFC_NAMESPACE } |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
47 | |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
48 | // Goddamnit, MSVC |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
49 | #ifdef _MSC_VER |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
50 | # define and && |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
51 | # define or || |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
52 | # define not ! |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
53 | #endif |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
54 | |
70 | 55 | #define TEXTCOLOR_Escape "\x1C" |
56 | #define TEXTCOLOR_Black TEXTCOLOR_Escape "M" | |
57 | #define TEXTCOLOR_Gray TEXTCOLOR_Escape "U" | |
58 | #define TEXTCOLOR_Silver TEXTCOLOR_Escape "C" | |
59 | #define TEXTCOLOR_White TEXTCOLOR_Escape "J" | |
60 | #define TEXTCOLOR_Red TEXTCOLOR_Escape "R" | |
61 | #define TEXTCOLOR_BrightRed TEXTCOLOR_Escape "G" | |
62 | #define TEXTCOLOR_Green TEXTCOLOR_Escape "Q" | |
63 | #define TEXTCOLOR_BrightGreen TEXTCOLOR_Escape "D" | |
64 | #define TEXTCOLOR_Yellow TEXTCOLOR_Escape "K" | |
65 | #define TEXTCOLOR_BrightYellow TEXTCOLOR_Escape "F" | |
66 | #define TEXTCOLOR_Blue TEXTCOLOR_Escape "H" | |
67 | #define TEXTCOLOR_BrightBlue TEXTCOLOR_Escape "N" | |
68 | #define TEXTCOLOR_Magenta TEXTCOLOR_Escape "T" | |
69 | #define TEXTCOLOR_BrightCyan TEXTCOLOR_Escape "V" | |
70 | #define TEXTCOLOR_Reset TEXTCOLOR_Escape "-" | |
71 | ||
93 | 72 | #undef min |
73 | #undef max | |
74 | ||
89
777b2a10b835
Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents:
88
diff
changeset
|
75 | BEGIN_ZFC_NAMESPACE |
777b2a10b835
Add support for standard pdcurses, thanks to Leonard for pointing out the solutions to a few mysteries.
Teemu Piippo <tsapii@utu.fi>
parents:
88
diff
changeset
|
76 | |
191
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
77 | template<typename T, typename TT> |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
78 | constexpr std::common_type_t<T, TT> min(T a, TT b) |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
79 | { |
99
f9f73eeba3b7
Fixed crashing problems: min and max had their logic inverted and Bytestream::read_string moved the cursor too early
Teemu Piippo <tsapii@utu.fi>
parents:
93
diff
changeset
|
80 | return (a < b) ? a : b; |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
81 | } |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
82 | |
161
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
83 | template<typename ContainerType> |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
84 | typename ContainerType::value_type min(const ContainerType& container) |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
85 | { |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
86 | typename ContainerType::value_type result; |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
87 | |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
88 | for (typename ContainerType::value_type element : container) |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
89 | result = min(result, element); |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
90 | |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
91 | return result; |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
92 | } |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
93 | |
191
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
94 | template<typename T, typename TT> |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
95 | constexpr std::common_type_t<T, TT> max(T a, TT b) |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
96 | { |
99
f9f73eeba3b7
Fixed crashing problems: min and max had their logic inverted and Bytestream::read_string moved the cursor too early
Teemu Piippo <tsapii@utu.fi>
parents:
93
diff
changeset
|
97 | return (a > b) ? a : b; |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
98 | } |
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
99 | |
161
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
100 | template<typename ContainerType> |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
101 | typename ContainerType::value_type max(const ContainerType& container) |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
102 | { |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
103 | typename ContainerType::value_type result; |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
104 | |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
105 | for (typename ContainerType::value_type element : container) |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
106 | result = max(result, element); |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
107 | |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
108 | return result; |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
109 | } |
1c483b54ddcb
Added versions of min() and max() that find the smallest and largest values in an iterable.
Teemu Piippo <teemu@compsta2.com>
parents:
157
diff
changeset
|
110 | |
179
7fc34735178e
start cleaning up unused code
Teemu Piippo <teemu@hecknology.net>
parents:
161
diff
changeset
|
111 | template<typename T, typename TT, typename TTT> |
191
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
112 | constexpr std::common_type_t<T, TT, TTT> clamp(T a, TT b, TTT c) |
17
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
113 | { |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
114 | return (a < b) ? b : (a > c) ? c : a; |
50341dec533e
- added command sending
Teemu Piippo <crimsondusk64@gmail.com>
parents:
15
diff
changeset
|
115 | } |
27
089e37c0887e
- now exits cleanly with ^Q!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
17
diff
changeset
|
116 | |
157
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
114
diff
changeset
|
117 | inline const char *plural(int value) |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
114
diff
changeset
|
118 | { |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
114
diff
changeset
|
119 | return value != 1 ? "s" : ""; |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
114
diff
changeset
|
120 | } |
42bb29924218
Bytestream now behaves more like a cursor. It does not store the data anymore, rather it leaves the user to specify a vector to use for storage.
Teemu Piippo <teemu@compsta2.com>
parents:
114
diff
changeset
|
121 | |
191
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
122 | template<typename T, std::size_t N> |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
123 | constexpr std::size_t countof(T(&)[N]) |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
124 | { |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
125 | return N; |
2e6cbacafdc7
various little touchups
Teemu Piippo <teemu@hecknology.net>
parents:
190
diff
changeset
|
126 | } |
113
b3a33bc2e482
Added support for long-form color codes, such as \c[Green]
Teemu Piippo <crimsondusk64@gmail.com>
parents:
109
diff
changeset
|
127 | |
189
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
128 | #ifdef __GNUC__ |
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
129 | # define GNUATTRIBUTE(X) __attribute__(X) |
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
130 | #else |
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
131 | # define GNUATTRIBUTE(X) |
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
132 | #endif |
248d0b85cbda
various changes, better network error handling
Teemu Piippo <teemu@hecknology.net>
parents:
181
diff
changeset
|
133 | |
88
08ccaf26cffd
Now works with MSVC 2010/pdcurses-win32a
Teemu Piippo <tsapii@utu.fi>
parents:
87
diff
changeset
|
134 | END_ZFC_NAMESPACE |