Spinning Topp Logo BlackTopp Studios
inc
datatypes.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2016 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 #ifndef _datatypes_h
41 #define _datatypes_h
42 
43 ///////////////////////////////////////////////////////////////////////////////
44 // Any Special data types that we need will get declared right here
45 /// @file
46 /// @brief All the definitions for datatypes as well as some basic conversion functions are defined
47 /// here. Additionally, this is where all of the other singular header inclusions go as well.
48 ///////////////////////////////////////
49 
50 /// @def MEZZANINE_CORE
51 /// @brief Only defined in the Mezzanine and none of the Sattelite libraries
52 /// @details Some parts of the code are in the Mezzanine and other libraries, Only
53 /// the Mezzanine defines this to allow that code to fully integrate its behaviour.
54 #define MEZZANINE_CORE 1
55 
56 #include "crossplatformexport.h"
57 //#include "pstdint.h" // A reimplimentation of the C99 stdint.h for all compilers
58 
59 // Standard Headers are not included in SWIG preprocessing
60 // Most std includes are centralized here to make modifying this list as simple as possible. Other
61 // standard includes that are not included here are in places that they are required and
62 // conditionally may not be compiled in. For example,
63 
64 #ifndef SWIG
65  #if defined( _MSC_VER )
66  #include "pstdint.h"
67  #else
68  #include <stdint.h> //Not available in all version of mscv
69  #endif
70  #include <cstddef>
71 
72  #include <algorithm>
73  #include <exception>
74  #include <istream>
75  #include <list>
76  #include <map>
77  #include <string>
78  #include <sstream>
79  #include <fstream>
80  #include <set>
81  #include <vector>
82  #include <utility>
83  #include <memory>
84  #include <ostream>
85 #endif
86 
87 #include "swig.h"
88 
89 /// @internal
90 /// @brief Forward declaration for SDL compatibilty
91 union SDL_Event;
92 
93 namespace Mezzanine
94 {
95  ///////////////////////////////////////////////////////////////////////////////
96  // Datatypes
97  ///////////////////////////////////////
98 
99  #ifdef _MEZZ_CPP11_PARTIAL_
100  #ifndef SWIG
101  //#include <cstdint>
102  #endif
103  /// @brief A type that any pointer can be converted to and back from, and insures after the
104  /// conversion back it will be identical.
105  typedef std::intptr_t ConvertiblePointer;
106  #else
107  #ifndef SWIG
108  //#include <stdint.h>
109  #endif
110  /// @brief A type that any pointer can be converted to and back from, and insures after the
111  /// conversion back it will be identical.
112  typedef intptr_t ConvertiblePointer;
113  #endif
114 
115  /// @brief An 8-bit integer.
116  typedef int8_t Int8;
117  /// @brief An 8-bit unsigned integer.
118  typedef uint8_t UInt8;
119  /// @brief An 16-bit integer.
120  typedef int16_t Int16;
121  /// @brief An 16-bit unsigned integer.
122  typedef uint16_t UInt16;
123  /// @brief An 32-bit integer.
124  typedef int32_t Int32;
125  /// @brief An 32-bit unsigned integer.
126  typedef uint32_t UInt32;
127  /// @brief An 64-bit integer.
128  typedef int64_t Int64;
129  /// @brief An 64-bit unsigned integer.
130  typedef uint64_t UInt64;
131 
132  /// @brief A Datatype used to represent a real floating point number.
133  /// @details This Datatype is currently a typedef to a float, This is to match
134  /// our compilations of Ogre (rendering subsystem ogre::Real), and Bullet (physics
135  /// subsystem, btScalar). With a recompilation of all the subsystems and this
136  /// there is no theoretical reason why this could not be changed to a
137  /// double, or even something more extreme like a GMP datatype. Most likely this
138  /// switch would require atleast some troubleshooting.
139  /// @n @n
140  /// This type will be word aligned and fast
141  typedef float Real;
142  /// @brief A Real number that is at least as precise as the Real and could be considerably
143  /// moreso, perhaps Doubly precise.
144  /// @n @n
145  /// This type might be poorly aligned but very precise.
146  typedef double PreciseReal;
147 
148  /// @brief Whole is an unsigned integer, it will be at least 32bits in size.
149  /// @details This is a typedef to unsigned Long. but could be smaller in some situations. In
150  /// general it will be the most efficient unsigned type for math.
151  typedef unsigned long Whole;
152  /// @brief A datatype used to represent any integer close to.
153  /// @details This is a typedef to int, but could int16 or smaller to improve performance in some situtations, In general it will be the most efficient signed type for math.
154  typedef int Integer;
155 
156  /// @brief A datatype used to a series of characters.
157  /// @details This is a typedef to std::string, but could change particularly if UTF16 or UTF32 support is desired. If this is
158  /// changed, The Character typedef should be adjusted accordingly.
159  typedef std::string String;
160  /// @brief A wide version of the String typedef.
161  /// @details Wide strings are seldom used, but often come in handy when dealing with Unicode strings.
162  typedef std::wstring WideString;
163  /// @brief A Datatype used to a series of imutable characters.
164  /// @details This is a typedef to const String, but could change.
165  typedef const String ConstString;
166 
167  /// @brief A datatype to represent one character.
168  /// @details This should be a char if String is an std::string.
169  typedef char Char8;
170 
171  /// @brief Generally acts a single bit, true or false
172  /// @details Normally just a bool, but on some platform alignment matters more than size, so this could be as large as one cpu word in size.
173  typedef bool Boole;
174 
175  /// @brief A Datatype used for streaming operations with strings.
176  typedef std::stringstream StringStream;
177 
178  /// @brief In case we ever replace the stringstream with another class, this will allow us to swap it out.
179  /// @details This will always support <<, str() but may lose support for formatting functions like std::hex.
180  typedef std::stringstream Logger;
181 
182  /// @brief A large integer type suitable for compile time math and long term microsecond time keeping.
183  /// @details For reference when this is a 64 bit integer, it can store a number between −9,223,372,036,854,775,808 and 9,223,372,036,854,775,807.
184  /// In seconds that is approximately 292,277,000,000 years and the universe is only 14,600,000,000 years old. So this is good for any time between
185  /// 20x the age of the universe before and after the beginning of any chosen epoch. Even if used to track nanoseconds it should be good for
186  /// 292 years.
187  #ifdef _MEZZ_CPP11_PARTIAL_
188  typedef intmax_t MaxInt;
189  #else
190  typedef long long MaxInt;
191  #endif
192 
193  /// @brief A datatype used to indicate a specific point in time, or a timestamp.
194  /// @details This is made into it's own datatype in case we want to tweak the possible size for a timestamp.
195  typedef UInt32 TimeMarker;
196 
197  ///////////////////////////////////////////////////////////////////////////////
198  // Complex Data types
199  ///////////////////////////////////////
200 
201  /// @brief This is a pair for the generic storage of a value and it's associated name.
202  typedef std::pair< String, String > NameValuePair;
203 
204  /// @brief This is a datatype mostly used for describing settings or parameters that can't be declared in advance.
205  /// @details This datatype uses the std::list container for it's storage.
206  typedef std::list< NameValuePair > NameValuePairList;
207  /// @brief This is a datatype mostly used for describing settings or parameters that can't be declared in advance.
208  /// @details This datatype uses the std::map container for it's storage.
209  typedef std::map< String, String > NameValuePairMap;
210 
211  /// @brief This is a simple datatype for a vector container of strings.
212  typedef std::vector< String > StringVector;
213  /// @brief This is a simple datatype for a set container of strings.
214  typedef std::set< String > StringSet;
215 
216  /// @internal
217  /// @brief This is an internal datatype use to communicate with the User input Subsystem.
218  /// @details This is a typedef to SDL_Event. See the SDL Documentation for more details.
219  typedef SDL_Event RawEvent;
220 
221  ///////////////////////////////////////////////////////////////////////////////
222  // Simple conversion functions
223  ///////////////////////////////////////
224 
225  /// @brief Catch all Lexigraphical Conversion.
226  /// @param Datum A value of any type that will be converted.
227  /// @return The value as if 'read' into the target type.
228  /// @todo Overload ConvertTo for ToString Conversions.
229  template<typename To, typename From>
230  To ConvertTo(const From& Datum)
231  {
232  std::stringstream Converter;
233  Converter << Datum;
234  To Results;
235  Converter >> Results;
236  return Results;
237  }
238 
239  /// @brief Converts whatever to a String as long as a streaming operator is available for it.
240  /// @param Datum The whatever to be converted.
241  /// @return A String with the converted data.
242  template<class T> String ToString( const T& Datum )
243  {
244  std::stringstream Converter;
245  Converter << Datum;
246  return Converter.str();
247  }
248 
249  /// @brief Converts whatever to a Whole as long as the proper streaming operators are available for it.
250  /// @param Datum The whatever to be converted.
251  /// @return A Whole with the converted data.
252  template<class T> Whole ToWhole( const T& Datum )
253  { return ConvertTo<Whole>(Datum); }
254 
255  /// @brief Converts whatever to an Integer as long as the proper streaming operators are available for it.
256  /// @param Datum The whatever to be converted.
257  /// @return An Integer with the converted data.
258  template<class T> Integer ToInteger( const T& Datum )
259  { return ConvertTo<Integer>(Datum); }
260 
261  /// @brief Converts whatever to an int as long as the proper streaming operators are available for it.
262  /// @param Datum The whatever to be converted.
263  /// @return An int with the converted data.
264  /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
265  /// break things.
266  template<class T> int Toint( const T& Datum )
267  { return ConvertTo<int>(Datum); }
268 
269  /// @brief Converts whatever to an unsigned int as long as the proper streaming operators are available for it.
270  /// @param Datum The whatever to be converted.
271  /// @return An unsigned int with the converted data.
272  /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
273  /// break things.
274  template<class T> unsigned int Tounsignedint( const T& Datum )
275  { return ConvertTo<unsigned int>(Datum); }
276 
277  /// @brief Converts whatever to a Real as long as the proper streaming operators are available for it.
278  /// @param Datum The whatever to be converted.
279  /// @return A Real with the converted data.
280  template<class T> Real ToReal( const T& Datum )
281  { return ConvertTo<Real>(Datum); }
282 
283  /// @brief Converts whatever to a Boole as long as the proper streaming operators are available for it
284  /// @param Datum The whatever to be converted
285  /// @return A Bool with the converted data
286  template<class T> Boole ToBool( const T& Datum )
287  { return ConvertTo<Boole>(Datum); }
288 
289  /// @brief Converts whatever to a float as long as the proper streaming operators are available for it
290  /// @param Datum The whatever to be converted
291  /// @return A float with the converted data
292  /// @details This exists for interacting with other libraies, in situations where changing the Real Typedef could
293  /// break things.
294  template<class T> float Tofloat( const T& Datum )
295  { return ConvertTo<float>(Datum); }
296 
297  /// @brief Converts whatever to a double as long as the proper streaming operators are available for it.
298  /// @param Datum The whatever to be converted.
299  /// @return A double with the converted data.
300  /// @details This exists for interacting with other libraies, in situations where changing the Typedefs could break things.
301  template<class T> double Todouble( const T& Datum )
302  { return ConvertTo<double>(Datum); }
303 }//Mezzanine
304 
305 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
std::vector< String > StringVector
This is a simple datatype for a vector container of strings.
Definition: datatypes.h:212
std::stringstream Logger
In case we ever replace the stringstream with another class, this will allow us to swap it out...
Definition: datatypes.h:180
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
This file is used on some platforms to determine what data should be read and written to and from a s...
Boole ToBool(const T &Datum)
Converts whatever to a Boole as long as the proper streaming operators are available for it...
Definition: datatypes.h:286
String ToString(const T &Datum)
Converts whatever to a String as long as a streaming operator is available for it.
Definition: datatypes.h:242
int Integer
A datatype used to represent any integer close to.
Definition: datatypes.h:154
unsigned int Tounsignedint(const T &Datum)
Converts whatever to an unsigned int as long as the proper streaming operators are available for it...
Definition: datatypes.h:274
uint8_t UInt8
An 8-bit unsigned integer.
Definition: datatypes.h:118
SDL_Event RawEvent
This is an internal datatype use to communicate with the User input Subsystem.
Definition: datatypes.h:219
std::set< String > StringSet
This is a simple datatype for a set container of strings.
Definition: datatypes.h:214
std::stringstream StringStream
A Datatype used for streaming operations with strings.
Definition: datatypes.h:176
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
char Char8
A datatype to represent one character.
Definition: datatypes.h:169
std::pair< String, String > NameValuePair
This is a pair for the generic storage of a value and it's associated name.
Definition: datatypes.h:202
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
std::wstring WideString
A wide version of the String typedef.
Definition: datatypes.h:162
int64_t Int64
An 64-bit integer.
Definition: datatypes.h:128
const String ConstString
A Datatype used to a series of imutable characters.
Definition: datatypes.h:165
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
UInt32 TimeMarker
A datatype used to indicate a specific point in time, or a timestamp.
Definition: datatypes.h:195
std::list< NameValuePair > NameValuePairList
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:206
int16_t Int16
An 16-bit integer.
Definition: datatypes.h:120
To ConvertTo(const From &Datum)
Catch all Lexigraphical Conversion.
Definition: datatypes.h:230
Real ToReal(const T &Datum)
Converts whatever to a Real as long as the proper streaming operators are available for it...
Definition: datatypes.h:280
uint64_t UInt64
An 64-bit unsigned integer.
Definition: datatypes.h:130
long long MaxInt
A large integer type suitable for compile time math and long term microsecond time keeping...
Definition: datatypes.h:190
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
double PreciseReal
A Real number that is at least as precise as the Real and could be considerably moreso, perhaps Doubly precise. This type might be poorly aligned but very precise.
Definition: datatypes.h:146
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Definition: datatypes.h:151
intptr_t ConvertiblePointer
A type that any pointer can be converted to and back from, and insures after the conversion back it w...
Definition: datatypes.h:112
Used to give commands specifically to the SWIG preprocessor.
float Tofloat(const T &Datum)
Converts whatever to a float as long as the proper streaming operators are available for it...
Definition: datatypes.h:294
int8_t Int8
An 8-bit integer.
Definition: datatypes.h:116
std::map< String, String > NameValuePairMap
This is a datatype mostly used for describing settings or parameters that can't be declared in advanc...
Definition: datatypes.h:209
int Toint(const T &Datum)
Converts whatever to an int as long as the proper streaming operators are available for it...
Definition: datatypes.h:266
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
double Todouble(const T &Datum)
Converts whatever to a double as long as the proper streaming operators are available for it...
Definition: datatypes.h:301
Integer ToInteger(const T &Datum)
Converts whatever to an Integer as long as the proper streaming operators are available for it...
Definition: datatypes.h:258
Whole ToWhole(const T &Datum)
Converts whatever to a Whole as long as the proper streaming operators are available for it...
Definition: datatypes.h:252