Main Page   Packages   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

C:/temp/src/j2k/Fred/String/StrData.inl

Go to the documentation of this file.
00001 #ifndef __J2K__JString_Data_INL__
00002 #define __J2K__JString_Data_INL__
00003 
00004 #include <j2k/Fred/String/StrData.hpp>
00005 
00006 ////////////////////////////////////////////////////////////////////////////
00007 /// Constructor, Copy Constructor and Destructor                         ///
00008 ////////////////////////////////////////////////////////////////////////////
00009 inline JStringData::JStringData()
00010   : nbRefs( 1 ), length( 0 ), lock( 0 ), bufferSize( 0 )
00011 {
00012   data = "";  
00013 }
00014 
00015 inline JStringData::JStringData( const char* s )
00016   : nbRefs( 1 ), lock( 0 )
00017 {
00018   if ( s == NULL || *s == '\0' ) 
00019   {
00020 
00021     data = "";
00022     length     = 0;
00023     bufferSize = 0;
00024 
00025   } else {
00026 
00027     length     = strlen( s );
00028     bufferSize = length;
00029     Init( s, length );
00030   }
00031 }
00032 
00033 // WARNING: Rough, rip-out extra !
00034 inline JStringData::JStringData( const char* s, size_t nBuffer )
00035   : nbRefs( 1 ), lock( 0 )
00036 {
00037   if ( nBuffer < 1 ) 
00038   {
00039     bufferSize = 0;
00040     data = "";
00041 
00042   } else {
00043     length = strlen( s );
00044 
00045     if ( length > nBuffer ) {
00046       length = nBuffer; 
00047     }
00048 
00049     bufferSize = nBuffer;
00050     Init( s, bufferSize );
00051   }
00052 }
00053 
00054 inline JStringData::JStringData( const JStringData& sd )
00055   : nbRefs( 1 ), lock( 0 ), length( sd.length ), bufferSize( sd.bufferSize )
00056 {
00057   Init( sd.data, sd.bufferSize );
00058 }
00059 
00060 inline JStringData::JStringData( size_t nBuffer )
00061   : nbRefs( 1 ), length( 0 ), lock( 0 ), bufferSize( nBuffer )
00062 {
00063   InitBuffer( nBuffer, '\0' );
00064 }
00065 
00066 inline JStringData::JStringData( char fill, size_t nRepeat )
00067   : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( 0 )
00068 {
00069   InitBuffer( nRepeat, fill );
00070 }
00071 
00072 inline JStringData::JStringData( char fill, size_t nRepeat, size_t nBuffer )
00073   : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( nBuffer )
00074 {
00075   InitBuffer( nRepeat, fill );
00076 }
00077 
00078 inline JStringData::~JStringData()
00079 {
00080   if ( data != NULL  &&  *data != (char)NULL ) {
00081 
00082 #ifdef __J2K__DEBUG
00083      printf("\nDelete JStringData[%s]\n", data );
00084 #endif
00085 
00086 /** ANDREA ***************************************************
00087 JString();
00088   The previous remark means that here you may be calling
00089   delete[] on something that wasn't necessarely allocated
00090   with new[] and that wasn't owned by you anyway.
00091 
00092   I delete only if new[] was call no ?
00093 
00094 *************************************************************/
00095 
00096      delete[] data;
00097   }
00098 }
00099 
00100 ////////////////////////////////////////////////////////////////////////////
00101 /// Utilities and function helper                                        ///
00102 ////////////////////////////////////////////////////////////////////////////
00103 inline void JStringData::Dec() {
00104   if ( this == strNull  ||  lock != 0 ) return;
00105 
00106   if ( --nbRefs == 0 ) {   // If not used anymore,
00107 
00108 #ifdef __J2K__DEBUG
00109   printf("\nStringData[%s], Counter decrement[%d]\n", data, nbRefs );
00110 #endif
00111 
00112     delete this;       // then Suicide yourself ( Ahhhh... BANG! =) 
00113   }
00114 }
00115 
00116 inline void JStringData::Inc() {
00117   if ( this == strNull ) return;
00118 
00119 #ifdef __J2K__DEBUG
00120   printf("\nStringData[%s], Counter increment[%d]\n", data, nbRefs );
00121 #endif
00122 
00123   ++nbRefs;
00124 }
00125 
00126 #endif

Generated on Sun Oct 14 18:46:27 2001 for Standard J2K Library by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001