# HLAtypesIEEE1516.hh

Go to the documentation of this file.

    00001 // ----------------------------------------------------------------------------
    00002 // HLAtypesIEEE1516.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: HLAtypesIEEE1516.hh,v 1.4 2008/08/02 14:03:14 gotthardp Exp $
    00015 // ----------------------------------------------------------------------------
    00016
    00017 #ifndef _HLATYPES_IEEE1516_HH
    00018 #define _HLATYPES_IEEE1516_HH
    00019
    00020 /* These templates implement efficient access functions that provide direct
    00021  * access to IEEE 1516.2 compliant data buffers.
    00022  * The data are manipulated "in situ", no temporary variables are created.
    00023  *
    00024  * Use hlaomtdif2cpp -i <file> to generate FOM/SOM specific datatypes.
    00025  *
    00026  * The extensive use of template metaprogramming allows many operations to
    00027  * be pre-calculated during compile-time.
    00028  * See http://aszt.inf.elte.hu/~gsd/halado_cpp/ch06s09.html
    00029  */
    00030
    00031 #include <HLAbuffer.hh>
    00032
    00033 namespace libhla {
    00034
    00035 template<class T>
    00036 class HLAdata : public __HLAbuffer
    00037 {
    00038 public:
    00040     HLAdata(size_t capacity = T::emptysizeof())
    00041       : __HLAbuffer(capacity)
    00042     { }
    00043
    00045     HLAdata(void *begin, size_t capacity)
    00046       : __HLAbuffer(begin, capacity)
    00047     {
    00048         if (capacity < size())
    00049             throw std::length_error("HLAdata: data buffer overflow");
    00050         // do *not* clean the data buffer, it may contain valid data
    00051     }
    00052
    00053     T& operator *() const
    00054     { return *(T*)mBegin; }
    00055
    00056     T* operator ->() const
    00057     { return (T*)mBegin; }
    00058
    00059     virtual const size_t size() const
    00060     { return ((T*)mBegin)->__sizeof(); }
    00061
    00063     /* Resizing the variable-size elements may have significant impact on padding
    00064      * of other elements. This function changes a <value> of <__that> element
    00065      * and updates the padding through the whole buffer.
    00066      */
    00067     virtual void __shake(const void* __that, int value, long resize)
    00068     {
    00069         HLAdata<T> newData(size()+resize);
    00070
    00071         // copy the data to the temporary buffer, while changing a <value> of <__that>
    00072         newData.mShakeThat = __that;
    00073         newData.mShakeValue = value;
    00074         // create copy of the data
    00075         ((T*)newData.mBegin)->copy(mBegin);
    00076
    00077         if (mUserAllocated)
    00078         {
    00079             if (newData.size() < mCapacity)
    00080                 // copy data back to the original buffer
    00081                 memcpy(mBegin, newData.mBegin, newData.size());
    00082             else
    00083                 throw std::length_error("HLAdata: data buffer overflow");
    00084         }
    00085         else
    00086             __exchange_buffers(newData);
    00087     }
    00088 };
    00089
    00090 } // namespace libhla
    00091
    00092 #if defined(_WIN32)
    00093 #pragma warning(disable:4503) // suppress warning C4503: decorated name length exceeded
    00094 #endif
    00095
    00096 #include <HLAbasicType.hh>
    00097 #include <HLAenumeratedType.hh>
    00098 #include <HLAfixedArray.hh>
    00099 #include <HLAvariableArray.hh>
    00100 #include <HLAfixedRecord.hh>
    00101 #include <HLAvariantRecord.hh>
    00102
    00103 #endif // _HLATYPES_IEEE1516_HH
    00104
    00105 // $Id: HLAtypesIEEE1516.hh,v 1.4 2008/08/02 14:03:14 gotthardp Exp $
    00106