#include <StrData.hpp>
Public Methods | |
| JStringData () | |
| JStringData (const char *s) | |
| JStringData (const char *s, ULONG nBuffer) | |
| JStringData (const JStringData &sd) | |
| JStringData (ULONG nBuffer) | |
| JStringData (char fill, ULONG nRepeat) | |
| JStringData (char fill, ULONG nRepeat, ULONG nBuffer) | |
| virtual | ~JStringData () |
| void | Dec () |
| void | Inc () |
| void | Init (const char *s, ULONG nBuffer) |
| void | InitBuffer (ULONG nBuffer, char fill) |
| void | Clear (char fill) |
| JStringData () | |
| JStringData (const char *s) | |
| JStringData (const char *s, size_t nBuffer) | |
| JStringData (const JStringData &sd) | |
| JStringData (size_t nBuffer) | |
| JStringData (char fill, size_t nRepeat) | |
| JStringData (char fill, size_t nRepeat, size_t nBuffer) | |
| virtual | ~JStringData () |
| void | Dec () |
| void | Inc () |
| void | Init (const char *s, size_t nBuffer) |
| void | InitBuffer (size_t nBuffer, char fill) |
| void | Clear (char fill) |
Static Public Methods | |
| JStringData * | strNull () |
| JStringData * | strNull () |
Public Attributes | |
| ULONG | bufferSize |
| ULONG | length |
| long | nbRefs |
| int | lock |
| char * | data |
| size_t | bufferSize |
| size_t | length |
| char * | data |
Private Methods | |
| const JStringData & | operator= (const JStringData &sd) |
| const JStringData & | operator= (const JStringData &sd) |
What do you think sizeof(ULONG) will return ? Fortunately you never used that defined symbol anywhere.
This is for portability, some system might use long or long long or ...
Definition at line 25 of file StrData.hpp.
|
|
Constructor, Copy Constructor and Destructor ////////////////////////////////////////////////////////////////////////////.
Definition at line 9 of file StrData.inl. 00010 : nbRefs( 1 ), length( 0 ), lock( 0 ), bufferSize( 0 ) 00011 { 00012 data = ""; 00013 } |
|
|
Definition at line 15 of file StrData.inl. |
|
||||||||||||
|
Definition at line 34 of file StrData.inl. 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 } |
|
|
Definition at line 54 of file StrData.inl. 00055 : nbRefs( 1 ), lock( 0 ), length( sd.length ), bufferSize( sd.bufferSize ) 00056 { 00057 Init( sd.data, sd.bufferSize ); 00058 } |
|
|
Definition at line 60 of file StrData.inl. 00061 : nbRefs( 1 ), length( 0 ), lock( 0 ), bufferSize( nBuffer ) 00062 { 00063 InitBuffer( nBuffer, '\0' ); 00064 } |
|
||||||||||||
|
Definition at line 66 of file StrData.inl. 00067 : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( 0 ) 00068 { 00069 InitBuffer( nRepeat, fill ); 00070 } |
|
||||||||||||||||
|
Definition at line 72 of file StrData.inl. 00073 : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( nBuffer ) 00074 { 00075 InitBuffer( nRepeat, fill ); 00076 } |
|
|
Definition at line 78 of file StrData.inl. 00079 {
00080 if ( data != NULL && *data != '\0' ) {
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 }
|
|
|
Constructor, Copy Constructor and Destructor ////////////////////////////////////////////////////////////////////////////.
|
|
|
|
|
||||||||||||
|
Definition at line 21 of file StrData.inl. |
|
|
|
|
|
Definition at line 33 of file StrData.inl. 00034 : nbRefs( 1 ), length( 0 ), lock( 0 ), bufferSize( nBuffer ) 00035 { 00036 InitBuffer( nBuffer, '\0' ); 00037 } |
|
||||||||||||
|
Definition at line 39 of file StrData.inl. 00040 : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( 0 ) 00041 { 00042 InitBuffer( nRepeat, fill ); 00043 } |
|
||||||||||||||||
|
Definition at line 45 of file StrData.inl. 00046 : nbRefs( 1 ), length( nRepeat ), lock( 0 ), bufferSize( nBuffer ) 00047 { 00048 InitBuffer( nRepeat, fill ); 00049 } |
|
|
|
|
|
|
|
|
Definition at line 50 of file StrData.cpp. Referenced by JString::Clear().
00050 {
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 }
|
|
|
Utility functions ////////////////////////////////////////////////////////////////////////////.
|
|
|
Utility functions ////////////////////////////////////////////////////////////////////////////. I delete only if new[] was call no ? Definition at line 103 of file StrData.inl. Referenced by JString::Add(), JString::AllocBeforeWrite(), JString::AllocBuffer(), JString::Clear(), JString::CopyBeforeWrite(), JString::Empty(), JString::FillBuffer(), JString::FillString(), JString::FreeExtra(), JString::GetBuffer(), JSubString::JSubString::operator=(), JString::ReleaseBuffer(), JString::charAt(), JString::modifyAt(), JString::operator=(), JString::setConcatenate(), JString::setConcatenateWithLimits(), JString::setDate(), JString::setFillWithChar(), JString::setTime(), JString::setTimeFormat(), JString::setTransform(), and JString::~JString().
00104 {
00105 if ( this == strNull || lock != 0 ) return;
00106
00107 if ( --nbRefs == 0 ) // If not used anymore,
00108 {
00109 #ifdef __J2K__DEBUG
00110 printf("\nStringData[%s], Counter decrement[%d]\n", data, nbRefs );
00111 #endif
00112
00113 delete this; // then Suicide yourself ( Ahhhh... BANG! =)
00114 }
00115 }
|
|
|
|
|
|
Definition at line 117 of file StrData.inl. Referenced by JString::JString(), JSubString::JSubString(), and JString::operator=().
00118 {
00119 if ( this == strNull ) return;
00120
00121 #ifdef __J2K__DEBUG
00122 printf("\nStringData[%s], Counter increment[%d]\n", data, nbRefs );
00123 #endif
00124
00125 ++nbRefs;
00126 }
|
|
||||||||||||
|
Utilities and function helper ////////////////////////////////////////////////////////////////////////////.
Definition at line 9 of file StrData.cpp. 00009 {
00010 if ( s == NULL || *s == '\0' ) {
00011 InitBuffer( nBuffer, '\0' );
00012 } else {
00013 length = strlen( s );
00014
00015 if (nBuffer > length) {
00016 bufferSize = nBuffer;
00017 } else {
00018 bufferSize = length;
00019 }
00020
00021 data = new char[ bufferSize + 1 ];
00022 assert( data != NULL ); // Exit if memory not allocated.
00023 data[length] = '\0';
00024 memcpy( data, s, length );
00025
00026 assert( data[length] == '\0' );
00027 assert( data[bufferSize] == '\0' );
00028
00029 /** ANDREA ***************************************************
00030
00031 Completely useless assignment. If you're really paranoid at
00032 least change it to assert(data[lenght]=='\0').
00033
00034 ok.
00035 done.
00036
00037 *************************************************************/
00038 }
00039 }
|
|
||||||||||||
|
Utilities and function helper ////////////////////////////////////////////////////////////////////////////.
Definition at line 14 of file StrData.cpp. Referenced by JStringData(), and operator=().
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 }
|
|
||||||||||||
|
ANDREA ***************************************************. Completely useless assignment. If you're really paranoid at least change it to assert(data[lenght]=='\0'). ok. done. Definition at line 41 of file StrData.cpp. 00041 {
00042 if ( nRepeat > 0 ) {
00043 if ( bufferSize < nRepeat ) {
00044 bufferSize = nRepeat;
00045 }
00046 data = new char[ bufferSize + 1];
00047 assert( data != NULL ); // Exit if memory not allocated.
00048
00049 // Clear memory with NULLs
00050 memset( data, fill, nRepeat );
00051 memset( data + nRepeat, 0, bufferSize - nRepeat );
00052
00053 data[nRepeat] = '\0';
00054 data[bufferSize] = '\0';
00055
00056 /*
00057 size_t i = 0;
00058 for( ; i < nRepeat; i++) {
00059 data[i] = fill;
00060 }
00061 for( i = nRepeat; i <= bufferSize; i++) {
00062 data[i] = '\0';
00063 }
00064 */
00065 } else {
00066 bufferSize = 0;
00067 data = NULL;
00068 }
00069 }
|
|
||||||||||||
|
Definition at line 29 of file StrData.cpp. Referenced by Init(), and JStringData().
00029 {
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 }
|
|
|
|
|
|
ANDREA ***************************************************. Why not using memset ? ughhh, didn't know that. I see in Watcom C++ Ref that it exist really, will it be faster? Now, I know and it's very cool to use it ! =] Definition at line 87 of file StrData.cpp. 00087 {
00088 nbRefs = 1;
00089 Init( sd.data, sd.bufferSize );
00090 return *this;
00091 }
|
|
|
Definition at line 67 of file StrData.hpp. 00068 {
00069 static JStringData s;
00070 return &s;
00071 }
|
|
|
Definition at line 67 of file StrData.hpp. 00068 {
00069 static JStringData s;
00070 return &s;
00071 }
|
|
|
Definition at line 27 of file StrData.hpp. |
|
|
Definition at line 27 of file StrData.hpp. Referenced by JString::AllocBeforeWrite(), JString::Append(), JString::FillBuffer(), JString::FillString(), JString::FreeExtra(), JString::GetBuffer(), JString::OK(), JString::getAllocLength(), JString::getBufferSize(), and operator=().
|
|
|
Definition at line 31 of file StrData.hpp. |
|
|
|
Definition at line 28 of file StrData.hpp. |
|
|
|
Definition at line 30 of file StrData.hpp. Referenced by JString::Clear(), JString::CopyBeforeWrite(), JString::FillBuffer(), JString::FillString(), JString::GetBuffer(), JString::ReleaseBuffer(), JString::getLockNb(), JString::isLock(), and JString::isUnlock().
|
|
|
Definition at line 29 of file StrData.hpp. Referenced by JString::AllocBeforeWrite(), JString::Append(), JString::Clear(), JString::CopyBeforeWrite(), JString::FillBuffer(), JString::FillString(), and JString::GetBuffer().
|
1.2.11.1 written by Dimitri van Heesch,
© 1997-2001