aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
TiXmlString Class Reference

#include <tinystr.h>

+ Inheritance diagram for TiXmlString:
+ Collaboration diagram for TiXmlString:

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
 

Public Types

typedef size_t size_type
 

Classes

struct  Rep
 

Detailed Description

Definition at line 71 of file tinystr.h.

Member Typedef Documentation

◆ size_type

typedef size_t TiXmlString::size_type

Definition at line 74 of file tinystr.h.

Constructor & Destructor Documentation

◆ TiXmlString() [1/4]

TiXmlString::TiXmlString ( )
inline

Definition at line 80 of file tinystr.h.

References nullrep_, and rep_.

81  : rep_(&nullrep_) {}
Rep * rep_
Definition: tinystr.h:239
static Rep nullrep_
Definition: tinystr.h:240

◆ TiXmlString() [2/4]

TiXmlString::TiXmlString ( const TiXmlString copy)
inline

Definition at line 84 of file tinystr.h.

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

85  : rep_(0) {
86  init(copy.length());
87  memcpy(start(), copy.data(), length());
88  }
Rep * rep_
Definition: tinystr.h:239
void init(size_type sz)
Definition: tinystr.h:202
char * start() const
Definition: tinystr.h:204
size_type length() const
Definition: tinystr.h:137
const char * data() const
Definition: tinystr.h:134
+ Here is the call graph for this function:

◆ TiXmlString() [3/4]

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

Definition at line 91 of file tinystr.h.

References rep_.

92  : rep_(0) {
93  init(static_cast< size_type >(strlen(copy)));
94  memcpy(start(), copy, length());
95  }
Rep * rep_
Definition: tinystr.h:239
void init(size_type sz)
Definition: tinystr.h:202
char * start() const
Definition: tinystr.h:204
size_type length() const
Definition: tinystr.h:137

◆ TiXmlString() [4/4]

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

Definition at line 98 of file tinystr.h.

References init(), and rep_.

99  : rep_(0) {
100  init(len);
101  memcpy(start(), str, len);
102  }
Rep * rep_
Definition: tinystr.h:239
void init(size_type sz)
Definition: tinystr.h:202
char * start() const
Definition: tinystr.h:204
+ Here is the call graph for this function:

◆ ~TiXmlString()

TiXmlString::~TiXmlString ( )
inline

Definition at line 105 of file tinystr.h.

References quit().

105 { quit(); }
void quit()
Definition: tinystr.h:230
+ Here is the call graph for this function:

Member Function Documentation

◆ append()

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

Definition at line 65 of file tinystr.cpp.

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

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

65  {
66  size_type newsize = length() + len;
67 
68  if (newsize > capacity()) {
69  reserve(newsize + capacity());
70  }
71 
72  memmove(finish(), str, len);
73  set_size(newsize);
74  return *this;
75 }
size_type capacity() const
Definition: tinystr.h:146
void reserve(size_type cap)
Definition: tinystr.cpp:40
void set_size(size_type sz)
Definition: tinystr.h:203
size_t size_type
Definition: tinystr.h:74
size_type length() const
Definition: tinystr.h:137
char * finish() const
Definition: tinystr.h:205
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ assign()

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

Definition at line 49 of file tinystr.cpp.

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

Referenced by operator=().

49  {
50  size_type cap = capacity();
51 
52  if (len > cap || cap > 3 * (len + 8)) {
53  TiXmlString tmp;
54  tmp.init(len);
55  memcpy(tmp.start(), str, len);
56  swap(tmp);
57  } else {
58  memmove(start(), str, len);
59  set_size(len);
60  }
61 
62  return *this;
63 }
void swap(TiXmlString &other)
Definition: tinystr.h:195
size_type capacity() const
Definition: tinystr.h:146
void init(size_type sz)
Definition: tinystr.h:202
void set_size(size_type sz)
Definition: tinystr.h:203
char * start() const
Definition: tinystr.h:204
size_t size_type
Definition: tinystr.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ at()

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

Definition at line 149 of file tinystr.h.

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

149  {
150  assert(index < length());
151  return rep_->str[index];
152  }
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
size_type length() const
Definition: tinystr.h:137
+ Here is the call graph for this function:

◆ c_str()

const char* TiXmlString::c_str ( ) const
inline

Definition at line 131 of file tinystr.h.

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

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

131 { return rep_->str; }
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
+ Here is the caller graph for this function:

◆ capacity()

size_type TiXmlString::capacity ( ) const
inline

Definition at line 146 of file tinystr.h.

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

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

146 { return rep_->capacity; }
Rep * rep_
Definition: tinystr.h:239
size_type capacity
Definition: tinystr.h:208
+ Here is the caller graph for this function:

◆ clear()

void TiXmlString::clear ( )
inline

Definition at line 175 of file tinystr.h.

References init(), and quit().

175  {
176  // Lee:
177  // The original was just too strange, though correct:
178  // TiXmlString().replace(*this);
179  // Instead use the quit & re-init:
180  quit();
181  init(0, 0);
182  }
void quit()
Definition: tinystr.h:230
void init(size_type sz)
Definition: tinystr.h:202
+ Here is the call graph for this function:

◆ data()

const char* TiXmlString::data ( ) const
inline

Definition at line 134 of file tinystr.h.

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

Referenced by operator+=().

134 { return rep_->str; }
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
+ Here is the caller graph for this function:

◆ empty()

bool TiXmlString::empty ( ) const
inline

Definition at line 143 of file tinystr.h.

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

143 { return rep_->size == 0; }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239

◆ find() [1/2]

size_type TiXmlString::find ( char  lookup) const
inline

Definition at line 161 of file tinystr.h.

References find().

161 { return find(lookup, 0); }
size_type find(char lookup) const
Definition: tinystr.h:161
+ Here is the call graph for this function:

◆ find() [2/2]

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

Definition at line 165 of file tinystr.h.

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

Referenced by find().

165  {
166  if (offset >= length()) return npos;
167 
168  for (const char* p = c_str() + offset; *p != '\0'; ++p) {
169  if (*p == tofind) return static_cast< size_type >(p - c_str());
170  }
171 
172  return npos;
173  }
static const size_type npos
Definition: tinystr.h:77
size_t size_type
Definition: tinystr.h:74
size_type length() const
Definition: tinystr.h:137
const char * c_str() const
Definition: tinystr.h:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ finish()

char* TiXmlString::finish ( ) const
inlineprivate

Definition at line 205 of file tinystr.h.

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

205 { return rep_->str + rep_->size; }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209

◆ init() [1/2]

void TiXmlString::init ( size_type  sz)
inlineprivate

Definition at line 202 of file tinystr.h.

References init().

Referenced by assign(), and TiXmlString().

202 { init(sz, sz); }
void init(size_type sz)
Definition: tinystr.h:202
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [2/2]

void TiXmlString::init ( size_type  sz,
size_type  cap 
)
inlineprivate

Definition at line 212 of file tinystr.h.

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

Referenced by clear(), init(), and reserve().

212  {
213  if (cap) {
214  // Lee: the original form:
215  // rep_ = static_cast<Rep*>(operator new(sizeof(Rep) + cap));
216  // doesn't work in some cases of new being overloaded. Switching
217  // to the normal allocation, although use an 'int' for systems
218  // that are overly picky about structure alignment.
219  const size_type bytesNeeded = sizeof(Rep) + cap;
220  const size_type intsNeeded = (bytesNeeded + sizeof(int) - 1) / sizeof(int);
221  rep_ = reinterpret_cast< Rep* >(new int[intsNeeded]);
222 
223  rep_->str[rep_->size = sz] = '\0';
224  rep_->capacity = cap;
225  } else {
226  rep_ = &nullrep_;
227  }
228  }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
size_type capacity
Definition: tinystr.h:208
size_t size_type
Definition: tinystr.h:74
static Rep nullrep_
Definition: tinystr.h:240
+ Here is the caller graph for this function:

◆ length()

size_type TiXmlString::length ( ) const
inline

Definition at line 137 of file tinystr.h.

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

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

137 { return rep_->size; }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239
+ Here is the caller graph for this function:

◆ operator+=() [1/3]

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

Definition at line 118 of file tinystr.h.

Referenced by TiXmlOutStream::operator<<().

118  {
119  return append(suffix, static_cast< size_type >(strlen(suffix)));
120  }
TiXmlString & append(const char *str, size_type len)
Definition: tinystr.cpp:65
+ Here is the caller graph for this function:

◆ operator+=() [2/3]

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

Definition at line 123 of file tinystr.h.

References append().

123 { return append(&single, 1); }
TiXmlString & append(const char *str, size_type len)
Definition: tinystr.cpp:65
+ Here is the call graph for this function:

◆ operator+=() [3/3]

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

Definition at line 126 of file tinystr.h.

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

Referenced by operator+(), and TiXmlOutStream::operator<<().

126  {
127  return append(suffix.data(), suffix.length());
128  }
size_type length() const
Definition: tinystr.h:137
TiXmlString & append(const char *str, size_type len)
Definition: tinystr.cpp:65
const char * data() const
Definition: tinystr.h:134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ operator=() [1/2]

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

Definition at line 108 of file tinystr.h.

108  {
109  return assign(copy, (size_type)strlen(copy));
110  }
TiXmlString & assign(const char *str, size_type len)
Definition: tinystr.cpp:49
size_t size_type
Definition: tinystr.h:74

◆ operator=() [2/2]

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

Definition at line 113 of file tinystr.h.

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

113  {
114  return assign(copy.start(), copy.length());
115  }
TiXmlString & assign(const char *str, size_type len)
Definition: tinystr.cpp:49
char * start() const
Definition: tinystr.h:204
size_type length() const
Definition: tinystr.h:137
+ Here is the call graph for this function:

◆ operator[]()

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

Definition at line 155 of file tinystr.h.

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

155  {
156  assert(index < length());
157  return rep_->str[index];
158  }
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
size_type length() const
Definition: tinystr.h:137
+ Here is the call graph for this function:

◆ quit()

void TiXmlString::quit ( )
inlineprivate

Definition at line 230 of file tinystr.h.

References nullrep_, and rep_.

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

230  {
231  if (rep_ != &nullrep_) {
232  // The rep_ is really an array of ints. (see the allocator, above).
233  // Cast it back before delete, so the compiler won't incorrectly call
234  // destructors.
235  delete[](reinterpret_cast< int* >(rep_));
236  }
237  }
Rep * rep_
Definition: tinystr.h:239
static Rep nullrep_
Definition: tinystr.h:240
+ Here is the caller graph for this function:

◆ reserve()

void TiXmlString::reserve ( size_type  cap)

Definition at line 40 of file tinystr.cpp.

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

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

40  {
41  if (cap > capacity()) {
42  TiXmlString tmp;
43  tmp.init(length(), cap);
44  memcpy(tmp.start(), data(), length());
45  swap(tmp);
46  }
47 }
void swap(TiXmlString &other)
Definition: tinystr.h:195
size_type capacity() const
Definition: tinystr.h:146
void init(size_type sz)
Definition: tinystr.h:202
char * start() const
Definition: tinystr.h:204
size_type length() const
Definition: tinystr.h:137
const char * data() const
Definition: tinystr.h:134
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ set_size()

void TiXmlString::set_size ( size_type  sz)
inlineprivate

Definition at line 203 of file tinystr.h.

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

Referenced by append(), and assign().

203 { rep_->str[rep_->size = sz] = '\0'; }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
+ Here is the caller graph for this function:

◆ size()

size_type TiXmlString::size ( ) const
inline

Definition at line 140 of file tinystr.h.

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

140 { return rep_->size; }
size_type size
Definition: tinystr.h:208
Rep * rep_
Definition: tinystr.h:239

◆ start()

char* TiXmlString::start ( ) const
inlineprivate

Definition at line 204 of file tinystr.h.

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

Referenced by operator=().

204 { return rep_->str; }
Rep * rep_
Definition: tinystr.h:239
char str[1]
Definition: tinystr.h:209
+ Here is the caller graph for this function:

◆ swap()

void TiXmlString::swap ( TiXmlString other)
inline

Definition at line 195 of file tinystr.h.

References rep_.

Referenced by assign(), and reserve().

195  {
196  Rep* r = rep_;
197  rep_ = other.rep_;
198  other.rep_ = r;
199  }
Rep * rep_
Definition: tinystr.h:239
+ Here is the caller graph for this function:

Member Data Documentation

◆ npos

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

Definition at line 77 of file tinystr.h.

Referenced by find().

◆ nullrep_

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

Definition at line 240 of file tinystr.h.

Referenced by init(), quit(), and TiXmlString().

◆ rep_

Rep* TiXmlString::rep_
private

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