Main Page | Class Hierarchy | Compound List | File List | Compound Members

BxDataObject.h

00001 /********************************************************************
00002  * Binx
00003  * $Id: BxDataObject_8h-source.html,v 1.1.1.1 2006/04/19 14:19:02 edikt2 Exp $
00004  *
00005  * Base class for the BinX data types
00006  *
00007  *
00008  * edikt::BinX
00009  * www.edikt.org
00010  * support@edikt.org
00011  *
00012  * Copyright (c) 2005 The University of Edinburgh.
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_;     // Provides storage for 8-bit, a single byte, and a single unsigned byte data values.
00053     bx_ubyte8   ub_;    // Provides storage for 8-bit, unsigned.
00054     bx_char8    c_;     // Provides storage for single character data values.
00055     bx_short16  s_;     // Provides storage for 16-bit integer data values.
00056     bx_ushort16 us_;    // Provides storage for 16-bit unsigned integer, and 16-bit unicode data values.
00057     bx_int32    i_;     // Provides storage for 32-bit integer data values.
00058     bx_uint32   ui_;    // Provides storage for 32-bit unsigned integer, and 32-bit unicode data values.
00059     bx_long64   l_;     // Provides storage for 64-bit integer values. When using C++Builder, this is restricted to 32-bit representations.
00060     bx_ulong64  ul_;    // Provides storage for 64-bit unsigned integer data values. When using C++Builder this is restricted to 32-bit representations.
00061     bx_float32       f_;   // Provides storage for 32-bit floating point numbers.
00062     bx_double64      d_;   // Provides storage for 64-bit floating point numbers.
00063     bx_extended80    e_;   // Provides storage for 80-bit floating point numbers.
00064     bx_quadruple128  q_; // Provides storage for 128-bit floating point numbers.
00065     byte  block_[16]; // Provides maximum storage size of 128-bit (16 bytes) for quadruple floating point numbers or future large data types.
00066     void* ptr_;   // Provides a pointer reference to any BinX primitive or abstract data type.
00067 };
00068 
00127 class DECLSPEC BxDataObject : public BxObject
00128 {
00129 public:
00130         // The default constructor
00131     BxDataObject();
00132 
00133         // The default copy constructor
00134     BxDataObject(const BxDataObject& copy);
00135 
00136         // The destructor
00137     virtual ~BxDataObject();
00138 
00139     virtual char* className() const { return "BxDataObject"; }   //Get class name for this object.
00140     virtual BxDataObject* clone() const;      //make a copy of the object
00141 
00142     int dataClass() const { return dataClass_; }    
00143     int bits() const { return sizeInBits_; }    //<Get the number of bits used to store the primary data value of this object.
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;   //returns the variable name
00155     virtual char* testValue() const { return testValue_; }  //<Get the test value for this object.
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; }    //<Set the byte offset to locate the primary data value in the associated binary file.
00160 
00161     virtual bool  parseValue(const char*);
00162 
00163         //read data value from binary file for this data object - should make pure virtual
00164     virtual bool  readFromFile();
00165     virtual void  readFromBuffer(const byte*);  //read data from a buffer
00166     virtual void  setBinaryFilePtr(BxBinaryFile* fp);
00167     virtual bool  save();    //save the object in the binary file.
00168     virtual void  print();   //print the attributes and value.
00169     virtual bool  equals(const BxDataObject&) const;
00170     virtual char* toString(bool xml); //new a string for the value
00171     virtual bool  toStream(FILE*);
00172     virtual bool  toStreamBinary(FILE*);
00173 
00174         // Write out the binary data with the specified byte order
00175     virtual bool  toStreamBinary(FILE*, BxByteOrder);
00176     virtual long  locate() const; //seek file pointer to the object offset
00177 
00178     virtual byte* getDataPointer(); //return data pointer
00179 
00180     bx_byte8    getByte();      //return the value as a byte
00181     bx_ubyte8   getUnsignedByte();  //return the value as an unsigned byte
00182     bx_char8    getChar();    //return the data value as a char
00183     bx_short16   getShort();   //return the data value as a short int
00184     bx_int32     getInt();     //return the data value as an int
00185     bx_long64    getLong();    //return the data value as a long
00186     bx_float32   getFloat();   // return the data value as a float
00187     bx_double64  getDouble();  // return the data value as a double
00188     bx_extended80   getExtended80();  // return extended floating point value
00189     bx_extended96   getExtended96();
00190     bx_quadruple128 getQuadruple(); // return data value as a quaduple floating number
00191     bx_ushort16 getUnsignedShort();    //return unsigned short
00192     bx_ushort16 getUnicode16();
00193     bx_uint32 getUnicode32();
00194     bx_uint32 getUnsignedInt();    //return unsigned int
00195     bx_ulong64 getUnsignedLong();  //return unsigned long
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         // Protected operations
00221 
00222     int computeElementSize(int elem);
00223     void fillElementHead(char* buf, int elem);
00224     void fillElementTail(char* buf, int elem);
00225 
00226 
00227         // Protected data
00228 
00229     int dataClass_;     // data class for this object, e.g., BXINTEGER32, etc.
00230     int sizeInBits_;    // number of bits for this data object, used for primitive data types only
00231     int sizeInBytes_;   // number of bytes for this data object
00232     int sizeInAll_;     // real size in bytes, inlcuding block size adjustment and padding ofr alignment
00233     long offsetInFile_;  // offset of this data element in the binary file
00234     int  blockSize_;     // number of bits for this block, if specified
00235     bool loaded_;        // indicates whether a data value is loaded from the binary file
00236     char* typeName_;     // data type name, used mainly for user-defined types
00237     char* varName_;      // name of the variable, user-defined in the BinX document
00238     char* testValue_;    // used for testing purpose only
00239     BxByteOrder byteOrder_; // byte order of the data element, if applicable
00240     BxBinaryFile* bfile_;   // pointer to the open binary file
00241     BxDataUnion dataValue_; // the application data value, read from or to be written to a binary file
00242 };
00243 
00244 #endif

Generated on Fri May 6 13:36:17 2005 for edikt::BinX by doxygen 1.3.3