Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::IDString Class Reference
[Base]

#include <OSGIDString.h>

Inheritance diagram for osg::IDString:

osg::IDStringLink List of all members.

Public Types

typedef std::vector< IDStringStringVec
typedef std::vector< IDString * > StringPVec
enum  MemType { COPY, LINK }

Public Member Functions

Constructors
IDString (UInt32 size=0)
 IDString (const Char8 *str, MemType memType=COPY)
 IDString (const IDString &obj, MemType memType=COPY)
Destructors
*virtual ~IDString (void)
Access
*const Char8str (void) const
bool isEmpty (void) const
void set (const Char8 *str, MemType memType=COPY)
void toUpper (void)
void toLower (void)
UInt32 getLength (void) const
void setLength (UInt32 length)
void tokenize (StringVec &v)
void tokenize (StringPVec &v)
Assignment
*const IDStringoperator= (const IDString &obj)
Comparison
*bool operator== (const IDString &obj) const
bool operator!= (const IDString &obj) const
bool operator< (const IDString &obj) const
bool operator> (const IDString &obj) const
bool operator>= (const IDString &obj) const
bool operator<= (const IDString &obj) const

Protected Attributes

Char8_str
MemType _memType

Friends

std::ostream & operator<< (std::ostream &os, const IDString &obj)

Detailed Description

Definition at line 62 of file OSGIDString.h.


Member Typedef Documentation

typedef std::vector<IDString > osg::IDString::StringVec
 

Definition at line 74 of file OSGIDString.h.

typedef std::vector<IDString *> osg::IDString::StringPVec
 

Definition at line 75 of file OSGIDString.h.


Member Enumeration Documentation

enum osg::IDString::MemType
 

Enumerator:
COPY 
LINK 

Definition at line 68 of file OSGIDString.h.

00069     {
00070         COPY,
00071         LINK
00072     };


Constructor & Destructor Documentation

IDString::IDString UInt32  size = 0  )  [explicit]
 

Definition at line 55 of file OSGIDString.cpp.

References setLength().

Referenced by tokenize().

00055                               : 
00056     _str    (NULL), 
00057     _memType(COPY)
00058 {
00059     setLength(size);
00060 }

IDString::IDString const Char8 str,
MemType  memType = COPY
[explicit]
 

Definition at line 62 of file OSGIDString.cpp.

References set().

00062                                                     : 
00063     _str    (NULL   ), 
00064     _memType(memType)
00065 {
00066     set(str, memType);
00067 }

IDString::IDString const IDString obj,
MemType  memType = COPY
 

Definition at line 69 of file OSGIDString.cpp.

References _str, and set().

00069                                                        :
00070     _str    (NULL   ), 
00071     _memType(memType)
00072 {
00073     set(obj._str, memType);
00074 }

IDString::~IDString void   )  [virtual]
 

Definition at line 79 of file OSGIDString.cpp.

References _memType, _str, and COPY.

00080 {
00081     if(_memType == COPY)
00082         delete [] _str;
00083 }


Member Function Documentation

const Char8 * osg::IDString::str void   )  const [inline]
 

Definition at line 42 of file OSGIDString.inl.

References _str.

Referenced by osg::FieldContainerType::addDescription(), osg::SharePtrGraphOp::compareFCs(), osg::deepClone(), osg::SimpleStatisticsForeground::draw(), osg::StatElemDescBase::findDescByName(), osg::TypeBase::getCName(), osg::FieldDescription::getCName(), osg::TypeBase::getCParentName(), osg::ImageFileHandler::getDefaultType(), osg::FieldDescription::getDefaultValue(), osg::FieldDescription::getField(), osg::ImageFileType::getMimeType(), osg::FieldContainerType::initFields(), osg::FieldContainerType::initialize(), osg::FieldContainerType::initParentFields(), osg::operator<<(), osg::IDStringLink::operator=(), osg::StatElemDescBase::print(), osg::RemoteAspect::receiveSync(), and osg::FieldContainerType::registerType().

00043 {
00044     return _str; 
00045 }

bool osg::IDString::isEmpty void   )  const [inline]
 

Definition at line 48 of file OSGIDString.inl.

References _str.

Referenced by osg::TypeFactory::registerType().

00049 {
00050     return (_str != NULL && *_str != '\0') ? false : true; 
00051 }

void IDString::set const Char8 str,
MemType  memType = COPY
 

Definition at line 88 of file OSGIDString.cpp.

References _memType, _str, and COPY.

Referenced by osg::ImageFileHandler::addImageFileType(), osg::SceneFileHandler::addSceneFileType(), osg::SceneFileHandler::getFileType(), osg::ImageFileHandler::getFileType(), IDString(), osg::ImageFileType::ImageFileType(), osg::IDStringLink::operator=(), operator=(), and osg::SceneFileHandler::subSceneFileType().

00089 {
00090     if(str == _str)
00091     {
00092         // !!! can you change _memType here? I think not. IMHO
00093         return;
00094     }
00095 
00096     if(_memType == COPY)
00097         delete [] _str;
00098 
00099     if(memType == COPY)
00100     {
00101         if(str != NULL)
00102         {
00103             _str = new Char8[strlen(str) + 1];
00104 
00105             strcpy(_str, str);
00106         }
00107         else
00108         {
00109             _str = NULL;
00110         }
00111     }
00112     else
00113     {
00114         _str = const_cast<Char8 *>(str);
00115     }
00116 
00117     _memType = memType;
00118 }

void IDString::toUpper void   ) 
 

Definition at line 124 of file OSGIDString.cpp.

References _str, and getLength().

00125 {
00126     UInt32 l = getLength();
00127 
00128     for(UInt32 i = 0; i < l; ++i)
00129     {
00130         _str[i] = ::toupper(_str[i]);
00131     }
00132 
00133 }

void IDString::toLower void   ) 
 

Definition at line 135 of file OSGIDString.cpp.

References _str, and getLength().

Referenced by osg::ImageFileHandler::addImageFileType(), osg::SceneFileHandler::addSceneFileType(), osg::SceneFileHandler::getFileType(), osg::ImageFileHandler::getFileType(), and osg::SceneFileHandler::subSceneFileType().

00136 {
00137     UInt32 l = getLength();
00138 
00139     for(UInt32 i = 0; i < l; ++i)
00140     {
00141         _str[i] = ::tolower(_str[i]);
00142     }
00143 
00144 }

UInt32 IDString::getLength void   )  const
 

Definition at line 150 of file OSGIDString.cpp.

References _str.

Referenced by osg::FieldDescription::isValid(), tokenize(), toLower(), and toUpper().

00151 {
00152     return (_str != NULL) ? ::strlen(_str) : 0;
00153 }

void IDString::setLength UInt32  length  ) 
 

Definition at line 155 of file OSGIDString.cpp.

References _memType, _str, and COPY.

Referenced by IDString().

00156 {
00157     if(_memType == COPY)
00158         delete [] _str;
00159 
00160     if(length != 0)
00161     {
00162          _str = new Char8[length];
00163         *_str = 0;
00164     }
00165     else
00166     {
00167         _str = 0;
00168     }
00169 
00170     _memType = COPY;
00171 }

void IDString::tokenize StringVec v  ) 
 

Definition at line 173 of file OSGIDString.cpp.

References _str, getLength(), and IDString().

00174 {
00175     UInt32 l        = getLength();
00176     UInt32 oldpos   = 0;
00177     UInt32 pos      = 0;
00178     bool   inQuotes = false;
00179     bool   inToken  = false;
00180 
00181     if(l > 0)
00182     {
00183         Char8 *buf = new Char8[l + 1];
00184 
00185         for(pos = 0; pos <= l; ++pos)
00186         {
00187             if(!inQuotes)
00188             {
00189                 if(!inToken)
00190                 {
00191                     if(_str[pos] == '"')
00192                     {
00193                         inQuotes = true;
00194                         oldpos   = pos + 1;
00195                     }
00196                     else if(_str[pos] != ' ')
00197                     {
00198                         inToken = true;
00199                         oldpos  = pos;
00200                     }
00201                 }
00202                 else if(inToken)
00203                 {
00204                     if(_str[pos] == '"')
00205                     {
00206                         inToken = false;
00207 
00208                         strncpy(buf, _str + oldpos, pos - oldpos);
00209 
00210                         buf[pos - oldpos] = '\0';
00211 
00212                         v.push_back(IDString(buf));
00213 
00214                         inQuotes = true;
00215                         oldpos   = pos;
00216                     }
00217                     else if(_str[pos] == ' ')
00218                     {
00219                         inToken = false;
00220 
00221                         strncpy(buf, _str + oldpos, pos - oldpos);
00222 
00223                         buf[pos - oldpos] = '\0';
00224 
00225                         v.push_back(IDString(buf));
00226                     }
00227                     else if(pos == l)
00228                     {
00229                         strncpy(buf, _str + oldpos, pos - oldpos);
00230 
00231                         buf[pos - oldpos] = '\0';
00232 
00233                         v.push_back(IDString(buf));
00234                     }
00235                 }
00236             }
00237             else if(inQuotes)
00238             {
00239                 if(_str[pos] == '"')
00240                 {
00241                     inQuotes = false;
00242 
00243                     if(pos > oldpos)
00244                     {
00245                         strncpy(buf, _str + oldpos, pos - oldpos);
00246 
00247                         buf[pos - oldpos] = '\0';
00248 
00249                         v.push_back(IDString(buf));
00250                     }
00251                 }
00252                 else if(pos == l)
00253                 {
00254                     if(pos > oldpos)
00255                     {
00256                         strncpy(buf, _str + oldpos, pos - oldpos);
00257 
00258                         buf[pos - oldpos] = '\0';
00259 
00260                         v.push_back(IDString(buf));
00261                     }
00262                 }
00263             }
00264         }
00265 
00266         delete [] buf;
00267     }
00268 }

void IDString::tokenize StringPVec v  ) 
 

Definition at line 270 of file OSGIDString.cpp.

References _str, getLength(), and IDString().

00271 {
00272     UInt32 l        = getLength();
00273     UInt32 oldpos   = 0;
00274     UInt32 pos      = 0;
00275     bool   inQuotes = false;
00276     bool   inToken  = false;
00277 
00278     IDString *pString = NULL;
00279 
00280     if(l > 0)
00281     {
00282         Char8 *buf = new Char8[l + 1];
00283 
00284         for(pos = 0; pos <= l; ++pos)
00285         {
00286             if(!inQuotes)
00287             {
00288                 if(!inToken)
00289                 {
00290                     if(_str[pos] == '"')
00291                     {
00292                         inQuotes = true;
00293                         oldpos   = pos + 1;
00294                     }
00295                     else if(_str[pos] != ' ')
00296                     {
00297                         inToken = true;
00298                         oldpos  = pos;
00299                     }
00300                 }
00301                 else if(inToken)
00302                 {
00303                     if(_str[pos] == '"')
00304                     {
00305                         inToken = false;
00306 
00307                         strncpy(buf, _str + oldpos, pos - oldpos);
00308 
00309                         buf[pos - oldpos] = '\0';
00310 
00311                         pString =  new IDString(buf);
00312 
00313                         v.push_back(pString);
00314 
00315                         inQuotes = true;
00316                         oldpos   = pos;
00317 
00318                     }
00319                     else if(_str[pos] == ' ')
00320                     {
00321                         inToken = false;
00322 
00323                         strncpy(buf, _str + oldpos, pos - oldpos);
00324 
00325                         buf[pos - oldpos] = '\0';
00326 
00327                         pString =  new IDString(buf);
00328 
00329                         v.push_back(pString);
00330                     }
00331                     else if(pos == l)
00332                     {
00333                         strncpy(buf, _str + oldpos, pos - oldpos);
00334 
00335                         buf[pos - oldpos] = '\0';
00336 
00337                         pString =  new IDString(buf);
00338 
00339                         v.push_back(pString);
00340                     }
00341                 }
00342             }
00343             else if(inQuotes)
00344             {
00345                 if(_str[pos] == '"')
00346                 {
00347                     inQuotes = false;
00348 
00349                     if(pos > oldpos)
00350                     {
00351                         strncpy(buf, _str + oldpos, pos - oldpos);
00352 
00353                         buf[pos - oldpos] = '\0';
00354 
00355                         pString =  new IDString(buf);
00356 
00357                         v.push_back(pString);
00358                     }
00359                 }
00360                 else if(pos == l)
00361                 {
00362                     if(pos > oldpos)
00363                     {
00364                         strncpy(buf, _str + oldpos, pos - oldpos);
00365 
00366                         buf[pos - oldpos] = '\0';
00367 
00368                         pString =  new IDString(buf);
00369 
00370                         v.push_back(pString);
00371                     }
00372                 }
00373             }
00374         }
00375 
00376         delete [] buf;
00377     }
00378 }

const IDString & osg::IDString::operator= const IDString obj  )  [inline]
 

Definition at line 54 of file OSGIDString.inl.

References _str, and set().

00055 {
00056     set(obj._str);
00057     
00058     return *this;
00059 }

bool osg::IDString::operator== const IDString obj  )  const [inline]
 

Definition at line 62 of file OSGIDString.inl.

References _str.

00063 {
00064     return ((_str == obj._str) ? 
00065             1 : 
00066             (_str != NULL && obj._str != NULL && !::strcmp(_str, obj._str)));
00067 }

bool osg::IDString::operator!= const IDString obj  )  const [inline]
 

Definition at line 70 of file OSGIDString.inl.

00071 {
00072     return ! (*this == obj);
00073 }

bool osg::IDString::operator< const IDString obj  )  const [inline]
 

Definition at line 76 of file OSGIDString.inl.

References _str.

00077 {
00078     return (    _str != NULL && 
00079             obj._str != NULL && 
00080             (::strcmp(_str, obj._str) < 0));
00081 }

bool osg::IDString::operator> const IDString obj  )  const [inline]
 

Definition at line 84 of file OSGIDString.inl.

00085 {
00086         return ! (*this < obj) && ! (*this == obj);
00087 }

bool osg::IDString::operator>= const IDString obj  )  const [inline]
 

Definition at line 90 of file OSGIDString.inl.

00091 {
00092     return ! (*this < obj);
00093 }

bool osg::IDString::operator<= const IDString obj  )  const [inline]
 

Definition at line 96 of file OSGIDString.inl.

00097 {
00098     return (*this < obj) || (*this == obj);
00099 }


Friends And Related Function Documentation

std::ostream& operator<< std::ostream &  os,
const IDString obj
[friend]
 

Definition at line 383 of file OSGIDString.cpp.

00385 {
00386     return os << (obj.str() ? obj.str() : "0 IDString");
00387 }


Member Data Documentation

Char8* osg::IDString::_str [protected]
 

Definition at line 145 of file OSGIDString.h.

Referenced by getLength(), IDString(), isEmpty(), operator<(), operator=(), operator==(), set(), setLength(), str(), tokenize(), toLower(), toUpper(), and ~IDString().

MemType osg::IDString::_memType [protected]
 

Definition at line 146 of file OSGIDString.h.

Referenced by set(), setLength(), and ~IDString().


The documentation for this class was generated from the following files:
Generated on Thu Aug 25 04:12:34 2005 for OpenSG by  doxygen 1.4.3