00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BXDATAOBJECT_H
00017 #define BXDATAOBJECT_H
00018
00019 #include "BxObject.h"
00020 #include "BxBinaryFile.h"
00021
00022 #include <string.h>
00023
00050 union BxDataUnion
00051 {
00052 bx_byte8 b_;
00053 bx_ubyte8 ub_;
00054 bx_char8 c_;
00055 bx_short16 s_;
00056 bx_ushort16 us_;
00057 bx_int32 i_;
00058 bx_uint32 ui_;
00059 bx_long64 l_;
00060 bx_ulong64 ul_;
00061 bx_float32 f_;
00062 bx_double64 d_;
00063 bx_extended80 e_;
00064 bx_quadruple128 q_;
00065 byte block_[16];
00066 void* ptr_;
00067 };
00068
00127 class DECLSPEC BxDataObject : public BxObject
00128 {
00129 public:
00130
00131 BxDataObject();
00132
00133
00134 BxDataObject(const BxDataObject& copy);
00135
00136
00137 virtual ~BxDataObject();
00138
00139 virtual char* className() const { return "BxDataObject"; }
00140 virtual BxDataObject* clone() const;
00141
00142 int dataClass() const { return dataClass_; }
00143 int bits() const { return sizeInBits_; }
00144 int bytes() const { return sizeInBytes_; }
00145 int size() const { return sizeInAll_; }
00146 long offset() const { return offsetInFile_; }
00147 BxByteOrder byteOrder() const { return byteOrder_; }
00148 BxDataUnion getDataValue() const { return dataValue_; }
00149
00150 BxBinaryFile* binaryFile() const { return bfile_; }
00151 bool loaded() const { return loaded_; }
00152
00153 virtual char* typeName() const { return typeName_; }
00154 virtual char* varName() const;
00155 virtual char* testValue() const { return testValue_; }
00156 virtual int blockSize() const { return blockSize_; }
00157 virtual void setByteOrder(BxByteOrder bo) { byteOrder_ = bo; }
00158 virtual void setBlockSize(int blocksize) { blockSize_ = blocksize; }
00159 virtual void setOffset(long offset) { offsetInFile_ = offset; }
00160
00161 virtual bool parseValue(const char*);
00162
00163
00164 virtual bool readFromFile();
00165 virtual void readFromBuffer(const byte*);
00166 virtual void setBinaryFilePtr(BxBinaryFile* fp);
00167 virtual bool save();
00168 virtual void print();
00169 virtual bool equals(const BxDataObject&) const;
00170 virtual char* toString(bool xml);
00171 virtual bool toStream(FILE*);
00172 virtual bool toStreamBinary(FILE*);
00173
00174
00175 virtual bool toStreamBinary(FILE*, BxByteOrder);
00176 virtual long locate() const;
00177
00178 virtual byte* getDataPointer();
00179
00180 bx_byte8 getByte();
00181 bx_ubyte8 getUnsignedByte();
00182 bx_char8 getChar();
00183 bx_short16 getShort();
00184 bx_int32 getInt();
00185 bx_long64 getLong();
00186 bx_float32 getFloat();
00187 bx_double64 getDouble();
00188 bx_extended80 getExtended80();
00189 bx_extended96 getExtended96();
00190 bx_quadruple128 getQuadruple();
00191 bx_ushort16 getUnsignedShort();
00192 bx_ushort16 getUnicode16();
00193 bx_uint32 getUnicode32();
00194 bx_uint32 getUnsignedInt();
00195 bx_ulong64 getUnsignedLong();
00196
00197 void copyTypeName(const char* typeName);
00198 void copyVarName(const char* vname);
00199 void setTypeName(char* typeName);
00200 void setVarName(char* vname);
00201 void setTestValue(char* testValue);
00202
00203 bool needChangeByteOrder() const;
00204
00205 void setByte(bx_byte8 b);
00206 void setChar(bx_char8 c);
00207 void setShort(bx_short16 s);
00208 void setInt32(bx_int32 i);
00209 void setLong64(bx_long64 l);
00210 void setFloat(bx_float32 f);
00211 void setDouble(bx_double64 d);
00212 void setExtended(bx_extended80 e);
00213 void setQuadruple(bx_quadruple128 q);
00214 void setUnsignedByte(bx_ubyte8 ub);
00215 void setUnsignedShort(bx_ushort16 us);
00216 void setUnsignedInt32(bx_uint32 ui);
00217 void setUnsignedLong64(bx_ulong64 ul);
00218
00219 protected:
00220
00221
00222 int computeElementSize(int elem);
00223 void fillElementHead(char* buf, int elem);
00224 void fillElementTail(char* buf, int elem);
00225
00226
00227
00228
00229 int dataClass_;
00230 int sizeInBits_;
00231 int sizeInBytes_;
00232 int sizeInAll_;
00233 long offsetInFile_;
00234 int blockSize_;
00235 bool loaded_;
00236 char* typeName_;
00237 char* varName_;
00238 char* testValue_;
00239 BxByteOrder byteOrder_;
00240 BxBinaryFile* bfile_;
00241 BxDataUnion dataValue_;
00242 };
00243
00244 #endif