Back to index

nux  3.0.0
Classes | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
TiXmlString Class Reference

#include <tinystr.h>

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

List of all members.

Classes

struct  Rep

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' } }

Detailed Description

Definition at line 89 of file tinystr.h.


Class Documentation

struct TiXmlString::Rep

Definition at line 278 of file tinystr.h.

Class Members
size_type capacity
size_type size
char str

Member Typedef Documentation

typedef size_t TiXmlString::size_type

Definition at line 93 of file tinystr.h.


Constructor & Destructor Documentation

Definition at line 100 of file tinystr.h.

                 : rep_ (&nullrep_)
  {
  }
TiXmlString::TiXmlString ( const TiXmlString copy) [inline]

Definition at line 105 of file tinystr.h.

                                         : rep_ (0)
  {
    init (copy.length() );
    memcpy (start(), copy.data(), length() );
  }

Here is the call graph for this function:

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

Definition at line 112 of file tinystr.h.

                                                 : rep_ (0)
  {
    init ( static_cast<size_type> ( strlen (copy) ) );
    memcpy (start(), copy, length() );
  }

Here is the call graph for this function:

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

Definition at line 119 of file tinystr.h.

                                                               : rep_ (0)
  {
    init (len);
    memcpy (start(), str, len);
  }

Here is the call graph for this function:

Definition at line 126 of file tinystr.h.

  {
    quit();
  }

Here is the call graph for this function:


Member Function Documentation

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

Definition at line 97 of file tinystr.cpp.

{
  size_type newsize = length() + len;

  if (newsize > capacity() )
  {
    reserve (newsize + capacity() );
  }

  memmove (finish(), str, len);
  set_size (newsize);
  return *this;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 76 of file tinystr.cpp.

{
  size_type cap = capacity();

  if (len > cap || cap > 3 * (len + 8) )
  {
    TiXmlString tmp;
    tmp.init (len);
    memcpy (tmp.start(), str, len);
    swap (tmp);
  }
  else
  {
    memmove (start(), str, len);
    set_size (len);
  }

  return *this;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 201 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 164 of file tinystr.h.

  {
    return rep_->str;
  }

Here is the caller graph for this function:

size_type TiXmlString::capacity ( ) const [inline]

Definition at line 194 of file tinystr.h.

  {
    return rep_->capacity;
  }

Here is the caller graph for this function:

void TiXmlString::clear ( ) [inline]

Definition at line 233 of file tinystr.h.

  {
    //Lee:
    //The original was just too strange, though correct:
    // TiXmlString().swap(*this);
    //Instead use the quit & re-init:
    quit();
    init (0, 0);
  }

Here is the call graph for this function:

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

Definition at line 170 of file tinystr.h.

  {
    return rep_->str;
  }

Here is the caller graph for this function:

bool TiXmlString::empty ( ) const [inline]

Definition at line 188 of file tinystr.h.

  {
    return rep_->size == 0;
  }
size_type TiXmlString::find ( char  lookup) const [inline]

Definition at line 215 of file tinystr.h.

  {
    return find (lookup, 0);
  }
size_type TiXmlString::find ( char  tofind,
size_type  offset 
) const [inline]

Definition at line 221 of file tinystr.h.

  {
    if (offset >= length() ) return npos;

    for (const char *p = c_str() + offset; *p != '\0'; ++p)
    {
      if (*p == tofind) return static_cast< size_type > ( p - c_str() );
    }

    return npos;
  }

Here is the call graph for this function:

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

Definition at line 273 of file tinystr.h.

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

Here is the caller graph for this function:

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

Definition at line 261 of file tinystr.h.

  {
    init (sz, sz);
  }

Here is the caller graph for this function:

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

Definition at line 284 of file tinystr.h.

  {
    if (cap)
    {
      // Lee: the original form:
      //      rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
      // doesn't work in some cases of new being overloaded. Switching
      // to the normal allocation, although use an 'int' for systems
      // that are overly picky about structure alignment.
      const size_type bytesNeeded = sizeof (Rep) + cap;
      const size_type intsNeeded = ( bytesNeeded + sizeof (int) - 1 ) / sizeof ( int );
      rep_ = reinterpret_cast<Rep *> ( new int[ intsNeeded ] );

      rep_->str[ rep_->size = sz ] = '\0';
      rep_->capacity = cap;
    }
    else
    {
      rep_ = &nullrep_;
    }
  }
size_type TiXmlString::length ( ) const [inline]

Definition at line 176 of file tinystr.h.

  {
    return rep_->size;
  }

Here is the caller graph for this function:

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

Definition at line 145 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 151 of file tinystr.h.

  {
    return append (&single, 1);
  }

Here is the call graph for this function:

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

Definition at line 157 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 132 of file tinystr.h.

  {
    return assign ( copy, (size_type) strlen (copy) );
  }

Here is the call graph for this function:

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

Definition at line 138 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 208 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 306 of file tinystr.h.

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

Here is the caller graph for this function:

Definition at line 64 of file tinystr.cpp.

{
  if (cap > capacity() )
  {
    TiXmlString tmp;
    tmp.init (length(), cap);
    memcpy (tmp.start(), data(), length() );
    swap (tmp);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 265 of file tinystr.h.

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

Here is the caller graph for this function:

size_type TiXmlString::size ( ) const [inline]

Definition at line 182 of file tinystr.h.

  {
    return rep_->size;
  }
char* TiXmlString::start ( ) const [inline, private]

Definition at line 269 of file tinystr.h.

  {
    return rep_->str;
  }

Here is the caller graph for this function:

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

Definition at line 252 of file tinystr.h.

  {
    Rep *r = rep_;
    rep_ = other.rep_;
    other.rep_ = r;
  }

Here is the caller graph for this function:


Member Data Documentation

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

Definition at line 96 of file tinystr.h.

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

Definition at line 317 of file tinystr.h.

Rep* TiXmlString::rep_ [private]

Definition at line 316 of file tinystr.h.


The documentation for this class was generated from the following files: