aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2019-05-25 00:19:04 -0700
committerMike Buland <eichlan@xagasoft.com>2019-05-25 00:19:04 -0700
commit00cef0e9a21e1ee07d622bb05c3a7e4e56425723 (patch)
tree334088b2827237b6bc19ba66f926f2e3d90d2e69 /src
parentffa9751b84ba615c8f6efbc6b88c9016d333f8d2 (diff)
downloadlibbu++-00cef0e9a21e1ee07d622bb05c3a7e4e56425723.tar.gz
libbu++-00cef0e9a21e1ee07d622bb05c3a7e4e56425723.tar.bz2
libbu++-00cef0e9a21e1ee07d622bb05c3a7e4e56425723.tar.xz
libbu++-00cef0e9a21e1ee07d622bb05c3a7e4e56425723.zip
Started Bu::Text and Bu::Blob.
These will someday replace Bu::String and Bu::UtfString. The plan is to support more encodings in the Text class than just Unicode, Blob and Text will not be shared core, but the Builders will be, making Text and Blob objects much safer in multi-threaded programs.
Diffstat (limited to 'src')
-rw-r--r--src/stable/exceptioninvaliditerator.cpp14
-rw-r--r--src/stable/exceptioninvaliditerator.h18
-rw-r--r--src/unstable/blob.cpp403
-rw-r--r--src/unstable/blob.h125
-rw-r--r--src/unstable/blobbuilder.cpp8
-rw-r--r--src/unstable/blobbuilder.h8
-rw-r--r--src/unstable/text.cpp8
-rw-r--r--src/unstable/text.h0
-rw-r--r--src/unstable/textbuilder.cpp8
-rw-r--r--src/unstable/textbuilder.h8
10 files changed, 600 insertions, 0 deletions
diff --git a/src/stable/exceptioninvaliditerator.cpp b/src/stable/exceptioninvaliditerator.cpp
new file mode 100644
index 0000000..8cd9061
--- /dev/null
+++ b/src/stable/exceptioninvaliditerator.cpp
@@ -0,0 +1,14 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/exceptioninvaliditerator.h"
9
10namespace Bu
11{
12 subExceptionDef( ExceptionInvalidIterator );
13}
14
diff --git a/src/stable/exceptioninvaliditerator.h b/src/stable/exceptioninvaliditerator.h
new file mode 100644
index 0000000..a157553
--- /dev/null
+++ b/src/stable/exceptioninvaliditerator.h
@@ -0,0 +1,18 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_EXCEPTION_INVALID_ITERATOR_H
9#define BU_EXCEPTION_INVALID_ITERATOR_H
10
11#include "exceptionbase.h"
12
13namespace Bu
14{
15 subExceptionDecl( ExceptionInvalidIterator );
16}
17
18#endif
diff --git a/src/unstable/blob.cpp b/src/unstable/blob.cpp
new file mode 100644
index 0000000..51a3b93
--- /dev/null
+++ b/src/unstable/blob.cpp
@@ -0,0 +1,403 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/blob.h"
9#include "bu/exceptioninvaliditerator.h"
10
11#include <string.h>
12
13Bu::Blob::Blob() :
14 pData( 0 ),
15 iSize( -1 )
16{
17}
18
19Bu::Blob::Blob( const Bu::Blob &rSrc ) :
20 pData( 0 ),
21 iSize( rSrc.iSize )
22{
23 pData = new char[rSrc.iSize+1];
24 memcpy( pData, rSrc.pData, iSize+1 );
25}
26
27Bu::Blob::Blob( const char *pSrc ) :
28 pData( 0 ),
29 iSize( 0 )
30{
31 for(; iSize < __INT_MAX__ && pSrc[iSize]; iSize++ ) { }
32 pData = new char[iSize+1];
33 memcpy( pData, pSrc, iSize+1 );
34}
35
36Bu::Blob::Blob( const void *pSrc, int32_t iSize )
37{
38 this->iSize = iSize;
39 pData = new char[iSize+1];
40 memcpy( pData, pSrc, iSize );
41 pData[iSize] = '\0';
42}
43
44Bu::Blob::~Blob()
45{
46 delete[] pData;
47 pData = 0;
48 iSize = -1;
49}
50
51int32_t Bu::Blob::getSize() const
52{
53 return iSize;
54}
55
56char *Bu::Blob::getData() const
57{
58 return pData;
59}
60
61char *Bu::Blob::c_str() const
62{
63 return pData;
64}
65
66Bu::Blob &Bu::Blob::operator=( const Bu::Blob &rRhs )
67{
68 delete[] pData;
69
70 iSize = rRhs.iSize;
71 pData = new char[iSize+1];
72 memcpy( pData, rRhs.pData, iSize+1 );
73
74 return *this;
75}
76
77Bu::Blob &Bu::Blob::operator=( const char *pRhs )
78{
79 delete[] pData;
80
81 for(iSize = 0; iSize < __INT_MAX__ && pRhs[iSize]; iSize++ ) { }
82 pData = new char[iSize+1];
83 memcpy( pData, pRhs, iSize+1 );
84
85 return *this;
86}
87
88Bu::Blob::iterator::iterator( Bu::Blob *pBlob, bool bForward ) :
89 pBlob( pBlob ),
90 iIndex( bForward?0:pBlob->iSize-1 ),
91 bForward( bForward )
92{
93}
94
95Bu::Blob::iterator::iterator() :
96 pBlob( NULL ),
97 iIndex( -1 ),
98 bForward( true )
99{
100}
101
102Bu::Blob::iterator::iterator( const Bu::Blob::iterator &rSrc ) :
103 pBlob( rSrc.pBlob ),
104 iIndex( rSrc.iIndex ),
105 bForward( rSrc.bForward )
106{
107}
108
109bool Bu::Blob::iterator::isValid() const
110{
111 if( !pBlob )
112 return false;
113
114 if( iIndex < 0 || iIndex >= pBlob->iSize )
115 return false;
116
117 return true;
118}
119
120Bu::Blob::iterator::operator bool() const
121{
122 return isValid();
123}
124
125char &Bu::Blob::iterator::operator *()
126{
127 if( !isValid() )
128 throw Bu::ExceptionInvalidIterator();
129
130 return pBlob->pData[iIndex];
131}
132
133Bu::Blob::iterator &Bu::Blob::iterator::operator++( int )
134{
135 if( bForward )
136 ++iIndex;
137 else
138 --iIndex;
139
140 return *this;
141}
142
143Bu::Blob::iterator &Bu::Blob::iterator::operator++()
144{
145 if( bForward )
146 ++iIndex;
147 else
148 --iIndex;
149
150 return *this;
151}
152
153Bu::Blob::iterator &Bu::Blob::iterator::operator--( int )
154{
155 if( bForward )
156 --iIndex;
157 else
158 ++iIndex;
159
160 return *this;
161}
162
163Bu::Blob::iterator &Bu::Blob::iterator::operator--()
164{
165 if( bForward )
166 --iIndex;
167 else
168 ++iIndex;
169
170 return *this;
171}
172
173bool Bu::Blob::iterator::operator==( const Bu::Blob::iterator &rRhs )
174{
175 if( isValid() == false && rRhs.isValid() == false )
176 return true;
177
178 return pBlob == rRhs.pBlob && iIndex == rRhs.iIndex;
179}
180
181bool Bu::Blob::iterator::operator==( const Bu::Blob::const_iterator &rRhs )
182{
183 if( isValid() == false && rRhs.isValid() == false )
184 return true;
185
186 return pBlob == rRhs.pBlob && iIndex == rRhs.iIndex;
187}
188
189bool Bu::Blob::iterator::operator!=( const Bu::Blob::iterator &rRhs )
190{
191 if( isValid() != rRhs.isValid() )
192 return true;
193
194 return pBlob != rRhs.pBlob || iIndex != rRhs.iIndex;
195}
196
197bool Bu::Blob::iterator::operator!=( const Bu::Blob::const_iterator &rRhs )
198{
199 if( isValid() != rRhs.isValid() )
200 return true;
201
202 return pBlob != rRhs.pBlob || iIndex != rRhs.iIndex;
203}
204
205Bu::Blob::iterator &Bu::Blob::iterator::operator=( Bu::Blob::iterator &rRhs )
206{
207 pBlob = rRhs.pBlob;
208 iIndex = rRhs.iIndex;
209 bForward = rRhs.bForward;
210
211 return *this;
212}
213
214
215Bu::Blob::const_iterator::const_iterator( const Blob *pBlob, bool bForward ) :
216 pBlob( pBlob ),
217 iIndex( bForward?0:pBlob->iSize-1 ),
218 bForward( bForward )
219{
220}
221
222Bu::Blob::const_iterator::const_iterator() :
223 pBlob( NULL ),
224 iIndex( -1 ),
225 bForward( true )
226{
227}
228
229Bu::Blob::const_iterator::const_iterator(
230 const Bu::Blob::const_iterator &rSrc ) :
231 pBlob( rSrc.pBlob ),
232 iIndex( rSrc.iIndex ),
233 bForward( rSrc.bForward )
234{
235}
236
237Bu::Blob::const_iterator::const_iterator( const Bu::Blob::iterator &rSrc ) :
238 pBlob( rSrc.pBlob ),
239 iIndex( rSrc.iIndex ),
240 bForward( rSrc.bForward )
241{
242}
243
244bool Bu::Blob::const_iterator::isValid() const
245{
246 if( !pBlob )
247 return false;
248
249 if( iIndex < 0 || iIndex >= pBlob->iSize )
250 return false;
251
252 return true;
253}
254
255Bu::Blob::const_iterator::operator bool() const
256{
257 return isValid();
258}
259
260char Bu::Blob::const_iterator::operator *() const
261{
262 if( !isValid() )
263 throw Bu::ExceptionInvalidIterator();
264
265 return pBlob->pData[iIndex];
266}
267
268Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator++( int )
269{
270 if( bForward )
271 ++iIndex;
272 else
273 --iIndex;
274
275 return *this;
276}
277
278Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator++()
279{
280 if( bForward )
281 ++iIndex;
282 else
283 --iIndex;
284
285 return *this;
286}
287
288Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator--( int )
289{
290 if( bForward )
291 ++iIndex;
292 else
293 --iIndex;
294
295 return *this;
296}
297
298Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator--()
299{
300 if( bForward )
301 ++iIndex;
302 else
303 --iIndex;
304
305 return *this;
306}
307
308bool Bu::Blob::const_iterator::operator==( const Bu::Blob::iterator &rRhs )
309{
310 if( isValid() == false && rRhs.isValid() == false )
311 return true;
312
313 return pBlob == rRhs.pBlob && iIndex == rRhs.iIndex;
314}
315
316bool Bu::Blob::const_iterator::operator==(
317 const Bu::Blob::const_iterator &rRhs )
318{
319 if( isValid() == false && rRhs.isValid() == false )
320 return true;
321
322 return pBlob == rRhs.pBlob && iIndex == rRhs.iIndex;
323}
324
325bool Bu::Blob::const_iterator::operator!=( const Bu::Blob::iterator &rRhs )
326{
327 if( isValid() != rRhs.isValid() )
328 return true;
329
330 return pBlob != rRhs.pBlob || iIndex != rRhs.iIndex;
331}
332
333bool Bu::Blob::const_iterator::operator!=(
334 const Bu::Blob::const_iterator &rRhs )
335{
336 if( isValid() != rRhs.isValid() )
337 return true;
338
339 return pBlob != rRhs.pBlob || iIndex != rRhs.iIndex;
340}
341
342Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator=(
343 Bu::Blob::iterator &rRhs )
344{
345 pBlob = rRhs.pBlob;
346 iIndex = rRhs.iIndex;
347 bForward = rRhs.bForward;
348
349 return *this;
350}
351
352Bu::Blob::const_iterator &Bu::Blob::const_iterator::operator=(
353 Bu::Blob::const_iterator &rRhs )
354{
355 pBlob = rRhs.pBlob;
356 iIndex = rRhs.iIndex;
357 bForward = rRhs.bForward;
358
359 return *this;
360}
361
362
363Bu::Blob::iterator Bu::Blob::begin()
364{
365 return iterator( this, true );
366}
367
368Bu::Blob::const_iterator Bu::Blob::begin() const
369{
370 return const_iterator( this, true );
371}
372
373Bu::Blob::iterator Bu::Blob::end()
374{
375 return iterator();
376}
377
378Bu::Blob::const_iterator Bu::Blob::end() const
379{
380 return const_iterator();
381}
382
383Bu::Blob::iterator Bu::Blob::rbegin()
384{
385 return iterator( this, false );
386}
387
388Bu::Blob::const_iterator Bu::Blob::rbegin() const
389{
390 return const_iterator( this, false );
391}
392
393Bu::Blob::iterator Bu::Blob::rend()
394{
395 return iterator();
396}
397
398Bu::Blob::const_iterator Bu::Blob::rend() const
399{
400 return const_iterator();
401}
402
403
diff --git a/src/unstable/blob.h b/src/unstable/blob.h
new file mode 100644
index 0000000..5b8cabd
--- /dev/null
+++ b/src/unstable/blob.h
@@ -0,0 +1,125 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_BLOB_H
9#define BU_BLOB_H
10
11#include <stdint.h>
12
13namespace Bu
14{
15 /**
16 * Blob contans a sequence of binary values. This is basically the
17 * replacement for the old libbu++ Bu::String, std::string classes, or the
18 * tradition C char * string. The Blob is static and immutable, and a good
19 * choice when dealing with any sequence of binary data that you don't
20 * need to interpret further.
21 *
22 * If you're dealing with data that contains language, such as human text,
23 * then use the Bu::Text class instead.
24 */
25 class Blob
26 {
27 public:
28 Blob();
29 Blob( const Blob &rSrc );
30 Blob( const char *pSrc );
31 Blob( const void *pSrc, int32_t iSize );
32 virtual ~Blob();
33
34 int32_t getSize() const;
35 char *getData() const;
36
37 char *c_str() const;
38
39 Blob &operator=( const Blob &rRhs );
40 Blob &operator=( const char *pRhs );
41
42 class const_iterator;
43 class iterator
44 {
45 friend class Blob;
46 friend class const_iterator;
47 private:
48 iterator( Blob *pBlob, bool bForward );
49
50 public:
51 iterator();
52 iterator( const iterator &rSrc );
53
54 bool isValid() const;
55 operator bool() const;
56 char &operator *();
57
58 iterator &operator++( int );
59 iterator &operator++();
60 iterator &operator--( int );
61 iterator &operator--();
62 bool operator==( const iterator &rRhs );
63 bool operator==( const const_iterator &rRhs );
64 bool operator!=( const iterator &rRhs );
65 bool operator!=( const const_iterator &rRhs );
66
67 iterator &operator=( iterator &rRhs );
68
69 private:
70 Blob *pBlob;
71 int32_t iIndex;
72 bool bForward;
73 };
74
75 class const_iterator
76 {
77 friend class Blob;
78 friend class iterator;
79 private:
80 const_iterator( const Blob *pBlob, bool bForward );
81
82 public:
83 const_iterator();
84 const_iterator( const const_iterator &rSrc );
85 const_iterator( const iterator &rSrc );
86
87 bool isValid() const;
88 operator bool() const;
89 char operator *() const;
90
91 const_iterator &operator++( int );
92 const_iterator &operator++();
93 const_iterator &operator--( int );
94 const_iterator &operator--();
95 bool operator==( const iterator &rRhs );
96 bool operator==( const const_iterator &rRhs );
97 bool operator!=( const iterator &rRhs );
98 bool operator!=( const const_iterator &rRhs );
99
100 const_iterator &operator=( iterator &rRhs );
101 const_iterator &operator=( const_iterator &rRhs );
102
103 private:
104 const Blob *pBlob;
105 int32_t iIndex;
106 bool bForward;
107 };
108
109 iterator begin();
110 const_iterator begin() const;
111 iterator end();
112 const_iterator end() const;
113 iterator rbegin();
114 const_iterator rbegin() const;
115 iterator rend();
116 const_iterator rend() const;
117
118 private:
119 char *pData;
120 int32_t iSize;
121 };
122}
123
124#endif
125
diff --git a/src/unstable/blobbuilder.cpp b/src/unstable/blobbuilder.cpp
new file mode 100644
index 0000000..73271f8
--- /dev/null
+++ b/src/unstable/blobbuilder.cpp
@@ -0,0 +1,8 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8
diff --git a/src/unstable/blobbuilder.h b/src/unstable/blobbuilder.h
new file mode 100644
index 0000000..73271f8
--- /dev/null
+++ b/src/unstable/blobbuilder.h
@@ -0,0 +1,8 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8
diff --git a/src/unstable/text.cpp b/src/unstable/text.cpp
new file mode 100644
index 0000000..73271f8
--- /dev/null
+++ b/src/unstable/text.cpp
@@ -0,0 +1,8 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8
diff --git a/src/unstable/text.h b/src/unstable/text.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/unstable/text.h
diff --git a/src/unstable/textbuilder.cpp b/src/unstable/textbuilder.cpp
new file mode 100644
index 0000000..73271f8
--- /dev/null
+++ b/src/unstable/textbuilder.cpp
@@ -0,0 +1,8 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8
diff --git a/src/unstable/textbuilder.h b/src/unstable/textbuilder.h
new file mode 100644
index 0000000..73271f8
--- /dev/null
+++ b/src/unstable/textbuilder.h
@@ -0,0 +1,8 @@
1/*
2 * Copyright (C) 2007-2019 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8