MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
datatypes.h
Go to the documentation of this file.
1 // © Copyright 2010 - 2014 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 here. Additionally, this is where all of the other singular header inclusions go as well.
47 ///////////////////////////////////////
48 
49 /// @def MEZZANINE_CORE
50 /// @brief Only defined in the Mezzanine and none of the Sattelite libraries
51 /// @details Some parts of the code are in the Mezzanine and other libraries, Only
52 /// the Mezzanine defines this to allow that code to fully integrate its behaviour.
53 #define MEZZANINE_CORE 1
54 
55 #include "crossplatformexport.h"
56 //#include "pstdint.h" // A reimplimentation of the C99 stdint.h for all compilers
57 
58 // Standard Headers are not included in SWIG preprocessing
59 // Most std includes are centralized here to make modifying this list as simple as possible. Other standard includes that
60 // are not included here are in places that they are required and conditionally may not be compiled in. For example,
61 
62 #ifndef SWIG
63  #if defined( _MSC_VER )
64  #include "pstdint.h"
65  #else
66  #include <stdint.h> //Not available in all version of mscv
67  #endif
68  #include <cstddef>
69 
70  #include <algorithm>
71  #include <exception>
72  #include <istream>
73  #include <list>
74  #include <map>
75  #include <string>
76  #include <sstream>
77  #include <fstream>
78  #include <set>
79  #include <vector>
80  #include <utility>
81  #include <memory>
82  #include <ostream>
83 #endif
84 
85 #include "swig.h"
86 
87 /// @internal
88 /// @brief Forward declaration for SDL compatibilty
89 union SDL_Event;
90 
91 namespace Mezzanine
92 {
93  ///////////////////////////////////////////////////////////////////////////////
94  // Datatypes
95  ///////////////////////////////////////
96 
97  #ifdef _MEZZ_CPP11_PARTIAL_
98  #ifndef SWIG
99  //#include <cstdint>
100  #endif
101  /// @brief A type that any pointer can be converted to and back from, and insures after the conversion back it will be identical.
102  typedef std::intptr_t ConvertiblePointer;
103  #else
104  #ifndef SWIG
105  //#include <stdint.h>
106  #endif
107  /// @brief A type that any pointer can be converted to and back from, and insures after the conversion back it will be identical.
108  typedef intptr_t ConvertiblePointer;
109  #endif
110 
111  /// @typedef Int8
112  /// @brief An 8-bit integer.
113  typedef int8_t Int8;
114  /// @typedef UInt8
115  /// @brief An 8-bit unsigned integer.
116  typedef uint8_t UInt8;
117  /// @typedef Int16
118  /// @brief An 16-bit integer.
119  typedef int16_t Int16;
120  /// @typedef UInt16
121  /// @brief An 16-bit unsigned integer.
122  typedef uint16_t UInt16;
123  /// @typedef Int32
124  /// @brief An 32-bit integer.
125  typedef int32_t Int32;
126  /// @typedef UInt32
127  /// @brief An 32-bit unsigned integer.
128  typedef uint32_t UInt32;
129  /// @typedef Int64
130  /// @brief An 64-bit integer.
131  typedef int64_t Int64;
132  /// @typedef UInt64
133  /// @brief An 64-bit unsigned integer.
134  typedef uint64_t UInt64;
135 
136  /// @typedef Real
137  /// @brief A Datatype used to represent a real floating point number.
138  /// @details This Datatype is currently a typedef to a float, This is to match
139  /// our compilations of Ogre (rendering subsystem ogre::Real), and Bullet (physics
140  /// subsystem, btScalar). With a recompilation of all the subsystems and this
141  /// there is no theoretical reason why this could not be changed to a
142  /// double, or even something more extreme like a GMP datatype. Most likely this
143  /// switch would require atleast some troubleshooting.
144  typedef float Real;
145  /// @typedef PreciseReal
146  /// @brief A Real number that is at least as precise as the Real and could be considerabll moreso
147  typedef double PreciseReal;
148 
149  /// @typedef Whole
150  /// @brief Whole is an unsigned integer, it will be at least 32bits in size.
151  /// @details This is a typedef to unsigned Long. but could be smaller in some situations. In
152  /// general it will be the most efficient unsigned type for math.
153  typedef unsigned long Whole;
154  /// @typedef Integer
155  /// @brief A datatype used to represent any integer close to.
156  /// @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.
157  typedef int Integer;
158 
159  /// @typedef String
160  /// @brief A datatype used to a series of characters.
161  /// @details This is a typedef to std::string, but could change particularly if UTF16 or UTF32 support is desired. If this is
162  /// changed, The Character typedef should be adjusted accordingly.
163  typedef std::string String;
164  /// @typedef WideString
165  /// @brief A wide version of the String typedef.
166  /// @details Wide strings are seldom used, but often come in handy when dealing with Unicode strings.
167  typedef std::wstring WideString;
168  /// @typedef ConstString
169  /// @brief A Datatype used to a series of imutable characters.
170  /// @details This is a typedef to const String, but could change.
171  typedef const String ConstString;
172 
173  /// @typedef Char8
174  /// @brief A datatype to represent one character.
175  /// @details This should be a char if String is an std::string.
176  typedef char Char8;
177 
178  /// @typedef Bool
179  /// @brief Generally acts a single bit, true or false
180  /// @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.
181  typedef bool Boolean;
182 
183  /// @typedef StringStream
184  /// @brief A Datatype used for streaming operations with strings.
185  typedef std::stringstream StringStream;
186 
187  /// @brief In case we ever replace the stringstream with another class, this will allow us to swap it out.
188  /// @details This will always support <<, str() but may lose support for formatting functions like std::hex.
189  typedef std::stringstream Logger;
190 
191  /// @brief A large integer type suitable for compile time math and long term microsecond time keeping.
192  /// @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.
193  /// 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
194  /// 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
195  /// 292 years.
196  #ifdef _MEZZ_CPP11_PARTIAL_
197  typedef intmax_t MaxInt;
198  #else
199  typedef long long MaxInt;
200  #endif
201 
202  /// @typedef TimeMarker
203  /// @brief A datatype used to indicate a specific point in time, or a timestamp.
204  /// @details This is made into it's own datatype in case we want to tweak the possible size for a timestamp.
206 
207  ///////////////////////////////////////////////////////////////////////////////
208  // Complex Data types
209  ///////////////////////////////////////
210 
211  /// @typedef NameValuePair
212  /// @brief This is a pair for the generic storage of a value and it's associated name.
213  typedef std::pair< String, String > NameValuePair;
214 
215  /// @typedef NameValuePairList
216  /// @brief This is a datatype mostly used for describing settings or parameters that can't be declared in advance.
217  /// @details This datatype uses the std::list container for it's storage.
218  typedef std::list< NameValuePair > NameValuePairList;
219 
220  /// @typedef NameValuePairMap
221  /// @brief This is a datatype mostly used for describing settings or parameters that can't be declared in advance.
222  /// @details This datatype uses the std::map container for it's storage.
223  typedef std::map< String, String > NameValuePairMap;
224 
225  /// @typedef StringVector
226  /// @brief This is a simple datatype for a vector container of strings.
227  typedef std::vector< String > StringVector;
228 
229  /// @typedef StringSet
230  /// @brief This is a simple datatype for a set container of strings.
231  typedef std::set< String > StringSet;
232 
233  /// @internal
234  /// @typedef RawEvent
235  /// @brief This is an internal datatype use to communicate with the User input Subsystem.
236  /// @details This is a typedef to SDL_Event. See the SDL Documentation for more details.
237  typedef SDL_Event RawEvent;
238 
239  ///////////////////////////////////////////////////////////////////////////////
240  // Simple conversion functions
241  ///////////////////////////////////////
242 
243  /// @brief Catch all Lexigraphical Conversion.
244  /// @param Datum A value of any type that will be converted.
245  /// @return The value as if 'read' into the target type.
246  /// @todo Overload ConvertTo for ToString Conversions.
247  template<typename To, typename From>
248  To ConvertTo(const From& Datum)
249  {
250  std::stringstream Converter;
251  Converter << Datum;
252  To Results;
253  Converter >> Results;
254  return Results;
255  }
256 
257  /// @brief Converts whatever to a String as long as a streaming operator is available for it.
258  /// @param Datum The whatever to be converted.
259  /// @return A String with the converted data.
260  template<class T> String ToString( const T& Datum )
261  {
262  //std::stringstream Converter;
263  // ©onverter << Datum;
264  //return Converter.str();
265  return ConvertTo<String>(Datum);
266  }
267 
268  /// @brief Converts whatever to a Whole as long as the proper streaming operators are available for it.
269  /// @param Datum The whatever to be converted.
270  /// @return A Whole with the converted data.
271  template<class T> Whole ToWhole( const T& Datum )
272  { return ConvertTo<Whole>(Datum); }
273 
274  /// @brief Converts whatever to an Integer as long as the proper streaming operators are available for it.
275  /// @param Datum The whatever to be converted.
276  /// @return An Integer with the converted data.
277  template<class T> Integer ToInteger( const T& Datum )
278  { return ConvertTo<Integer>(Datum); }
279 
280  /// @brief Converts whatever to an int as long as the proper streaming operators are available for it.
281  /// @param Datum The whatever to be converted.
282  /// @return An int with the converted data.
283  /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
284  /// break things.
285  template<class T> int Toint( const T& Datum )
286  { return ConvertTo<int>(Datum); }
287 
288  /// @brief Converts whatever to an unsigned int as long as the proper streaming operators are available for it.
289  /// @param Datum The whatever to be converted.
290  /// @return An unsigned int with the converted data.
291  /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
292  /// break things.
293  template<class T> unsigned int Tounsignedint( const T& Datum )
294  { return ConvertTo<unsigned int>(Datum); }
295 
296  /// @brief Converts whatever to a Real as long as the proper streaming operators are available for it.
297  /// @param Datum The whatever to be converted.
298  /// @return A Real with the converted data.
299  template<class T> Real ToReal( const T& Datum )
300  { return ConvertTo<Real>(Datum); }
301 
302  /// @brief Converts whatever to a Boolean as long as the proper streaming operators are available for it
303  /// @param Datum The whatever to be converted
304  /// @return A Bool with the converted data
305  template<class T> Boolean ToBool( const T& Datum )
306  { return ConvertTo<Boolean>(Datum); }
307 
308  /// @brief Converts whatever to a float as long as the proper streaming operators are available for it
309  /// @param Datum The whatever to be converted
310  /// @return A float with the converted data
311  /// @details This exists for interacting with other libraies, in situations where changing the Real Typedef could
312  /// break things.
313  template<class T> float Tofloat( const T& Datum )
314  { return ConvertTo<float>(Datum); }
315 
316  /// @brief Converts whatever to a double as long as the proper streaming operators are available for it.
317  /// @param Datum The whatever to be converted.
318  /// @return A double with the converted data.
319  /// @details This exists for interacting with other libraies, in situations where changing the Typedefs could break things.
320  template<class T> double Todouble( const T& Datum )
321  { return ConvertTo<double>(Datum); }
322 }//Mezzanine
323 
324 #endif