00001 /* liblookdb: lkrawdata.h - Raw data representation
00002 Copyright (C) 1998-2001 LOOK Systems
00003
00004 This library is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU Lesser General Public
00006 License as published by the Free Software Foundation; either
00007 version 2.1 of the License, or (at your option) any later version.
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 You should have received a copy of the GNU Lesser General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00017 */
00018 #ifndef LIBLOOKDB_LKRAWDATA_H
00019 #define LIBLOOKDB_LKRAWDATA_H
00020
00021 // $Id: lkrawdata.h,v 1.4 2001/07/04 15:53:19 clive Exp $
00022
00023 #include "looktypes.h"
00024 #include "lktypebase.h"
00025 #include "lkstring.h"
00026
00027 namespace look {
00028
00029 // *****************************************************
00030 // LookRawData class
00031 // *****************************************************
00032
00034
00046 class LOOKTYPES_DLL LookRawData : public LookTypeBase
00047 {
00048 public:
00049 // Constructors.
00050 LookRawData();
00051 LookRawData( const char* theData, long theDataLength );
00052
00053 // Destructor.
00054 ~LookRawData( void );
00055
00056 // Copy constructor.
00057 LookRawData( const LookRawData &theOther );
00058
00059 // Assignment operators
00060 LookRawData& operator=( const LookRawData &theOther );
00061
00062 // get a copy
00063 LookTypeBase* GetNewCopy( void ) const;
00064
00065 // get my id
00066 long GetTypeID( void ) const;
00067
00068 // get a ptr
00069 char* GetData( void );
00070 // get the length
00071 long GetLength( void );
00072
00073 // get both
00074 char* GetData( long& theLength );
00075
00076 // this takes a copy of the data
00077 void SetData( const char* theData, long theLength );
00078
00079 // more efficient is to do this
00080 // this sets up a new area of memory theLength long and returns it to you
00081 // this class mananges it.
00082 char* InitialiseData( long theLength );
00083
00084 // concatenating things
00085 void Append( const LookRawData& theOther );
00086 void Append( const char* theData, long theLength );
00087 void Resize( long theNewLength );
00088
00089 // note we haven't got anything clever about copying on write.
00090 // so remember all LookRawData's copied from each other are the same thing.
00091
00092 // yeuch...
00093 bool Set( const LookString& theString );
00094 LookString GetString( void ) const;
00095
00096 // I'm not sure if we want these operators. convert to suitable class
00097 // first? (although == op will work better than float ==)
00098 /*
00099 // comparison operators
00100 bool operator==(const LookRawData &theValue) const;
00101 bool operator!=(const LookRawData &theValue) const;
00102 bool operator<=(const LookRawData &theValue) const;
00103 bool operator>=(const LookRawData &theValue) const;
00104 bool operator<(const LookRawData &theValue) const;
00105 bool operator>(const LookRawData &theValue) const;
00106
00107 // arithmetic operators
00108 LookRawData operator+(const LookRawData &theValue) const;
00109 LookRawData& operator+=(const LookRawData &theValue);
00110
00111 LookRawData operator-(const LookRawData &theValue) const;
00112 LookRawData& operator-=(const LookRawData &theValue);
00113 */
00114
00115 protected:
00116
00117 struct RawDataRepresentation
00118 {
00119 public:
00120 RawDataRepresentation()
00121 : itsData( NULL ), itsLength( 0 ), itsReferenceCount( 1 )
00122 {
00123 }
00124
00125 void AddRef( void )
00126 {
00127 ++itsReferenceCount;
00128 }
00129
00130 void RemoveRef( void )
00131 {
00132 --itsReferenceCount;
00133 if( !itsReferenceCount )
00134 {
00135 delete this;
00136 }
00137 }
00138
00139 char* itsData;
00140 long itsLength;
00141
00142 protected:
00143
00144 ~RawDataRepresentation()
00145 {
00146 delete[] itsData;
00147 }
00148
00149 int itsReferenceCount;
00150 };
00151
00152 // the value
00153 RawDataRepresentation* itsData;
00154
00155 };
00156
00157
00158 } // end of "look" namespace
00159 #endif
1.2.8.1 written by Dimitri van Heesch,
© 1997-2001