diff options
author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
commit | 74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch) | |
tree | 843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /c++-libbu++/src/list.cpp | |
parent | d9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff) | |
download | libgats-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.cpp | 205 |
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 | |||
12 | Gats::List::List() | ||
13 | { | ||
14 | } | ||
15 | |||
16 | Gats::List::~List() | ||
17 | { | ||
18 | for( iterator i = begin(); i; i++ ) | ||
19 | { | ||
20 | delete *i; | ||
21 | } | ||
22 | } | ||
23 | |||
24 | Gats::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 | |||
34 | void 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 | |||
44 | void 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 | |||
55 | void Gats::List::append( const char *s ) | ||
56 | { | ||
57 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
58 | } | ||
59 | |||
60 | void Gats::List::append( const Bu::String &s ) | ||
61 | { | ||
62 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
63 | } | ||
64 | |||
65 | void Gats::List::append( int32_t i ) | ||
66 | { | ||
67 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
68 | } | ||
69 | |||
70 | void Gats::List::append( int64_t i ) | ||
71 | { | ||
72 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
73 | } | ||
74 | |||
75 | void Gats::List::append( double d ) | ||
76 | { | ||
77 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | ||
78 | } | ||
79 | |||
80 | void Gats::List::appendStr( const Bu::String &s ) | ||
81 | { | ||
82 | Bu::List<Gats::Object *>::append( new Gats::String( s ) ); | ||
83 | } | ||
84 | |||
85 | void Gats::List::appendInt( int64_t i ) | ||
86 | { | ||
87 | Bu::List<Gats::Object *>::append( new Gats::Integer( i ) ); | ||
88 | } | ||
89 | |||
90 | void Gats::List::appendFloat( double d ) | ||
91 | { | ||
92 | Bu::List<Gats::Object *>::append( new Gats::Float( d ) ); | ||
93 | } | ||
94 | |||
95 | void Gats::List::appendBool( bool b ) | ||
96 | { | ||
97 | Bu::List<Gats::Object *>::append( new Gats::Boolean( b ) ); | ||
98 | } | ||
99 | |||
100 | void Gats::List::appendList( Gats::List *pL ) | ||
101 | { | ||
102 | Bu::List<Gats::Object *>::append( pL ); | ||
103 | } | ||
104 | |||
105 | void Gats::List::appendDict( Gats::Dictionary *pD ) | ||
106 | { | ||
107 | Bu::List<Gats::Object *>::append( pD ); | ||
108 | } | ||
109 | |||
110 | Gats::List *Gats::List::appendList() | ||
111 | { | ||
112 | Gats::List *pLst = new Gats::List(); | ||
113 | appendList( pLst ); | ||
114 | return pLst; | ||
115 | } | ||
116 | |||
117 | Gats::Dictionary *Gats::List::appendDict() | ||
118 | { | ||
119 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
120 | appendDict( pDict ); | ||
121 | return pDict; | ||
122 | } | ||
123 | |||
124 | void Gats::List::prepend( const char *s ) | ||
125 | { | ||
126 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
127 | } | ||
128 | |||
129 | void Gats::List::prepend( const Bu::String &s ) | ||
130 | { | ||
131 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
132 | } | ||
133 | |||
134 | void Gats::List::prepend( int32_t i ) | ||
135 | { | ||
136 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
137 | } | ||
138 | |||
139 | void Gats::List::prepend( int64_t i ) | ||
140 | { | ||
141 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
142 | } | ||
143 | |||
144 | void Gats::List::prepend( double d ) | ||
145 | { | ||
146 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | ||
147 | } | ||
148 | |||
149 | void Gats::List::prependStr( const Bu::String &s ) | ||
150 | { | ||
151 | Bu::List<Gats::Object *>::prepend( new Gats::String( s ) ); | ||
152 | } | ||
153 | |||
154 | void Gats::List::prependInt( int64_t i ) | ||
155 | { | ||
156 | Bu::List<Gats::Object *>::prepend( new Gats::Integer( i ) ); | ||
157 | } | ||
158 | |||
159 | void Gats::List::prependFloat( double d ) | ||
160 | { | ||
161 | Bu::List<Gats::Object *>::prepend( new Gats::Float( d ) ); | ||
162 | } | ||
163 | |||
164 | void Gats::List::prependBool( bool b ) | ||
165 | { | ||
166 | Bu::List<Gats::Object *>::prepend( new Gats::Boolean( b ) ); | ||
167 | } | ||
168 | |||
169 | void Gats::List::prependList( Gats::List *pL ) | ||
170 | { | ||
171 | Bu::List<Gats::Object *>::prepend( pL ); | ||
172 | } | ||
173 | |||
174 | void Gats::List::prependDict( Gats::Dictionary *pD ) | ||
175 | { | ||
176 | Bu::List<Gats::Object *>::prepend( pD ); | ||
177 | } | ||
178 | |||
179 | Gats::List *Gats::List::prependList() | ||
180 | { | ||
181 | Gats::List *pLst = new Gats::List(); | ||
182 | prependList( pLst ); | ||
183 | return pLst; | ||
184 | } | ||
185 | |||
186 | Gats::Dictionary *Gats::List::prependDict() | ||
187 | { | ||
188 | Gats::Dictionary *pDict = new Gats::Dictionary(); | ||
189 | prependDict( pDict ); | ||
190 | return pDict; | ||
191 | } | ||
192 | |||
193 | Bu::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 | |||