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

C:/temp/src/j2k/Deprecated/old_18mar_diff/Str14dec/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 ULONG i = 0;
00028   if ( pData->length < 1 ) return;
00029   if ( pData->nbRefs == 1  &&  pData != strNull  &&  pData->lock == 0 ) {
00030     for( ; i < pData->length; i++ ) {
00031       pData->data[i] = ch;
00032     }
00033     for( i = pData->length; i <= pData->bufferSize; i++ ) {
00034       pData->data[i] = '\0';
00035     }
00036   } else {
00037     ULONG nRepeat = pData->length;
00038     JStringData* sd = pData;
00039     pData = new JStringData(ch, pData->length, pData->bufferSize );
00040     sd->Dec();
00041   }
00042   pData->data[pData->length] = '\0';
00043 }
00044 
00045 void JString::FillBuffer( char ch ) {
00046   register ULONG i = 0;
00047   if ( pData->bufferSize < 1 ) return;
00048   if ( pData->nbRefs == 1  &&  pData != strNull  &&  pData->lock == 0 ) {
00049     for( ; i < pData->bufferSize; i++ ) {
00050       pData->data[i] = ch;
00051     }
00052   } else {
00053     JStringData* sd = pData;
00054     pData = new JStringData( ch, pData->bufferSize, pData->bufferSize );
00055     sd->Dec();
00056   }
00057   pData->length = pData->bufferSize;
00058   pData->data[pData->length] = '\0';
00059 }
00060 
00061 // Debug checking function: this.OK() == OK ? =P
00062 // Code reading is so boring sometime, so jokes are always welcome...
00063 /** ANDREA ***************************************************
00064 
00065   I can reassure you that your code is not boring at all.
00066   It's full of surprises...
00067 
00068   (it was a joke)
00069 
00070 *************************************************************/
00071 BOOL JString::OK() const
00072 {
00073   if ( pData != NULL ) {
00074     if ( pData->length > pData->bufferSize ) {
00075       printf( "ERROR in JString:  JString length > buffer" );
00076       return FALSE;
00077     }
00078     if ( pData->data == "" ) {
00079       printf( "data = empty" );
00080     }
00081     
00082     if ( pData->data[ pData->length ] != 0 ) {
00083       printf( "ERROR in JString:  JString not NULL terminated" );
00084       return FALSE;
00085     }
00086 
00087     if ( pData->data[ pData->bufferSize ] != 0 ) {
00088       printf( "ERROR in JString:  JString Buffer not NULL terminated" );
00089       return FALSE;
00090     }
00091     
00092     if ( pData->length != strlen( pData->data ) ) { 
00093       printf( "ERROR in JString:  Length is not equal to strlen( data )" );
00094       return FALSE;
00095     }
00096     
00097     if ( pData->bufferSize < strlen( pData->data ) ) {
00098       printf( "ERROR in JString:  Buffer Size is lower than strlen( data )" );
00099       return FALSE;
00100     }
00101   } else {
00102     printf( "ERROR in JString:  pData is NULL" );
00103     return FALSE;
00104   }
00105 
00106 #ifndef __J2K__QUIET
00107   printf("OK!\n");   
00108 #endif
00109 
00110   return TRUE;
00111 }
00112 
00113 /** ANDREA ***************************************************
00114 
00115   I can't really tell much about this module as the concept
00116   of "lock" isn't clear to me.
00117 
00118   LOCK means that Doctor (the user) is messing up with your stomach 
00119   in the Hospital Operation table (you are lying lock with handcuff
00120   on the table), so if you need to modify yourself too, use must
00121   clone yourself and to something else on your clone ! =P
00122 
00123   Another "more salty" analogy would be that:
00124 
00125   a JStringData can be 'virgin', 'married' or 'bitch/slut/hooker' (whatever)
00126 
00127   'virgin'  is not attached to any husband (pure JStringData)
00128 
00129   'married' is attached to one or many husband (JString, count >= 1)
00130             RefCount is used as a polygamie counter...
00131 
00132   'bitch'   is when JString is lock and she allow everyone
00133             to have fun with her as intimate as they want...
00134             Private part included... =P
00135 
00136             Since she's too "dirty" to have fun with her real husband,
00137             she must clone herself to get fresh virgin copy;
00138             therefore her husband can have fun with that
00139             new fresh clone, to do what he had to do with her...
00140 
00141   This remind me one of the C++ book I read:
00142   "A friend is someone who can touch your private parts..."
00143   (C++ Strategies and Tactics, Addison-Wesley)
00144 
00145 *************************************************************/
00146 
00147 #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