xmlTiny::TiXmlString Class Reference

#include <OBTtinystr.h>

Inheritance diagram for xmlTiny::TiXmlString:

Inheritance graph
[legend]
Collaboration diagram for xmlTiny::TiXmlString:

Collaboration graph
[legend]

List of all members.

Public Types

typedef size_t size_type

Public Member Functions

 TiXmlString ()
 TiXmlString (const TiXmlString &copy)
TIXML_EXPLICIT TiXmlString (const char *copy)
TIXML_EXPLICIT TiXmlString (const char *str, size_type len)
 ~TiXmlString ()
TiXmlStringoperator= (const char *copy)
TiXmlStringoperator= (const TiXmlString &copy)
TiXmlStringoperator+= (const char *suffix)
TiXmlStringoperator+= (char single)
TiXmlStringoperator+= (const TiXmlString &suffix)
const char * c_str () const
const char * data () const
size_type length () const
size_type size () const
bool empty () const
size_type capacity () const
const char & at (size_type index) const
char & operator[] (size_type index) const
size_type find (char lookup) const
size_type find (char tofind, size_type offset) const
void clear ()
void reserve (size_type cap)
TiXmlStringassign (const char *str, size_type len)
TiXmlStringappend (const char *str, size_type len)
void swap (TiXmlString &other)

Static Public Attributes

static const size_type npos = static_cast< TiXmlString::size_type >(-1)

Private Member Functions

void init (size_type sz)
void set_size (size_type sz)
char * start () const
char * finish () const
void init (size_type sz, size_type cap)
void quit ()

Private Attributes

Reprep_

Static Private Attributes

static Rep nullrep_ = { 0, 0, { '\0' } }

Classes

struct  Rep


Detailed Description

Definition at line 68 of file tmp/OBTtinystr.h.


Member Typedef Documentation

typedef size_t xmlTiny::TiXmlString::size_type

Definition at line 72 of file tmp/OBTtinystr.h.


Constructor & Destructor Documentation

xmlTiny::TiXmlString::TiXmlString (  )  [inline]

Definition at line 79 of file tmp/OBTtinystr.h.

00079                        : rep_(&nullrep_)
00080         {
00081         }

xmlTiny::TiXmlString::TiXmlString ( const TiXmlString copy  )  [inline]

Definition at line 84 of file tmp/OBTtinystr.h.

References data(), init(), length(), and start().

00084                                                 : rep_(0)
00085         {
00086                 init(copy.length());
00087                 memcpy(start(), copy.data(), length());
00088         }

TIXML_EXPLICIT xmlTiny::TiXmlString::TiXmlString ( const char *  copy  )  [inline]

Definition at line 91 of file tmp/OBTtinystr.h.

References init(), length(), and start().

00091                                                         : rep_(0)
00092         {
00093                 init( static_cast<size_type>( strlen(copy) ));
00094                 memcpy(start(), copy, length());
00095         }

TIXML_EXPLICIT xmlTiny::TiXmlString::TiXmlString ( const char *  str,
size_type  len 
) [inline]

Definition at line 98 of file tmp/OBTtinystr.h.

References init(), and start().

00098                                                                       : rep_(0)
00099         {
00100                 init(len);
00101                 memcpy(start(), str, len);
00102         }

xmlTiny::TiXmlString::~TiXmlString (  )  [inline]

Definition at line 105 of file tmp/OBTtinystr.h.

References quit().

00106         {
00107                 quit();
00108         }


Member Function Documentation

TiXmlString& xmlTiny::TiXmlString::operator= ( const char *  copy  )  [inline]

Definition at line 111 of file tmp/OBTtinystr.h.

References assign().

00112         {
00113                 return assign( copy, (size_type)strlen(copy));
00114         }

TiXmlString& xmlTiny::TiXmlString::operator= ( const TiXmlString copy  )  [inline]

Definition at line 117 of file tmp/OBTtinystr.h.

References assign(), length(), and start().

00118         {
00119                 return assign(copy.start(), copy.length());
00120         }

TiXmlString& xmlTiny::TiXmlString::operator+= ( const char *  suffix  )  [inline]

Definition at line 124 of file tmp/OBTtinystr.h.

References append().

00125         {
00126                 return append(suffix, static_cast<size_type>( strlen(suffix) ));
00127         }

TiXmlString& xmlTiny::TiXmlString::operator+= ( char  single  )  [inline]

Definition at line 130 of file tmp/OBTtinystr.h.

References append().

00131         {
00132                 return append(&single, 1);
00133         }

TiXmlString& xmlTiny::TiXmlString::operator+= ( const TiXmlString suffix  )  [inline]

Definition at line 136 of file tmp/OBTtinystr.h.

References append(), data(), and length().

00137         {
00138                 return append(suffix.data(), suffix.length());
00139         }

const char* xmlTiny::TiXmlString::c_str (  )  const [inline]

Definition at line 143 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::str.

Referenced by find(), xmlTiny::operator<(), and xmlTiny::operator==().

00143 { return rep_->str; }

const char* xmlTiny::TiXmlString::data (  )  const [inline]

Definition at line 146 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::str.

Referenced by operator+=(), reserve(), and TiXmlString().

00146 { return rep_->str; }

size_type xmlTiny::TiXmlString::length (  )  const [inline]

Definition at line 149 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::size.

Referenced by append(), at(), find(), xmlTiny::operator+(), operator+=(), operator=(), xmlTiny::operator==(), operator[](), reserve(), and TiXmlString().

00149 { return rep_->size; }

size_type xmlTiny::TiXmlString::size (  )  const [inline]

Definition at line 152 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::size.

00152 { return rep_->size; }

bool xmlTiny::TiXmlString::empty (  )  const [inline]

Definition at line 155 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::size.

00155 { return rep_->size == 0; }

size_type xmlTiny::TiXmlString::capacity (  )  const [inline]

Definition at line 158 of file tmp/OBTtinystr.h.

References xmlTiny::TiXmlString::Rep::capacity, and rep_.

Referenced by append(), assign(), and reserve().

00158 { return rep_->capacity; }

const char& xmlTiny::TiXmlString::at ( size_type  index  )  const [inline]

Definition at line 162 of file tmp/OBTtinystr.h.

References length(), rep_, and xmlTiny::TiXmlString::Rep::str.

00163         {
00164                 assert( index < length() );
00165                 return rep_->str[ index ];
00166         }

char& xmlTiny::TiXmlString::operator[] ( size_type  index  )  const [inline]

Definition at line 169 of file tmp/OBTtinystr.h.

References length(), rep_, and xmlTiny::TiXmlString::Rep::str.

00170         {
00171                 assert( index < length() );
00172                 return rep_->str[ index ];
00173         }

size_type xmlTiny::TiXmlString::find ( char  lookup  )  const [inline]

Definition at line 176 of file tmp/OBTtinystr.h.

00177         {
00178                 return find(lookup, 0);
00179         }

size_type xmlTiny::TiXmlString::find ( char  tofind,
size_type  offset 
) const [inline]

Definition at line 182 of file tmp/OBTtinystr.h.

References c_str(), length(), and npos.

00183         {
00184                 if (offset >= length()) return npos;
00185 
00186                 for (const char* p = c_str() + offset; *p != '\0'; ++p)
00187                 {
00188                    if (*p == tofind) return static_cast< size_type >( p - c_str() );
00189                 }
00190                 return npos;
00191         }

void xmlTiny::TiXmlString::clear (  )  [inline]

Definition at line 193 of file tmp/OBTtinystr.h.

References init(), and quit().

00194         {
00195                 //Lee:
00196                 //The original was just too strange, though correct:
00197                 //      TiXmlString().swap(*this);
00198                 //Instead use the quit & re-init:
00199                 quit();
00200                 init(0,0);
00201         }

void xmlTiny::TiXmlString::reserve ( size_type  cap  ) 

Definition at line 44 of file tmp/OBTtinystr.cpp.

References capacity(), data(), init(), length(), start(), and swap().

Referenced by append(), and xmlTiny::operator+().

00045 {
00046         if (cap > capacity())
00047         {
00048                 TiXmlString tmp;
00049                 tmp.init(length(), cap);
00050                 memcpy(tmp.start(), data(), length());
00051                 swap(tmp);
00052         }
00053 }

TiXmlString & xmlTiny::TiXmlString::assign ( const char *  str,
size_type  len 
)

Definition at line 56 of file tmp/OBTtinystr.cpp.

References capacity(), init(), set_size(), start(), and swap().

Referenced by operator=().

00057 {
00058         size_type cap = capacity();
00059         if (len > cap || cap > 3*(len + 8))
00060         {
00061                 TiXmlString tmp;
00062                 tmp.init(len);
00063                 memcpy(tmp.start(), str, len);
00064                 swap(tmp);
00065         }
00066         else
00067         {
00068                 memmove(start(), str, len);
00069                 set_size(len);
00070         }
00071         return *this;
00072 }

TiXmlString & xmlTiny::TiXmlString::append ( const char *  str,
size_type  len 
)

Definition at line 75 of file tmp/OBTtinystr.cpp.

References capacity(), finish(), length(), reserve(), and set_size().

Referenced by xmlTiny::operator+(), and operator+=().

00076 {
00077         size_type newsize = length() + len;
00078         if (newsize > capacity())
00079         {
00080                 reserve (newsize + capacity());
00081         }
00082         memmove(finish(), str, len);
00083         set_size(newsize);
00084         return *this;
00085 }

void xmlTiny::TiXmlString::swap ( TiXmlString other  )  [inline]

Definition at line 212 of file tmp/OBTtinystr.h.

References rep_.

Referenced by assign(), and reserve().

00213         {
00214                 Rep* r = rep_;
00215                 rep_ = other.rep_;
00216                 other.rep_ = r;
00217         }

void xmlTiny::TiXmlString::init ( size_type  sz  )  [inline, private]

Definition at line 221 of file tmp/OBTtinystr.h.

Referenced by assign(), clear(), reserve(), and TiXmlString().

00221 { init(sz, sz); }

void xmlTiny::TiXmlString::set_size ( size_type  sz  )  [inline, private]

Definition at line 222 of file tmp/OBTtinystr.h.

References rep_, xmlTiny::TiXmlString::Rep::size, and xmlTiny::TiXmlString::Rep::str.

Referenced by append(), and assign().

00222 { rep_->str[ rep_->size = sz ] = '\0'; }

char* xmlTiny::TiXmlString::start (  )  const [inline, private]

Definition at line 223 of file tmp/OBTtinystr.h.

References rep_, and xmlTiny::TiXmlString::Rep::str.

Referenced by assign(), operator=(), reserve(), and TiXmlString().

00223 { return rep_->str; }

char* xmlTiny::TiXmlString::finish (  )  const [inline, private]

Definition at line 224 of file tmp/OBTtinystr.h.

References rep_, xmlTiny::TiXmlString::Rep::size, and xmlTiny::TiXmlString::Rep::str.

Referenced by append().

00224 { return rep_->str + rep_->size; }

void xmlTiny::TiXmlString::init ( size_type  sz,
size_type  cap 
) [inline, private]

Definition at line 232 of file tmp/OBTtinystr.h.

References xmlTiny::TiXmlString::Rep::capacity, nullrep_, rep_, xmlTiny::TiXmlString::Rep::size, and xmlTiny::TiXmlString::Rep::str.

00233         {
00234                 if (cap)
00235                 {
00236                         // Lee: the original form:
00237                         //      rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
00238                         // doesn't work in some cases of new being overloaded. Switching
00239                         // to the normal allocation, although use an 'int' for systems
00240                         // that are overly picky about structure alignment.
00241                         const size_type bytesNeeded = sizeof(Rep) + cap;
00242                         const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); 
00243                         rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
00244 
00245                         rep_->str[ rep_->size = sz ] = '\0';
00246                         rep_->capacity = cap;
00247                 }
00248                 else
00249                 {
00250                         rep_ = &nullrep_;
00251                 }
00252         }

void xmlTiny::TiXmlString::quit (  )  [inline, private]

Definition at line 254 of file tmp/OBTtinystr.h.

References nullrep_, and rep_.

Referenced by clear(), and ~TiXmlString().

00255         {
00256                 if (rep_ != &nullrep_)
00257                 {
00258                         // The rep_ is really an array of ints. (see the allocator, above).
00259                         // Cast it back before delete, so the compiler won't incorrectly call destructors.
00260                         delete [] ( reinterpret_cast<int*>( rep_ ) );
00261                 }
00262         }


Member Data Documentation

const TiXmlString::size_type xmlTiny::TiXmlString::npos = static_cast< TiXmlString::size_type >(-1) [static]

Definition at line 75 of file tmp/OBTtinystr.h.

Referenced by find().

Rep* xmlTiny::TiXmlString::rep_ [private]

Definition at line 264 of file tmp/OBTtinystr.h.

Referenced by at(), c_str(), capacity(), data(), empty(), finish(), init(), length(), operator[](), quit(), set_size(), size(), start(), and swap().

TiXmlString::Rep xmlTiny::TiXmlString::nullrep_ = { 0, 0, { '\0' } } [static, private]

Definition at line 265 of file tmp/OBTtinystr.h.

Referenced by init(), and quit().


Generated on Wed Oct 1 11:34:24 2008 for OBT by  doxygen 1.5.3