HLAenumeratedType.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // HLAenumeratedType.hh - IEEE 1516.2 compliant datatypes
00003 // Copyright (C) 2008  Petr Gotthard <petr.gotthard@centrum.cz>
00004 //
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License version 2.1, as published by the Free Software Foundation.
00008 //
00009 // This library 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 GNU
00012 // Lesser General Public License for more details.
00013 //
00014 // $Id: HLAenumeratedType.hh,v 1.2 2008/11/03 11:10:58 gotthardp Exp $
00015 // ----------------------------------------------------------------------------
00016 
00017 #ifndef _HLATYPES_ENUMERATEDTYPE_HH
00018 #define _HLATYPES_ENUMERATEDTYPE_HH
00019 
00020 namespace libhla {
00021 
00022 /* HLAenumeratedType<ENUMERATION, REPRESENTATION>
00023  * defines an user-convenient ENUMERATION stored using given REPRESENTATION.
00024  *
00025  * The data can be accessed in an usual way.
00026  *
00027  * Some models may use one enumerated value in multiple enumerations. To avoid
00028  * name collisions it's recommended to put the ENUMERATION in an individual namespace.
00029  *
00030  * For example:
00031  * +------------+----------------+------------+--------+-----------+
00032  * | Name       | Representation | Enumerator | Values | Semantics |
00033  * +------------+----------------+------------+--------+-----------+
00034  * |            |                | HLAfalse   | 0      |           |
00035  * | HLAboolean | HLAinteger32BE +------------+--------+-----------+
00036  * |            |                | HLAfalse   | 1      |           |
00037  * +------------+----------------+------------+--------+-----------+
00038  * 
00039  * namespace __HLAboolean {
00040  * enum __enum {
00041  *   HLAfalse = 0,
00042  *   HLAtrue = 1
00043  * };
00044  * }
00045  * typedef HLAenumeratedType<__HLAboolean::__enum, HLAinteger32BE> HLAboolean;
00046  * HLAdata<HLAboolean> value;
00047  *
00048  * value = HLAtrue;
00049  */
00050 
00052 template<class E, class R>
00053 struct HLAenumeratedType
00054 {
00055     HLAenumeratedType& operator = (const E& data)
00056     {
00057         *(R*)this = data;
00058         return *this;
00059     }
00060 
00061     HLAenumeratedType& operator = (const int& data)
00062     {
00063         *(R*)this = data;
00064         return *this;
00065     }
00066 
00067     operator E() const
00068     {
00069         int result = *(R*)this;
00070         return (E)result;
00071     }
00072 
00073     operator int() const
00074     { return *(R*)this; }
00075 
00076     static const size_t emptysizeof()
00077     { return R::emptysizeof(); }
00078 
00079     static const size_t __sizeof()
00080     { return R::__sizeof(); }
00081 
00082     void copy(void* source)
00083     { ((R*)this)->copy(source); }
00084 
00085     static const size_t m_octetBoundary = R::m_octetBoundary;
00086     static const bool m_isVariable = false;
00087 };
00088 
00089 /* IEEE 1516.2, Table 27:
00090  * Enumerated datatype table
00091  */
00092 enum __HLAboolean {
00093     HLAfalse = 0,
00094     HLAtrue = 1
00095 };
00096 typedef HLAenumeratedType<__HLAboolean, HLAinteger32BE> HLAboolean;
00097 
00098 } // namespace libhla
00099 
00100 #endif // _HLATYPES_ENUMERATEDTYPE_HH
00101 
00102 // $Id: HLAenumeratedType.hh,v 1.2 2008/11/03 11:10:58 gotthardp Exp $
00103 

Generated on Thu Apr 30 15:53:49 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5