aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/list.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-11-09 16:25:22 +0000
committerMike Buland <eichlan@xagasoft.com>2012-11-09 16:25:22 +0000
commit74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch)
tree843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /c++-libbu++/src/list.cpp
parentd9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff)
downloadlibgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz
libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip
Made the repo less libbu++-centric.
Diffstat (limited to 'c++-libbu++/src/list.cpp')
-rw-r--r--c++-libbu++/src/list.cpp205
1 files changed, 205 insertions, 0 deletions
diff --git a/c++-libbu++/src/list.cpp b/c++-libbu++/src/list.cpp
new file mode 100644
index 0000000..d081a22
--- /dev/null
+++ b/c++-libbu++/src/list.cpp
@@ -0,0 +1,205 @@
1#include "gats/list.h"
2
3#include "gats/string.h"
4#include "gats/integer.h"
5#include "gats/float.h"
6#include "gats/boolean.h"
7#include "gats/dictionary.h"
8
9#include <bu/formatter.h>
10#include <bu/stream.h>
11
12Gats::List::List()
13{
14}
15
16Gats::List::~List()
17{
18 for( iterator i = begin(); i; i++ )
19 {
20 delete *i;
21 }
22}
23
24Gats::Object *Gats::List::clone() const
25{
26 Gats::List *pClone = new Gats::List;
27 for( const_iterator i = begin(); i; i++ )
28 {
29 pClone->append( (*i)->clone() );
30 }
31 return pClone;
32}
33
34void Gats::List::write( Bu::Stream &rOut ) const
35{
36 rOut.write("l", 1 );
37 for( const_iterator i = begin(); i; i++ )
38 {
39 (*i)->write( rOut );
40 }
41 rOut.write("e", 1 );
42}
43
44void Gats::List::read( Bu::Stream &rIn, char cType )
45{
46 for(;;)
47 {
48 Gats::Object *pObj = Gats::Object::read( rIn );
49 if( pObj == NULL )
50 break;
51 append( pObj );
52 }
53}
54
55void Gats::List::append( const char *s )
56{
57 Bu::List<Gats::Object *>::append( new Gats::String( s ) );
58}
59
60void Gats::List::append( const Bu::String &s )
61{
62 Bu::List<Gats::Object *>::append( new Gats::String( s ) );
63}
64
65void Gats::List::append( int32_t i )
66{
67 Bu::List<Gats::Object *>::append( new Gats::Integer( i ) );
68}
69
70void Gats::List::append( int64_t i )
71{
72 Bu::List<Gats::Object *>::append( new Gats::Integer( i ) );
73}
74
75void Gats::List::append( double d )
76{
77 Bu::List<Gats::Object *>::append( new Gats::Float( d ) );
78}
79
80void Gats::List::appendStr( const Bu::String &s )
81{
82 Bu::List<Gats::Object *>::append( new Gats::String( s ) );
83}
84
85void Gats::List::appendInt( int64_t i )
86{
87 Bu::List<Gats::Object *>::append( new Gats::Integer( i ) );
88}
89
90void Gats::List::appendFloat( double d )
91{
92 Bu::List<Gats::Object *>::append( new Gats::Float( d ) );
93}
94
95void Gats::List::appendBool( bool b )
96{
97 Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) );
98}
99
100void Gats::List::appendList( Gats::List *pL )
101{
102 Bu::List<Gats::Object *>::append( pL );
103}
104
105void Gats::List::appendDict( Gats::Dictionary *pD )
106{
107 Bu::List<Gats::Object *>::append( pD );
108}
109
110Gats::List *Gats::List::appendList()
111{
112 Gats::List *pLst = new Gats::List();
113 appendList( pLst );
114 return pLst;
115}
116
117Gats::Dictionary *Gats::List::appendDict()
118{
119 Gats::Dictionary *pDict = new Gats::Dictionary();
120 appendDict( pDict );
121 return pDict;
122}
123
124void Gats::List::prepend( const char *s )
125{
126 Bu::List<Gats::Object *>::prepend( new Gats::String( s ) );
127}
128
129void Gats::List::prepend( const Bu::String &s )
130{
131 Bu::List<Gats::Object *>::prepend( new Gats::String( s ) );
132}
133
134void Gats::List::prepend( int32_t i )
135{
136 Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) );
137}
138
139void Gats::List::prepend( int64_t i )
140{
141 Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) );
142}
143
144void Gats::List::prepend( double d )
145{
146 Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) );
147}
148
149void Gats::List::prependStr( const Bu::String &s )
150{
151 Bu::List<Gats::Object *>::prepend( new Gats::String( s ) );
152}
153
154void Gats::List::prependInt( int64_t i )
155{
156 Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) );
157}
158
159void Gats::List::prependFloat( double d )
160{
161 Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) );
162}
163
164void Gats::List::prependBool( bool b )
165{
166 Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) );
167}
168
169void Gats::List::prependList( Gats::List *pL )
170{
171 Bu::List<Gats::Object *>::prepend( pL );
172}
173
174void Gats::List::prependDict( Gats::Dictionary *pD )
175{
176 Bu::List<Gats::Object *>::prepend( pD );
177}
178
179Gats::List *Gats::List::prependList()
180{
181 Gats::List *pLst = new Gats::List();
182 prependList( pLst );
183 return pLst;
184}
185
186Gats::Dictionary *Gats::List::prependDict()
187{
188 Gats::Dictionary *pDict = new Gats::Dictionary();
189 prependDict( pDict );
190 return pDict;
191}
192
193Bu::Formatter &operator<<( Bu::Formatter &f, const Gats::List &l )
194{
195 f << "(list) [";
196 f.incIndent();
197 for( Gats::List::const_iterator i = l.begin(); i; i++ )
198 {
199 f << f.nl << **i;
200 }
201 f.decIndent();
202 f << f.nl << "]";
203 return f;
204}
205