SDL Window Engine  20200905
swe_types.h
1 /***************************************************************************
2  * Copyright (C) 2017 by SWE team <sdl.window.engine@gmail.com> *
3  * *
4  * Part of the SWE: SDL Window Engine: *
5  * https://github.com/AndreyBarmaley/sdl-window-engine *
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 
23 #ifndef _SWE_TYPES_
24 #define _SWE_TYPES_
25 
26 #define MAXU16 0xFFFF
27 #define MAXU32 0xFFFFFFFF
28 
29 #define ARRAY_COUNT(A) sizeof(A) / sizeof(A[0])
30 #define ARRAY_COUNT_END(A) A + ARRAY_COUNT(A)
31 #define ARRAY_LAST(A) A + ARRAY_COUNT(A) - 1
32 
33 #include "SDL.h"
34 #ifndef SWE_DISABLE_TTF
35 #include "SDL_ttf.h"
36 #endif
37 #ifndef SWE_DISABLE_IMAGE
38 #include "SDL_image.h"
39 #endif
40 #ifndef SWE_DISABLE_AUDIO
41 #include "SDL_mixer.h"
42 #endif
43 #ifndef SWE_DISABLE_NETWORK
44 #include "SDL_net.h"
45 #endif
46 
47 #include <vector>
48 
49 typedef Sint8 s8;
50 typedef Uint8 u8;
51 typedef Sint16 s16;
52 typedef Uint16 u16;
53 typedef Sint32 s32;
54 typedef Uint32 u32;
55 typedef Sint64 s64;
56 typedef Uint64 u64;
57 
58 #ifndef PATH_MAX
59 #define PATH_MAX 4096
60 #endif
61 
62 #ifdef SWE_WITH_STD_MAP
63 #include <unordered_map>
64 #include <unordered_set>
65 #define swe_unordered_map std::unordered_map
66 #define swe_unordered_set std::unordered_set
67 #else
68 #include "flat_hash_map/unordered_map.hpp"
69 #define swe_unordered_map ska::unordered_map
70 #define swe_unordered_set ska::unordered_set
71 #endif
72 
73 #if defined __SYMBIAN32__
74 #undef PATH_MAX
75 #define PATH_MAX FILENAME_MAX
76 namespace std
77 {
78  int c_abs(int x);
79  float c_abs(float x);
80  double c_abs(double x);
81  int c_isspace(char c);
82 
83 #define isspace(c) c_isspace(c)
84 #define abs(x) c_abs(x)
85 }
86 using namespace std;
87 #endif
88 
89 #if defined __MINGW32CE__
90 #undef PATH_MAX
91 #define PATH_MAX 255
92 #endif
93 
94 #if defined __MINGW32__
95 #define S_IFSOCK 0140000
96 #define S_IFLNK 0120000
97 
98 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
99 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
100 #endif
101 
102 #if defined __MINGW32CE__
103 //#define S_IRWXU 00700
104 //#define S_IRUSR 00400
105 //#define S_IWUSR 00200
106 //#define S_IXUSR 00100
107 
108 #define S_IRWXG 00070
109 #define S_IRGRP 00040
110 #define S_IWGRP 00020
111 #define S_IXGRP 00010
112 
113 #define S_IRWXO 00007
114 #define S_IROTH 00004
115 #define S_IWOTH 00002
116 #define S_IXOTH 00001
117 #endif
118 
119 #define _(s) SWE::Translation::gettext(s)
120 #define _n(a,b,c) SWE::Translation::ngettext(a,b,c)
121 
123 namespace SWE
124 {
125  class StreamBase;
126 
127  struct packshort
128  {
129  protected:
130  u8 v1, v2;
131 
132  public:
133  packshort(u16 val = 0);
134  packshort(u8 val1, u8 val2);
135 
136  u16 operator()(void) const;
137  u16 value(void) const;
138 
139  const u8 & val1(void) const;
140  const u8 & val2(void) const;
141 
142  packshort & set1(u8);
143  packshort & set2(u8);
144  void setvalue(u16);
145 
146  bool operator< (const packshort &) const;
147  bool operator> (const packshort &) const;
148  bool operator== (const packshort &) const;
149  bool operator!= (const packshort &) const;
150  };
151 
152  StreamBase & operator<< (StreamBase &, const packshort &);
153  const StreamBase & operator>> (const StreamBase &, packshort &);
154 
155  struct packint
156  {
157  ~packint() {}
158 
159  u32 operator()(void) const { return value(); }
160 
161  virtual u32 value(void) const = 0;
162  virtual void setvalue(u32) = 0;
163 
164  bool operator< (const packint &) const;
165  bool operator> (const packint &) const;
166  bool operator== (const packint &) const;
167  bool operator!= (const packint &) const;
168  };
169 
170  StreamBase & operator<< (StreamBase &, const packint &);
171  const StreamBase & operator>> (const StreamBase &, packint &);
172 
173  struct packint2 : packint
174  {
175  protected:
176  u16 v1, v2;
177 
178  public:
179  packint2(u32 val = 0);
180  packint2(u16 val1, u16 val2);
181 
182  u32 value(void) const override;
183  void setvalue(u32) override;
184 
185  const u16 & val1(void) const;
186  const u16 & val2(void) const;
187 
188  packint2 & set1(u16);
189  packint2 & set2(u16);
190  };
191 
192  struct packint4 : packint
193  {
194  protected:
195  packshort v1, v2;
196 
197  public:
198  packint4(u32 val = 0);
199  packint4(u16 val1, u16 val2);
200  packint4(u8 val1, u8 val2, u8 val3, u8 val4);
201 
202  u32 value(void) const override;
203  void setvalue(u32) override;
204 
205  const u8 & val1(void) const;
206  const u8 & val2(void) const;
207  const u8 & val3(void) const;
208  const u8 & val4(void) const;
209 
210  packint4 & set1(u8);
211  packint4 & set2(u8);
212  packint4 & set3(u8);
213  packint4 & set4(u8);
214  };
215 
216  class BitFlags
217  {
218  u32 state;
219 
220  friend StreamBase & operator<< (StreamBase &, const BitFlags &);
221  friend const StreamBase & operator>> (const StreamBase &, BitFlags &);
222 
223  public:
224  BitFlags(int v = 0) : state(v) {}
225 
226  size_t operator()(void) const
227  {
228  return state;
229  }
230  size_t value(void) const
231  {
232  return state;
233  }
234 
235  void set(size_t v, bool f)
236  {
237  if(f) set(v);
238  else reset(v);
239  }
240  void set(size_t v)
241  {
242  state |= v;
243  }
244  void switched(size_t v)
245  {
246  set(v, ! check(v));
247  }
248  void reset(size_t v)
249  {
250  state &= ~v;
251  }
252  void reset(void)
253  {
254  state = 0;
255  }
256  bool check(size_t v) const
257  {
258  return state & v;
259  }
260 
261  int countBits(void) const;
262  std::vector<int> toVector(void) const;
263  };
264 
265  StreamBase & operator<< (StreamBase &, const BitFlags &);
266  const StreamBase & operator>> (const StreamBase &, BitFlags &);
267 
268 } // SWE
269 #endif
Definition: swe_types.h:192
Definition: swe_types.h:216
пространство SWE.
Definition: swe_binarybuf.cpp:30
Definition: swe_types.h:155
STL namespace.
Definition: swe_types.h:173
Definition: swe_types.h:127
Definition: swe_serialize.h:44