Veda/PackFloat.h

Go to the documentation of this file.
00001 /*! \file 
00002     \author victorien ferry & www.m4nkind.com
00003     \brief This file applies the GNU LESSER GENERAL PUBLIC LICENSE Version 2.1 , read file COPYING.
00004 */
00005 #ifndef COM_M4NKIND_PackFloat_H
00006 #define COM_M4NKIND_PackFloat_H
00007 
00008 #include "BaseType.h"
00009 
00010 /*!
00011     \class  PackFloat
00012     \ingroup    BaseSerializableClass
00013     \brief   Base type managing a serializable float value. a float type is serialized to 3 bytes,
00014             or 1 byte if value is 0.0f. once read, the 4th IEEE float byte is always set to 0, so that the mantissa
00015             is only 15 bit long, not 23 as usual.
00016             PackFloat, like all its inherited classes, can be inited with
00017             a special constructor where you use a VectorDimension enum.
00018             You can choose to init a PackFloat with PackFloat::vd_X if
00019             you need one dimension o represent a value, or use vd_XY, for
00020             example to define a 2D vector, vd_XYZ for a 3D vector, or vd_XYZD
00021             for a dated 3D vector.
00022             Note extension library VedaLibMath 's VirtualEquation::Compute()
00023             was based on float[4] parameters.
00024 */
00025 
00026 class PackFloat : public BaseType
00027 {
00028 /*==================================================================
00029                                 PUBLIC
00030 ==================================================================*/
00031 public:
00032     /*!
00033         \brief  Default Constructor. 
00034     */
00035     PackFloat(void);
00036 
00037     /*!
00038         \typedef    VectorDimensions are enum used to initialize a PackFloat to a X,Y or a X,Y,Z vector. 
00039     */
00040     typedef enum {
00041         //! declare a PackFloat with one dimension
00042         vd_X=1,
00043         //! declare a PackFloat with two dimensions
00044         vd_XY=2,
00045         //! declare a PackFloat with three dimensions
00046         vd_XYZ=3,
00047         //! declare a PackFloat with 4 dimensions 
00048         vd_XYZD=4
00049     }   VectorDimension ;
00050     /*!
00051         \brief  Constructor To initialize PackFloat as a multi dimentional vector. 
00052         \param _DimensionEnum on of the 3 VectorDimension enum.
00053     */
00054     PackFloat( VectorDimension _DimensionEnum );
00055 
00056 #ifdef _ENGINE_EDITABLE_
00057     /*!
00058         \brief  Destructor. 
00059     */
00060     virtual ~PackFloat(void);
00061 #endif
00062     /*!
00063         \brief  Read the object description from a byte chunk. Could crash if chunk not valid.
00064         \param  _pDescriptionChunk the objet description chunk. 
00065         \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it.
00066     */
00067     virtual  const unsigned char * Serialize_In( const unsigned char * _pDescriptionChunk);
00068 
00069 #ifdef _ENGINE_EDITABLE_
00070     /*!
00071         \brief  get the size of the whole byte chunk that will be written by Serialize_Out().
00072         \return byte size of the serialisation to do.(1,2,3, or4)
00073     */
00074     virtual unsigned int  GetSerializedDescriptionSize(void);
00075 #endif
00076 #ifdef _ENGINE_EDITABLE_
00077     /*!
00078         \brief  write the Current object definition to a Chunk using private packed types, recursively.
00079         \param  _pDescriptionChunkToFill the chunk where to write the objet description chunk. 
00080         \return the end of the chunk written, possibly unlocated. Don't use this if you don't need it.
00081     */
00082     virtual unsigned char * Serialize_Out(unsigned char * _pDescriptionChunkToFill);
00083 #endif
00084 #ifdef _ENGINE_EDITABLE_
00085     /*!
00086         \brief  Each BaseType's inherited classes must explicit an ID for their
00087                 class, or let use one of the super class at least through this virtual method.
00088                 This is needed by GUIs to detect the types of each sub-members, and shape
00089                 an interface for each Object according to their member list.
00090         \return a const character string, that must be unique and unchanged for all serializable base type.
00091     */
00092     virtual const char *GetClassID() const { return "PackFloat"; };
00093 #endif      
00094 #ifdef _ENGINE_EDITABLE_
00095     /*!
00096         \brief  convert the value of this object to an explicit string. The object manages the string privately,
00097             so just read it or copy it. the string would be destroyed with the objects, and changed when using Set() methods.
00098              Note: this is not virtual, but each class can manage m_pValueString or not.
00099         \return the value as a const string. 
00100     */
00101     virtual const char  *ValueToString();
00102 #endif
00103 #ifdef _ENGINE_EDITABLE_
00104     /*!
00105         \brief  change the value:
00106         \param  _value  value
00107     */
00108     virtual void    Set(float _value); 
00109 #endif
00110 #ifdef _ENGINE_EDITABLE_
00111     /*!
00112         \brief  change the value of a given dimension:
00113         \param _dimensionIndex  0 for X, 1 for Y, 2 for Z
00114         \param  _value  value
00115     */
00116     virtual void    Set(unsigned int _dimensionIndex,float _value); 
00117 #endif
00118 #ifdef _ENGINE_EDITABLE_
00119     /*!
00120         \brief  change values of X,Y and Z.
00121         \param  _x  value
00122         \param  _y  value
00123         \param  _z  value
00124     */
00125     inline void Set3f(float _x, float _y, float _z){ Set(_x); Set(1,_y); Set(2,_z); };
00126 #endif
00127     /*!
00128         \brief  Get the value
00129         \return  the float
00130     */
00131     inline float    Get() const { return m_value[0] ; };
00132     /*!
00133         \brief  Get the value. WILL CRASH IF _dimensionIndex>2.
00134         \param _dimensionIndex  0 for X, 1 for Y, 2 for Z
00135         \return  the float
00136     */
00137     inline float    Get(unsigned int _dimensionIndex) const { return m_value[_dimensionIndex] ; };
00138 
00139     /*!
00140         \brief  return Dimension Managed.
00141                 it should be 
00142 
00143         \return  the float
00144     */
00145     inline VectorDimension  GetVectorDimension(){return (VectorDimension)m_NumberOfDimensionManaged ; };
00146 
00147     //! public const float value in order to optimize size access for equations:
00148     static const float  m_0p0;
00149     static const float  m_0p01; // 1/100
00150     static const float  m_0p00001;
00151     static const float  m_0p25;
00152     static const float  m_0p5;
00153     static const float  m_1p0;
00154     static const float  m_2p0;
00155     static const float  m_255p0;
00156     static const float  m_256p0;
00157     static const float  m_0p0625; // 1/16
00158     static const float  m_100p0;
00159     static const float  m_1Div255; // 1/255
00160     static const float  m_1Div256; // 1/255
00161     static const float  m_1Div64;
00162     static const float  m_Pi;
00163     static const float  m_2Pi;
00164     static const float  m_180DivPi;
00165     static const float  m_32767p0; //(1<<15)-1 , to make float-1,1 to 16bit conversion.
00166     static const float  m_Max; //= 3.402823466e+38F; // this is max positive.
00167 
00168 /*==================================================================
00169                                 PROTECTED
00170 ==================================================================*/
00171 protected:
00172     //!     the value of this class: 
00173     float   m_value[vd_XYZD];
00174 
00175     //! the number of Dimension managed if PackFloat was initialized as a vector
00176     const unsigned int  m_NumberOfDimensionManaged;
00177 };
00178 
00179 /*!
00180     \def    REGISTER_MEMBER_PACKFLOAT
00181 
00182     \brief  This macro is used to register a serializable member in a class constructor.
00183             For editable mode, it uses _MemberName to explicit the use of the member, in order
00184             to display it in a GUI for example.
00185         
00186 */
00187 #ifdef _ENGINE_EDITABLE_
00188 #define     REGISTER_MEMBER_PACKFLOAT(_object,_MemberName,_DefaultVal) \
00189 RegisterSerializableMember(_object);\
00190 _object.SetMemberName( _MemberName );\
00191 _object.Set(_DefaultVal);
00192 #else
00193 #define     REGISTER_MEMBER_PACKFLOAT(_object,_MemberName,_DefaultVal) \
00194 RegisterSerializableMember(_object);
00195 #endif
00196 
00197 #ifdef _ENGINE_EDITABLE_
00198 #define     REGISTER_MEMBER_PACKFLOAT_XY(_object,_MemberName,_DefaultValX,_DefaultValY) \
00199 RegisterSerializableMember(_object);\
00200 _object.SetMemberName( _MemberName );\
00201 _object.Set(0,_DefaultValX);\
00202 _object.Set(1,_DefaultValY);
00203 #else
00204 #define     REGISTER_MEMBER_PACKFLOAT_XY(_object,_MemberName,_DefaultValX,_DefaultValY) \
00205 RegisterSerializableMember(_object);
00206 #endif
00207 
00208 #ifdef _ENGINE_EDITABLE_
00209 #define     REGISTER_MEMBER_PACKFLOAT_XYZ(_object,_MemberName,_DefaultValX,_DefaultValY,_DefaultValZ) \
00210 RegisterSerializableMember(_object);\
00211 _object.SetMemberName( _MemberName );\
00212 _object.Set(0,_DefaultValX);\
00213 _object.Set(1,_DefaultValY);\
00214 _object.Set(2,_DefaultValZ);
00215 #else
00216 #define     REGISTER_MEMBER_PACKFLOAT_XYZ(_object,_MemberName,_DefaultValX,_DefaultValY,_DefaultValZ) \
00217 RegisterSerializableMember(_object);
00218 #endif
00219 
00220 // end of file:
00221 #endif

      /\/\        4         N         k         !         N         D
                      _______  _ __ ___  _____            ___ _ _  ____
     ___________  __//___   /________  |/    / ___________\_______/    \
    /   _   _   \/   _     /    _   /      _/_/____/    _       __     /
   /    /   /       /     /    /    \      \/     /    /    \   \     /
  \\___/___/___/    ¯    _____/_____/       ______\___/_____/\________\\
               \________/_ ___ __ l____\      /elD!  
                 http://www.m4nkind.com \____/