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/StrData.cpp

Go to the documentation of this file.
00001 #ifndef __J2K__JString_Data_CPP__
00002 #define __J2K__JString_Data_CPP__
00003 
00004 #include <j2k/Fred/String/StrData.hpp>
00005 
00006 ////////////////////////////////////////////////////////////////////////////
00007 /// Utilities and function helper                                        ///
00008 ////////////////////////////////////////////////////////////////////////////
00009 
00010 /*
00011  if strlen(s) > nBuffer then rip-off, used by at() functions.
00012 */
00013 
00014 void JStringData::Init(const char* s, ULONG nBuffer) 
00015 {
00016   if ( s == NULL  ||  *s == '\0' ) {
00017     InitBuffer( nBuffer, '\0' );
00018   } else {
00019     bufferSize = nBuffer;
00020 
00021     data = new char[ bufferSize + 1 ];
00022     assert( data != NULL );  // Exit if memory not allocated.
00023     memcpy( data, s, nBuffer );
00024 
00025     data[ nBuffer ] = '\0';  // Needed if we rip-off strings
00026   }
00027 }
00028 
00029 void JStringData::InitBuffer( ULONG nRepeat, char fill ) {
00030   if ( nRepeat > 0 ) {
00031     if ( bufferSize < nRepeat ) {
00032       bufferSize = nRepeat;
00033     }
00034     data = new char[ bufferSize + 1];
00035     assert( data != NULL );  // Exit if memory not allocated.
00036 
00037     // Clear memory with NULLs
00038     memset( data, fill, nRepeat );
00039     memset( data + nRepeat, 0, bufferSize - nRepeat );
00040 
00041     data[nRepeat]    = '\0';
00042     data[bufferSize] = '\0';
00043 
00044   } else {
00045     bufferSize = 0;
00046     data = NULL;
00047   }
00048 }
00049 
00050 void JStringData::Clear( char fill ) {
00051   if ( data == NULL ) return;
00052 
00053 
00054   memset( data, fill, bufferSize );
00055 
00056 
00057  
00058   // Clear memory with NULLs
00059   /*
00060   for( ULONG i = 0; i < bufferSize; i++) { 
00061     data[i] = fill;
00062   }
00063   */
00064 
00065   data[bufferSize] = '\0';
00066 
00067   if ( fill != '\0' ) {
00068     length = bufferSize;
00069   } else {
00070     length = 0;
00071   }
00072 
00073 /** ANDREA ***************************************************
00074 
00075   Why not using memset ? 
00076 
00077   ughhh, didn't know that.
00078   I see in Watcom C++ Ref that it exist really,
00079   will it be faster?
00080 
00081   Now, I know and it's very cool to use it ! =]
00082 
00083 *************************************************************/
00084 
00085 }
00086 
00087 const JStringData& JStringData::operator=(const JStringData& sd) {
00088   nbRefs = 1;
00089   Init( sd.data, sd.bufferSize );
00090   return *this;
00091 }
00092 
00093 #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