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