00001 00002 #ifndef d_Binary_h 00003 #define d_Binary_h 1 00004 //------------------------------------------------------------------------------ 00005 00006 #include "cTypes.h" 00007 #include "oMemoryManager.h" 00008 //------------------------------------------------------------------------------ 00009 00010 /** 00011 * Manages binary data. 00012 * 00013 * d_Binary is the type for managing binary data. It's like the BLOB (Binary 00014 * Large Object Block) type of Relational DBMS. 00015 * 00016 * It permits to save any information: texts, pictures, movies, sounds, etc. 00017 * The size limit of a d_Binary object is 2^32 for 32bit systems. 00018 * 00019 * USAGE: 00020 * d_Binary <variable>; 00021 * 00022 * Where: 00023 * <VARIABLE>: NAME OF VARIABLE 00024 * 00025 * EXAMPLES: 00026 * class Employee : public d_Object 00027 * { 00028 * d_Binary photo; * JPEG FORMAT 00029 * }; 00030 * 00031 * * Use a d_Binary object in app 00032 * d_Binary stream; 00033 * 00034 * ODMG: 00035 * Extension 00036 */ 00037 class _ODLL d_Binary 00038 { 00039 public: 00040 00041 /** 00042 * Default constructor. 00043 * 00044 * <iSize> specifies the start size in bytes of d_Binary object. If not 00045 * specified will be taken the default value (256 bytes). 00046 * 00047 * <iStep> specifies the size in bytes of step of increment when the 00048 * d_Binary becames full. If not specified will be taken the default 00049 * value (64 bytes). 00050 * 00051 * SEE ALSO: reserve(), getSize() 00052 */ 00053 d_Binary (oUInt4 iSize = DEFAULT_SIZE, oUInt4 iStep = DEFAULT_STEP); 00054 00055 /** 00056 * Create a d_Binary object by a raw buffer. 00057 * 00058 * <iData> is a char* that points to the begin of buffer. <iLength> is the 00059 * size in bytes of buffer. 00060 * 00061 * The buffer will be copied into the d_Binary object. 00062 * 00063 * SEE ALSO: append(), set() 00064 */ 00065 d_Binary (const char* iData, oUInt4 iLength); 00066 00067 /** 00068 * Destructor. 00069 */ 00070 ~d_Binary(); 00071 00072 00073 /** 00074 * Reset the internal buffer. 00075 */ 00076 void reset (); 00077 00078 /** 00079 * Append a raw buffer to the end of own data. 00080 */ 00081 bool append (const char* iData, oUInt4 iLength); 00082 00083 /** 00084 * Append another d_Binary object to the end of own data. 00085 */ 00086 bool append (const d_Binary& iSource); 00087 00088 /** 00089 * Copy d_Buffer data in to a raw buffer. 00090 * 00091 * <iData> is a char* that points to the begin of buffer. <iLength> is the 00092 * size in bytes of buffer to copy and <iStart> is the offset from the 00093 * begin of buffer. 00094 */ 00095 bool get (const char* iData, oUInt4 iStart, oUInt4 iLength) const; 00096 00097 /** 00098 * Copy d_Buffer data in to another d_Binary object. 00099 * 00100 * <iData> is the d_Binary object where the buffer is copied. <iLength> is 00101 * the size in bytes of buffer to copy. If is equals to 0, then copy all 00102 * buffer. 00103 * 00104 * <iStart> is the offset from the begin of buffer. 00105 */ 00106 bool get (d_Binary& iData, oUInt4 iStart = 0, oUInt4 iLength = 0) const; 00107 00108 /** 00109 * Copy a raw buffer in the d_Binary object. 00110 * 00111 * <iData> is a char* that points to the begin of buffer. <iLength> is the 00112 * size in bytes of buffer to copy and <iStart> is the offset from the 00113 * begin of d_Binary buffer. 00114 */ 00115 bool set (const char* iData, oUInt4 iStart, oUInt4 iLength); 00116 00117 /** 00118 * Copy data from a d_Binary object. 00119 * 00120 * All <iSource> object is copied. 00121 * 00122 * <iSource> is the d_Binary object to copy. <iStart> is the offset from 00123 * the begin of own d_Binary buffer. 00124 */ 00125 bool set (d_Binary& iSource, oUInt4 iStart); 00126 00127 /** 00128 * Insert a d_Binary object in the current object. 00129 * 00130 * The <iSource> object is inserted by <iStart> position moving the data 00131 * on the right. 00132 * 00133 * <iSource> is the d_Binary object to insert. <iStart> is the offset from 00134 * the begin of own d_Binary buffer. 00135 */ 00136 bool insert( d_Binary& iSource, oUInt4 iStart ); 00137 00138 /** 00139 * Insert a buffer in the current object. 00140 * 00141 * The <iData> buffer of size <iLength> is inserted by <iStart> position 00142 * moving the data on the right. 00143 * 00144 * <iData> is the buffer to insert. <iStart> is the offset from the begin 00145 * of own d_Binary buffer. <iLength> is the size of buffer to insert. 00146 */ 00147 bool insert( char* iData, oUInt4 iStart, oUInt4 iLength ); 00148 00149 /** 00150 * Erase a portion of buffer. 00151 * 00152 * Data at the right of the portion to erase will be moved on left. 00153 * 00154 * <iStart> is the offset from the begin of own d_Binary buffer. <iLength> 00155 * is the size in bytes of buffer. 00156 */ 00157 void cut (oUInt4 iStart, oUInt4 iLength); 00158 00159 /** 00160 * Returns the current length of buffer in bytes. 00161 * 00162 * SEE ALSO: getSize() 00163 */ 00164 oUInt4 getLength () const; 00165 00166 /** 00167 * Returns the current size of buffer in bytes. 00168 * 00169 * The size is always grather or equals to the effective buffer length. 00170 * 00171 * SEE ALSO: getLength() 00172 */ 00173 oUInt4 getSize () const; 00174 00175 /** 00176 * Returns the pointer to the internal buffer. 00177 * 00178 * This method permits to access to the d_Binary buffer without copy it. 00179 * Applications should use this method just to read the buffer data and 00180 * not for write. 00181 * 00182 * If <iStart> is specified, then returns the pointer of the internal 00183 * buffer plus <iStart> offset. 00184 */ 00185 const char* raw (oUInt4 iStart = 0) const; 00186 00187 /** 00188 * Reserve space for data. 00189 * 00190 * <iSize> is the size in bytes of space to reserve. If <iSize> is minor 00191 * than actual size, then the extra data will be lost. 00192 * 00193 * SEE ALSO: d_Binary(), getSize() 00194 */ 00195 bool reserve (oUInt4 iSize); 00196 00197 private: 00198 // Internal. 00199 char* buffer; 00200 00201 // Internal. 00202 oUInt4 _length; 00203 00204 // Internal. 00205 oUInt4 size; 00206 00207 // Internal. 00208 oUInt4 step; 00209 00210 // Internal. 00211 static oUInt4 DEFAULT_SIZE; 00212 00213 // Internal. 00214 static oUInt4 DEFAULT_STEP; 00215 00216 00217 friend class _ODLL d_String; 00218 }; 00219 00220 //------------------------------------------------------------------------------ 00221 inline void d_Binary::reset () 00222 { 00223 // JUST RESET LENGTH MEMBER AND LEAVE MEMORY ALLOCATED FOR FUTURE USE 00224 _length = 0; 00225 } 00226 //------------------------------------------------------------------------------ 00227 inline bool d_Binary::append (const char* iData, oUInt4 iLength) 00228 { 00229 // MAP THIS CALL TO GET METHOD 00230 return set( iData, _length, iLength ); 00231 } 00232 //------------------------------------------------------------------------------ 00233 inline bool d_Binary::append (const d_Binary& iSource) 00234 { 00235 // MAP THIS CALL TO GET METHOD 00236 return set( iSource.buffer, _length, iSource._length ); 00237 } 00238 //------------------------------------------------------------------------------ 00239 inline bool d_Binary::set (d_Binary& iSource, oUInt4 iStart) 00240 { 00241 // MAP THIS CALL TO SET METHOD 00242 return set( iSource.buffer, iStart, iSource._length ); 00243 } 00244 //------------------------------------------------------------------------------ 00245 inline oUInt4 d_Binary::getLength () const 00246 { 00247 return _length; 00248 } 00249 //------------------------------------------------------------------------------ 00250 inline oUInt4 d_Binary::getSize () const 00251 { 00252 return size; 00253 } 00254 //------------------------------------------------------------------------------ 00255 inline const char* d_Binary::raw (oUInt4 iStart) const 00256 { 00257 // JUST RETURN POINTER OF INTERNAL BUFFER PLUS OFFSET 00258 return &buffer[iStart]; 00259 } 00260 //------------------------------------------------------------------------------ 00261 //------------------------------------------------------------------------------ 00262 00263 #endif 00264
1.3-rc1