FEDRA emulsion software from the OPERA Collaboration
TiXmlString Class Reference

#include <tinystr.h>

Inheritance diagram for TiXmlString:
Collaboration diagram for TiXmlString:

Classes

struct  Rep
 

Public Types

typedef size_t size_type
 

Public Member Functions

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

Static Public Attributes

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

Private Member Functions

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

Private Attributes

Reprep_
 

Static Private Attributes

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

Member Typedef Documentation

◆ size_type

typedef size_t TiXmlString::size_type

Constructor & Destructor Documentation

◆ TiXmlString() [1/4]

TiXmlString::TiXmlString ( )
inline
66 : rep_(&nullrep_)
67 {
68 }
Rep * rep_
Definition: tinystr.h:249
static Rep nullrep_
Definition: tinystr.h:250

◆ TiXmlString() [2/4]

TiXmlString::TiXmlString ( const TiXmlString copy)
inline
71 : rep_(0)
72 {
73 init(copy.length());
74 memcpy(start(), copy.data(), length());
75 }
const char * data() const
Definition: tinystr.h:131
size_type length() const
Definition: tinystr.h:134
void init(size_type sz)
Definition: tinystr.h:206
char * start() const
Definition: tinystr.h:208

◆ TiXmlString() [3/4]

TIXML_EXPLICIT TiXmlString::TiXmlString ( const char *  copy)
inline
78 : rep_(0)
79 {
80 init( static_cast<size_type>( strlen(copy) ));
81 memcpy(start(), copy, length());
82 }
size_t size_type
Definition: tinystr.h:59

◆ TiXmlString() [4/4]

TIXML_EXPLICIT TiXmlString::TiXmlString ( const char *  str,
size_type  len 
)
inline
85 : rep_(0)
86 {
87 init(len);
88 memcpy(start(), str, len);
89 }

◆ ~TiXmlString()

TiXmlString::~TiXmlString ( )
inline
93 {
94 quit();
95 }
void quit()
Definition: tinystr.h:239

Member Function Documentation

◆ append()

TiXmlString & TiXmlString::append ( const char *  str,
size_type  len 
)
69{
70 size_type newsize = length() + len;
71 if (newsize > capacity())
72 {
73 reserve (newsize + capacity());
74 }
75 memmove(finish(), str, len);
76 set_size(newsize);
77 return *this;
78}
size_type capacity() const
Definition: tinystr.h:143
void set_size(size_type sz)
Definition: tinystr.h:207
void reserve(size_type cap)
Definition: tinystr.cpp:37
char * finish() const
Definition: tinystr.h:209

◆ assign()

TiXmlString & TiXmlString::assign ( const char *  str,
size_type  len 
)
50{
51 size_type cap = capacity();
52 if (len > cap || cap > 3*(len + 8))
53 {
54 TiXmlString tmp;
55 tmp.init(len);
56 memcpy(tmp.start(), str, len);
57 swap(tmp);
58 }
59 else
60 {
61 memmove(start(), str, len);
62 set_size(len);
63 }
64 return *this;
65}
Definition: tinystr.h:56
void swap(TiXmlString &other)
Definition: tinystr.h:197

◆ at()

const char & TiXmlString::at ( size_type  index) const
inline
148 {
149 assert( index < length() );
150 return rep_->str[ index ];
151 }
char str[1]
Definition: tinystr.h:214

◆ c_str()

const char * TiXmlString::c_str ( ) const
inline
128{ return rep_->str; }

◆ capacity()

size_type TiXmlString::capacity ( ) const
inline
143{ return rep_->capacity; }
size_type capacity
Definition: tinystr.h:213

◆ clear()

void TiXmlString::clear ( )
inline
179 {
180 //Lee:
181 //The original was just too strange, though correct:
182 // TiXmlString().swap(*this);
183 //Instead use the quit & re-init:
184 quit();
185 init(0,0);
186 }

◆ data()

const char * TiXmlString::data ( ) const
inline
131{ return rep_->str; }

◆ empty()

bool TiXmlString::empty ( ) const
inline
140{ return rep_->size == 0; }
size_type size
Definition: tinystr.h:213

◆ find() [1/2]

size_type TiXmlString::find ( char  lookup) const
inline
162 {
163 return find(lookup, 0);
164 }
size_type find(char lookup) const
Definition: tinystr.h:161

◆ find() [2/2]

size_type TiXmlString::find ( char  tofind,
size_type  offset 
) const
inline
168 {
169 if (offset >= length()) return npos;
170
171 for (const char* p = c_str() + offset; *p != '\0'; ++p)
172 {
173 if (*p == tofind) return static_cast< size_type >( p - c_str() );
174 }
175 return npos;
176 }
const char * c_str() const
Definition: tinystr.h:128
static const size_type npos
Definition: tinystr.h:62
p
Definition: testBGReduction_AllMethods.C:8

◆ finish()

char * TiXmlString::finish ( ) const
inlineprivate
209{ return rep_->str + rep_->size; }

◆ init() [1/2]

void TiXmlString::init ( size_type  sz)
inlineprivate
206{ init(sz, sz); }

◆ init() [2/2]

void TiXmlString::init ( size_type  sz,
size_type  cap 
)
inlineprivate
218 {
219 if (cap)
220 {
221 // Lee: the original form:
222 // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
223 // doesn't work in some cases of new being overloaded. Switching
224 // to the normal allocation, although use an 'int' for systems
225 // that are overly picky about structure alignment.
226 const size_type bytesNeeded = sizeof(Rep) + cap;
227 const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int );
228 rep_ = reinterpret_cast<Rep*>( new int[ intsNeeded ] );
229
230 rep_->str[ rep_->size = sz ] = '\0';
231 rep_->capacity = cap;
232 }
233 else
234 {
235 rep_ = &nullrep_;
236 }
237 }

◆ length()

size_type TiXmlString::length ( ) const
inline
134{ return rep_->size; }

◆ operator+=() [1/3]

TiXmlString & TiXmlString::operator+= ( char  single)
inline
116 {
117 return append(&single, 1);
118 }
TiXmlString & append(const char *str, size_type len)
Definition: tinystr.cpp:68

◆ operator+=() [2/3]

TiXmlString & TiXmlString::operator+= ( const char *  suffix)
inline
110 {
111 return append(suffix, static_cast<size_type>( strlen(suffix) ));
112 }

◆ operator+=() [3/3]

TiXmlString & TiXmlString::operator+= ( const TiXmlString suffix)
inline
122 {
123 return append(suffix.data(), suffix.length());
124 }

◆ operator=() [1/2]

TiXmlString & TiXmlString::operator= ( const char *  copy)
inline
98 {
99 return assign( copy, (size_type)strlen(copy));
100 }
TiXmlString & assign(const char *str, size_type len)
Definition: tinystr.cpp:49

◆ operator=() [2/2]

TiXmlString & TiXmlString::operator= ( const TiXmlString copy)
inline
103 {
104 return assign(copy.start(), copy.length());
105 }

◆ operator[]()

char & TiXmlString::operator[] ( size_type  index) const
inline
155 {
156 assert( index < length() );
157 return rep_->str[ index ];
158 }

◆ quit()

void TiXmlString::quit ( )
inlineprivate
240 {
241 if (rep_ != &nullrep_)
242 {
243 // The rep_ is really an array of ints. (see the allocator, above).
244 // Cast it back before delete, so the compiler won't incorrectly call destructors.
245 delete [] ( reinterpret_cast<int*>( rep_ ) );
246 }
247 }

◆ reserve()

void TiXmlString::reserve ( size_type  cap)
38{
39 if (cap > capacity())
40 {
41 TiXmlString tmp;
42 tmp.init(length(), cap);
43 memcpy(tmp.start(), data(), length());
44 swap(tmp);
45 }
46}

◆ set_size()

void TiXmlString::set_size ( size_type  sz)
inlineprivate
207{ rep_->str[ rep_->size = sz ] = '\0'; }

◆ size()

size_type TiXmlString::size ( ) const
inline
137{ return rep_->size; }

◆ start()

char * TiXmlString::start ( ) const
inlineprivate
208{ return rep_->str; }

◆ swap()

void TiXmlString::swap ( TiXmlString other)
inline
198 {
199 Rep* r = rep_;
200 rep_ = other.rep_;
201 other.rep_ = r;
202 }
void r(int rid=2)
Definition: test.C:201

Member Data Documentation

◆ npos

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

◆ nullrep_

TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }
staticprivate

◆ rep_

Rep* TiXmlString::rep_
private

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