MezzanineEngine March 18, 2012

datatypes.h

00001 //© Copyright 2010 - 2011 BlackTopp Studios Inc.
00002 /* This file is part of The Mezzanine Engine.
00003 
00004     The Mezzanine Engine is free software: you can redistribute it and/or modify
00005     it under the terms of the GNU General Public License as published by
00006     the Free Software Foundation, either version 3 of the License, or
00007     (at your option) any later version.
00008 
00009     The Mezzanine Engine is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU General Public License for more details.
00013 
00014     You should have received a copy of the GNU General Public License
00015     along with The Mezzanine Engine.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 /* The original authors have included a copy of the license specified above in the
00018    'Docs' folder. See 'gpl.txt'
00019 */
00020 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
00021    Build professional software and charge for their product.
00022 
00023    However there are some practical restrictions, so if your project involves
00024    any of the following you should contact us and we will try to work something
00025    out:
00026     - DRM or Copy Protection of any kind(except Copyrights)
00027     - Software Patents You Do Not Wish to Freely License
00028     - Any Kind of Linking to Non-GPL licensed Works
00029     - Are Currently In Violation of Another Copyright Holder's GPL License
00030     - If You want to change our code and not add a few hundred MB of stuff to
00031         your distribution
00032 
00033    These and other limitations could cause serious legal problems if you ignore
00034    them, so it is best to simply contact us or the Free Software Foundation, if
00035    you have any questions.
00036 
00037    Joseph Toppi - toppij@gmail.com
00038    John Blackwood - makoenergy02@gmail.com
00039 */
00040 #ifndef _datatypes_h
00041 #define _datatypes_h
00042 ///////////////////////////////////////////////////////////////////////////////
00043 //Any Special data types that we need will get declared right here
00044 ///////////////////////////////////////
00045 #include "swig.h"
00046 #include "crossplatformexport.h"
00047 
00048 // Standard Headers are not included in SWIG preprocessing
00049 // Most std includes are centralized here to make modifying this list as simple as possible. Other standard includes that
00050 // are not included here are in places that they are required and conditionally may not be compiled in. For example,
00051 // Serialization requires <memory> and <ostream> and can optionally be compiled as part of Mezz_XML.
00052 #ifndef SWIG
00053     #include <algorithm>
00054     #include <exception>
00055     #include <istream>
00056     #include <list>
00057     #include <map>
00058     #include <string>
00059     #include <sstream>
00060     #include <set>
00061     #include <vector>
00062     #include <utility>
00063 #endif
00064 
00065 /// @internal
00066 /// @brief Forward declaration for SDL compatibilty
00067 union SDL_Event;
00068 
00069 namespace Mezzanine
00070 {
00071     ///////////////////////////////////////////////////////////////////////////////
00072     // Datatypes
00073     ///////////////////////////////////////
00074 
00075     // "fixed-width" types from SFML
00076     /// @todo Verify that these "fixed-width" type-defs work on mobiles and tablets.
00077     /// @typedef Int8
00078     /// @brief An 8-bit integer.
00079     typedef signed char Int8;
00080     /// @typedef UInt8
00081     /// @brief An 8-bit unsigned integer.
00082     typedef unsigned char UInt8;
00083     /// @typedef Int16
00084     /// @brief An 16-bit integer.
00085     typedef signed short Int16;
00086     /// @typedef UInt16
00087     /// @brief An 16-bit unsigned integer.
00088     typedef unsigned short UInt16;
00089     /// @typedef Int32
00090     /// @brief An 32-bit integer.
00091     typedef signed long Int32;
00092     /// @typedef UInt32
00093     /// @brief An 32-bit unsigned integer.
00094     typedef unsigned long UInt32;
00095     #if defined(_MSC_VER)
00096     /// @typedef Int64
00097     /// @brief An 64-bit integer.
00098     typedef signed __int64 Int64;
00099     /// @typedef UInt64
00100     /// @brief An 64-bit unsigned integer.
00101     typedef unsigned __int64 UInt64;
00102     #else
00103     /// @typedef Int64
00104     /// @brief An 64-bit integer.
00105     typedef signed long long Int64;
00106     /// @typedef UInt64
00107     /// @brief An 64-bit unsigned integer.
00108     typedef unsigned long long UInt64;
00109     #endif
00110 
00111     /// @typedef Real
00112     /// @brief A Datatype used to represent a real floating point number
00113     /// @details This Datatype is currently a typedef to a float, This is to match
00114     /// our compilations of Ogre (rendering subsystem ogre::Real), and Bullet (physics
00115     /// subsystem, btScalar). With a recompilation of all the subsystems and  this
00116     /// there is no theoretical reason why this could not be changed to a
00117     /// double, or even something more extreme like a GMP datatype. Most likely this
00118     /// switch would require atleast some troubleshooting.
00119     typedef float Real;
00120 
00121     /// @typedef Whole
00122     /// @brief A Datatype used to represent an postive integer numbers
00123     /// @details This is a typedef to unsigned Long. but could be smaller in some situations
00124     typedef unsigned long Whole;
00125 
00126     /// @typedef Integer
00127     /// @brief A datatype use to represent any integer close to
00128     /// @details This is a typedef to int, but could int16 or smaller to improve performance in some situtations
00129     /// handheld platforms
00130     typedef int Integer;
00131 
00132     /// @typedef String
00133     /// @brief A Datatype used to a series of characters
00134     /// @details This is a typedef to std::string, but could change particularly if UTF16 or UTF32 support is desired. If this is
00135     /// changed, The Character typedef should be adjusted accordingly.
00136     typedef std::string String;
00137 
00138     /// @typedef WideString
00139     /// @brief A wide version of the String typedef.
00140     /// @details Wide strings are seldom used, but often come in handy when dealing with Unicode strings.
00141     typedef std::wstring WideString;
00142 
00143     /// @typedef ConstString
00144     /// @brief A Datatype used to a series of imutable characters
00145     /// @details This is a typedef to const String, but could change.
00146     typedef const String ConstString;
00147 
00148     /// @typedef Character
00149     /// @brief A datatype to represent one character.
00150     /// @details This should be a char if String is an std::string. The XML parser expects this to be either char or wchar_t
00151     /// and has not be test with external types. The XML Parser expects XML_WCHAR_MODE to be defined if wchar_t is used. A remarked
00152     /// definition of this exists near the Character typedef in datatypes.h
00153     typedef char Character;
00154     // #define XML_WCHAR_MODE   //UNREMARK ME if changing the above line to typedef wchar_t Character;
00155 
00156     /// @internal
00157     /// @typedef RawEvent
00158     /// @brief This is an internal datatype use to communicate with the User input Subsystem
00159     /// @details This is a typedef to SDL_Event. See the SDL Documentation for more details
00160     typedef SDL_Event RawEvent;
00161 
00162     ///////////////////////////////////////////////////////////////////////////////
00163     // Simple conversion functions
00164     ///////////////////////////////////////
00165 
00166     /// @brief Converts whatever to a String as long as a streaming operator is available for it
00167     /// @param Datum The whatever to be converted
00168     /// @return A String with the converted data
00169     template<class T> String ToString( const T& Datum )
00170     {
00171         std::stringstream Converter;
00172         Converter << Datum;
00173         return Converter.str();
00174     }
00175 
00176     /// @brief Converts whatever to a Whole as long as the proper streaming operators are available for it
00177     /// @param Datum The whatever to be converted
00178     /// @return A Whole with the converted data
00179     template<class T> Whole ToWhole( const T& Datum )
00180     {
00181         std::stringstream Converter;
00182         Converter << Datum;
00183         Whole Results;
00184         Converter >> Results;
00185         return Results;
00186     }
00187 
00188     /// @brief Converts whatever to an Integer as long as the proper streaming operators are available for it
00189     /// @param Datum The whatever to be converted
00190     /// @return An Integer with the converted data
00191     template<class T> Integer ToInteger( const T& Datum )
00192     {
00193         std::stringstream Converter;
00194         Converter << Datum;
00195         Integer Results;
00196         Converter >> Results;
00197         return Results;
00198     }
00199 
00200     /// @brief Converts whatever to an int as long as the proper streaming operators are available for it
00201     /// @param Datum The whatever to be converted
00202     /// @return An int with the converted data
00203     /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
00204     /// break things
00205     template<class T> int Toint( const T& Datum )
00206     {
00207         std::stringstream Converter;
00208         Converter << Datum;
00209         int Results;
00210         Converter >> Results;
00211         return Results;
00212     }
00213 
00214     /// @brief Converts whatever to an unsigned int as long as the proper streaming operators are available for it
00215     /// @param Datum The whatever to be converted
00216     /// @return An unsigned int with the converted data
00217     /// @details This exists for interacting with other libraies, in situations where changing the Integer Typedef could
00218     /// break things
00219     template<class T> unsigned int Tounsignedint( const T& Datum )
00220     {
00221         std::stringstream Converter;
00222         Converter << Datum;
00223         unsigned int Results;
00224         Converter >> Results;
00225         return Results;
00226     }
00227 
00228     /// @brief Converts whatever to a Real as long as the proper streaming operators are available for it
00229     /// @param Datum The whatever to be converted
00230     /// @return A Real with the converted data
00231     template<class T> Real ToReal( const T& Datum )
00232     {
00233         std::stringstream Converter;
00234         Converter << Datum;
00235         Real Results;
00236         Converter >> Results;
00237         return Results;
00238     }
00239 
00240     /// @brief Converts whatever to a float as long as the proper streaming operators are available for it
00241     /// @param Datum The whatever to be converted
00242     /// @return A float with the converted data
00243     /// @details This exists for interacting with other libraies, in situations where changing the Real Typedef could
00244     /// break things
00245     template<class T> float Tofloat( const T& Datum )
00246     {
00247         std::stringstream Converter;
00248         Converter << Datum;
00249         float Results;
00250         Converter >> Results;
00251         return Results;
00252     }
00253 
00254     /// @brief Converts whatever to a double as long as the proper streaming operators are available for it
00255     /// @param Datum The whatever to be converted
00256     /// @return A double with the converted data
00257     /// @details This exists for interacting with other libraies, in situations where changing the Typedefs could break things
00258     template<class T> double Todouble( const T& Datum )
00259     {
00260         std::stringstream Converter;
00261         Converter << Datum;
00262         double Results;
00263         Converter >> Results;
00264         return Results;
00265     }
00266 } // \Mezzanine
00267 
00268 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines