osgEarth 2.1.1
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:
Collaboration diagram for TiXmlString:

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 67 of file tinystr.h.


Member Typedef Documentation

typedef size_t TiXmlString::size_type

Definition at line 71 of file tinystr.h.


Constructor & Destructor Documentation

TiXmlString::TiXmlString ( ) [inline]

Definition at line 78 of file tinystr.h.

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

Definition at line 83 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 90 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 97 of file tinystr.h.

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

Here is the call graph for this function:

TiXmlString::~TiXmlString ( ) [inline]

Definition at line 104 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 73 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 54 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 161 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 142 of file tinystr.h.

{ return rep_->str; }

Here is the caller graph for this function:

size_type TiXmlString::capacity ( ) const [inline]

Definition at line 157 of file tinystr.h.

{ return rep_->capacity; }

Here is the caller graph for this function:

void TiXmlString::clear ( ) [inline]

Definition at line 192 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 145 of file tinystr.h.

{ return rep_->str; }

Here is the caller graph for this function:

bool TiXmlString::empty ( ) const [inline]

Definition at line 154 of file tinystr.h.

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

Definition at line 175 of file tinystr.h.

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

Definition at line 181 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 223 of file tinystr.h.

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

Here is the caller graph for this function:

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

Definition at line 231 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_;
                }
        }
void TiXmlString::init ( size_type  sz) [inline, private]

Definition at line 220 of file tinystr.h.

{ init(sz, sz); }

Here is the call graph for this function:

Here is the caller graph for this function:

size_type TiXmlString::length ( ) const [inline]

Definition at line 148 of file tinystr.h.

{ return rep_->size; }

Here is the caller graph for this function:

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

Definition at line 129 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 135 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 123 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 116 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 110 of file tinystr.h.

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

Here is the call graph for this function:

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

Definition at line 168 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 253 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:

void TiXmlString::reserve ( size_type  cap)

Definition at line 42 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 221 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 151 of file tinystr.h.

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

Definition at line 222 of file tinystr.h.

{ return rep_->str; }

Here is the caller graph for this function:

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

Definition at line 211 of file tinystr.h.

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

Here is the caller graph for this function:


Member Data Documentation

Definition at line 74 of file tinystr.h.

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

Definition at line 264 of file tinystr.h.

Rep* TiXmlString::rep_ [private]

Definition at line 263 of file tinystr.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines