tinystr.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens do nov 2 13:06:02 CET 2006 tinystr.cpp
3 
4  tinystr.cpp - description
5  -------------------
6  begin : do november 02 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@gmail.com
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 /*
40 www.sourceforge.net/projects/tinyxml
41 Original file by Yves Berquin.
42 
43 This software is provided 'as-is', without any express or implied
44 warranty. In no event will the authors be held liable for any
45 damages arising from the use of this software.
46 
47 Permission is granted to anyone to use this software for any
48 purpose, including commercial applications, and to alter it and
49 redistribute it freely, subject to the following restrictions:
50 
51 1. The origin of this software must not be misrepresented; you must
52 not claim that you wrote the original software. If you use this
53 software in a product, an acknowledgment in the product documentation
54 would be appreciated but is not required.
55 
56 2. Altered source versions must be plainly marked as such, and
57 must not be misrepresented as being the original software.
58 
59 3. This notice may not be removed or altered from any source
60 distribution.
61 */
62 
63 /*
64  * THIS FILE WAS ALTERED BY Tyge LÝvset, 7. April 2005.
65  */
66 
67 
68 #ifndef TIXML_USE_STL
69 
70 #include "tinystr.h"
71 
72 namespace RTT { namespace marsh {
73 
74 // Error value for find primitive
75 const TiXmlString::size_type TiXmlString::npos = static_cast< size_type >(-1);
76 
77 // Null rep.
78 TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } };
79 
80 
82 {
83  if (cap > capacity())
84  {
85  TiXmlString tmp;
86  tmp.init(length(), cap);
87  memcpy(tmp.start(), data(), length());
88  swap(tmp);
89  }
90 }
91 
92 
94 {
95  size_type cap = capacity();
96  if (len > cap || cap > 3*(len + 8))
97  {
98  TiXmlString tmp;
99  tmp.init(len);
100  memcpy(tmp.start(), str, len);
101  swap(tmp);
102  }
103  else
104  {
105  memmove(start(), str, len);
106  set_size(len);
107  }
108  return *this;
109 }
110 
111 
113 {
114  size_type newsize = length() + len;
115  if (newsize > capacity())
116  {
117  reserve (newsize + capacity());
118  }
119  memmove(finish(), str, len);
120  set_size(newsize);
121  return *this;
122 }
123 
124 
126 {
127  TiXmlString tmp;
128  tmp.reserve(a.length() + b.length());
129  tmp += a;
130  tmp += b;
131  return tmp;
132 }
133 
134 TiXmlString operator + (const TiXmlString & a, const char* b)
135 {
136  TiXmlString tmp;
137  TiXmlString::size_type b_len = static_cast<TiXmlString::size_type>( strlen(b) );
138  tmp.reserve(a.length() + b_len);
139  tmp += a;
140  tmp.append(b, b_len);
141  return tmp;
142 }
143 
144 TiXmlString operator + (const char* a, const TiXmlString & b)
145 {
146  TiXmlString tmp;
147  TiXmlString::size_type a_len = static_cast<TiXmlString::size_type>( strlen(a) );
148  tmp.reserve(a_len + b.length());
149  tmp.append(a, a_len);
150  tmp += b;
151  return tmp;
152 }
153 
154 }}
155 
156 #endif // TIXML_USE_STL
void swap(TiXmlString &other)
Definition: tinystr.h:250
const char * data() const
Definition: tinystr.h:184
size_type capacity() const
Definition: tinystr.h:196
TiXmlString operator+(const TiXmlString &a, const TiXmlString &b)
Definition: tinystr.cpp:125
char * start() const
Definition: tinystr.h:261
void set_size(size_type sz)
Definition: tinystr.h:260
size_type length() const
Definition: tinystr.h:187
TiXmlString & append(const char *str, size_type len)
Definition: tinystr.cpp:112
static Rep nullrep_
Definition: tinystr.h:303
void init(size_type sz)
Definition: tinystr.h:259
void reserve(size_type cap)
Definition: tinystr.cpp:81
char * finish() const
Definition: tinystr.h:262
static const size_type npos
Definition: tinystr.h:113
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
TiXmlString & assign(const char *str, size_type len)
Definition: tinystr.cpp:93


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:37