aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
tinystr.cpp
Go to the documentation of this file.
1/*
2www.sourceforge.net/projects/tinyxml
3Original file by Yves Berquin.
4
5This software is provided 'as-is', without any express or implied
6warranty. In no event will the authors be held liable for any
7damages arising from the use of this software.
8
9Permission is granted to anyone to use this software for any
10purpose, including commercial applications, and to alter it and
11redistribute it freely, subject to the following restrictions:
12
131. The origin of this software must not be misrepresented; you must
14not claim that you wrote the original software. If you use this
15software in a product, an acknowledgment in the product documentation
16would be appreciated but is not required.
17
182. Altered source versions must be plainly marked as such, and
19must not be misrepresented as being the original software.
20
213. This notice may not be removed or altered from any source
22distribution.
23*/
24
25/*
26 * THIS FILE WAS ALTERED BY Tyge L�vset, 7. April 2005.
27 */
28
29#ifndef TIXML_USE_STL
30
31#include "tinystr.h"
32
33// Error value for find primitive
35 static_cast< TiXmlString::size_type >(-1);
36
37// Null rep.
39
41 if (cap > capacity()) {
42 TiXmlString tmp;
43 tmp.init(length(), cap);
44 memcpy(tmp.start(), data(), length());
45 swap(tmp);
46 }
47}
48
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}
64
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}
76
78 TiXmlString tmp;
79 tmp.reserve(a.length() + b.length());
80 tmp += a;
81 tmp += b;
82 return tmp;
83}
84
85TiXmlString operator+(const TiXmlString& a, const char* b) {
86 TiXmlString tmp;
87 TiXmlString::size_type b_len = static_cast< TiXmlString::size_type >(strlen(b));
88 tmp.reserve(a.length() + b_len);
89 tmp += a;
90 tmp.append(b, b_len);
91 return tmp;
92}
93
94TiXmlString operator+(const char* a, const TiXmlString& b) {
95 TiXmlString tmp;
96 TiXmlString::size_type a_len = static_cast< TiXmlString::size_type >(strlen(a));
97 tmp.reserve(a_len + b.length());
98 tmp.append(a, a_len);
99 tmp += b;
100 return tmp;
101}
102
103#endif // TIXML_USE_STL
size_type capacity() const
Definition tinystr.h:146
const char * data() const
Definition tinystr.h:134
TiXmlString()
Definition tinystr.h:80
void set_size(size_type sz)
Definition tinystr.h:203
size_type length() const
Definition tinystr.h:137
void init(size_type sz)
Definition tinystr.h:202
char * start() const
Definition tinystr.h:204
void reserve(size_type cap)
Definition tinystr.cpp:40
static const size_type npos
Definition tinystr.h:77
void swap(TiXmlString &other)
Definition tinystr.h:195
size_t size_type
Definition tinystr.h:74
TiXmlString & assign(const char *str, size_type len)
Definition tinystr.cpp:49
TiXmlString & append(const char *str, size_type len)
Definition tinystr.cpp:65
char * finish() const
Definition tinystr.h:205
static Rep nullrep_
Definition tinystr.h:38
TiXmlString operator+(const TiXmlString &a, const TiXmlString &b)
Definition tinystr.cpp:77