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