PF_API 0.52

Android/jni/Libs/Utils_LIB/UTypes.h

Go to the documentation of this file.
00001 
00002 //    Copyright (C) 2007-2011 Dylan Blair
00003 //
00004 //    email: dblair@alumni.cs.utexas.edu
00005 //
00006 //    This library is free software; you can redistribute it and/or
00007 //    modify it under the terms of the GNU Lesser General Public
00008 //    License as published by the Free Software Foundation; either
00009 //    version 2.1 of the License, or (at your option) any later version.
00010 //
00011 //    This library is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //    Lesser General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU Lesser General Public
00017 //    License along with this library; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef UTYPES_H
00022 #define UTYPES_H
00023 
00024 #include <string.h> //for memset()
00025 #include <assert.h>
00026 
00027 #define MAX_STRING_SIZE 4096
00028 
00029 #define UNUSED(var) (void)var;
00030 
00031 namespace OpenSkyNet {
00032     namespace Utils {
00033         typedef unsigned int uint;
00034         #ifdef _WIN32
00035         typedef unsigned __int64 uint64;
00036         #else
00037         typedef unsigned long long uint64;
00038         #endif
00039 
00040         class TaggedUnion {
00041         public:
00042             enum TAG { POINTER, INT, FLOAT };
00043 
00044             TaggedUnion(TAG tag_) : _tag(tag_) {}
00045             TaggedUnion(void* const &pointer_) : _tag(POINTER) { _taggedUnionData._pointer = pointer_; }
00046             TaggedUnion(const int& int_) : _tag(INT) { _taggedUnionData._int = int_; }
00047             TaggedUnion(const float& float_) : _tag(FLOAT) { _taggedUnionData._float = float_; }
00048 
00049             inline TAG getTag() const { return _tag; }
00050 
00051             inline void* getPointer() const { assert(_tag == POINTER); return _taggedUnionData._pointer; }
00052             inline int getInt() const { assert(_tag == INT); return _taggedUnionData._int; }
00053             inline float getFloat() const { assert(_tag == FLOAT); return _taggedUnionData._float; }
00054 
00055             inline void setPointer(void* const &pointer_) { assert(_tag == POINTER); _taggedUnionData._pointer = pointer_; }
00056             inline void setInt(const int& int_) { assert(_tag == INT); _taggedUnionData._int = int_; }
00057             inline void setFloat(const float& float_) { assert(_tag == FLOAT); _taggedUnionData._float = float_; }
00058         public:
00059             enum TAG _tag;
00060 
00061             union TaggedUnionData {
00062                 void* _pointer;
00063                 int _int;
00064                 float _float;
00065                 TaggedUnionData() { memset(this, 0, sizeof(TaggedUnionData)); }
00066             } _taggedUnionData;
00067         };
00068     }
00069 }
00070 
00071 #endif //UTYPES_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines