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

C:/temp/src/j2k/Fred/String/StrTools.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__JString_Tools_CPP__
00002 #define __J2K__JString_Tools_CPP__
00003 
00004 #include <j2k/Fred/String/String.hpp>
00005 // NO Problem with Lock functions !
00006   
00007 void JString::Empty() {
00008   if ( pData == strNull ) return;
00009   if ( pData->length == 0 ) return;
00010 
00011   // Okay like that, for Lock and Sharing.
00012   pData->Dec();
00013   pData = strNull;
00014 }
00015 
00016 void JString::Clear() {
00017   if ( pData == strNull ) return;
00018   if ( pData->nbRefs == 1  &&  pData->lock == 0 ) {
00019     pData->Clear( '\0' );
00020   } else {
00021     pData->Dec();
00022     pData = strNull;
00023   }
00024 }
00025 
00026 void JString::FillString( char ch ) {
00027   register size_t i = 0;
00028   if ( pData->length < 1 ) return;
00029   if ( pData->nbRefs == 1  &&
00030        pData != strNull    &&
00031        pData->lock == 0 )
00032   {
00033     for( ; i < pData->length; i++ )
00034     {
00035       pData->data[i] = ch;
00036     }
00037 
00038     for( i = pData->length;
00039          i <= pData->bufferSize;
00040          i++ )
00041     {
00042       pData->data[i] = '\0';
00043     }
00044   }
00045   else
00046   {
00047     JStringData* sd = pData;
00048     pData = new JStringData( ch, pData->length, pData->bufferSize );
00049     sd->Dec();
00050   }
00051   pData->data[pData->length] = '\0';
00052 }
00053 
00054 void JString::FillBuffer( char ch )
00055 {
00056   register size_t i = 0;
00057   if ( pData->bufferSize < 1 ) return;
00058 
00059   if ( pData->nbRefs == 1  &&  pData != strNull  &&  pData->lock == 0 )
00060   {
00061     for( ; i < pData->bufferSize; i++ )
00062     {
00063       pData->data[i] = ch;
00064     }
00065   }
00066   else
00067   {
00068     JStringData* sd = pData;
00069     pData = new JStringData( ch, pData->bufferSize, pData->bufferSize );
00070     sd->Dec();
00071   }
00072 
00073   pData->length = pData->bufferSize;
00074   pData->data[pData->length] = '\0';
00075 }
00076 
00077 // Debug checking function: this.OK() == OK ? =P
00078 // Code reading is so boring sometime, so jokes are always welcome...
00079 /** ANDREA ***************************************************
00080 
00081   I can reassure you that your code is not boring at all.
00082   It's full of surprises...
00083 
00084   (it was a joke)
00085 
00086 *************************************************************/
00087 BOOL JString::OK() const
00088 {
00089   if ( pData != NULL )
00090   {
00091     if ( pData->length > pData->bufferSize )
00092     {
00093       printf( "ERROR in JString:  JString length > buffer" );
00094       return FALSE;
00095     }
00096 
00097     if ( pData->data == "" )
00098     {
00099       printf( "data = empty" );
00100     }
00101 
00102     if ( pData->data[ pData->length ] != 0 )
00103     {
00104       printf( "ERROR in JString:  JString not NULL terminated" );
00105       return FALSE;
00106     }
00107 
00108     if ( pData->data[ pData->bufferSize ] != 0 )
00109     {
00110       printf( "ERROR in JString:  JString Buffer not NULL terminated" );
00111       return FALSE;
00112     }
00113 
00114     if ( pData->length != strlen( pData->data ) )
00115     {
00116       printf( "ERROR in JString:  Length is not equal to strlen( data )" );
00117       return FALSE;
00118     }
00119 
00120     if ( pData->bufferSize < strlen( pData->data ) )
00121     {
00122       printf( "ERROR in JString:  Buffer Size is lower than strlen( data )" );
00123       return FALSE;
00124     }
00125   }
00126   else
00127   {
00128     printf( "ERROR in JString:  pData is NULL" );
00129     return FALSE;
00130   }
00131 
00132 #ifndef __J2K__QUIET
00133   printf("OK!\n");
00134 #endif
00135 
00136   return TRUE;
00137 }
00138 
00139 /** ANDREA ***************************************************
00140 
00141   I can't really tell much about this module as the concept
00142   of "lock" isn't clear to me.
00143 
00144   LOCK means that Doctor (the user) is messing up with your stomach
00145   in the Hospital Operation table (you are lying lock with handcuff
00146   on the table), so if you need to modify yourself too, use must
00147   clone yourself and to something else on your clone ! =P
00148 
00149   Another "more salty" analogy would be that:
00150 
00151   a JStringData can be 'virgin', 'married' or 'bitch/slut/hooker' (whatever)
00152 
00153   'virgin'  is not attached to any husband (pure JStringData)
00154 
00155   'married' is attached to one or many husband (JString, count >= 1)
00156             RefCount is used as a polygamie counter...
00157 
00158   'bitch'   is when JString is lock and she allow everyone
00159             to have fun with her as intimate as they want...
00160             Private part included... =P
00161 
00162             Since she's too "dirty" to have fun with her real husband,
00163             she must clone herself to get fresh virgin copy;
00164             therefore her husband can have fun with that
00165             new fresh clone, to do what he had to do with her...
00166 
00167   This remind me one of the C++ book I read:
00168   "A friend is someone who can touch your private parts..."
00169   (C++ Strategies and Tactics, Addison-Wesley)
00170 
00171 *************************************************************/
00172 
00173 #endif

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