2 * Copyright (c) 2003, 2004 Michael Pyne <michael.pyne@kdemail.net>
4 * This software is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this library; see the file COPYING.
16 * If not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <qiodevice.h>
27 BList::BList (ByteTape
&tape
)
28 : m_valid(false), m_array()
33 BList::BList (QByteArray
&dict
, unsigned int start
)
34 : m_valid(false), m_array()
36 ByteTape
tape (dict
, start
);
41 void BList::init (ByteTape
&tape
)
50 /* Repeat circling over the string until the list is over */
56 temp
= new BDict (tape
);
59 case 'l': /* This element is a list */
60 temp
= new BList (tape
);
63 case 'i': /* This element is an int */
64 temp
= new BInt (tape
);
67 default: /* Maybe a string? */
68 temp
= new BString (tape
);
71 if (!temp
|| !temp
->isValid())
72 return; // Invalid list element
74 m_array
.append (temp
);
79 // Only way out is to detect 'e', so we need to increment tape past that.
85 BBaseVectorIterator iter
;
87 for (iter
= begin(); iter
!= end(); ++iter
)
91 BBase
* BList::index (unsigned int i
)
99 BList
* BList::indexList (unsigned int i
)
101 BBase
*base
= index(i
);
103 if (base
&& base
->type_id() == bList
)
104 return dynamic_cast<BList
*>(base
);
109 BInt
* BList::indexInt (unsigned int i
)
111 BBase
*base
= index(i
);
113 if (base
&& base
->type_id() == bInt
)
114 return dynamic_cast<BInt
*>(base
);
119 BDict
* BList::indexDict (unsigned int i
)
121 BBase
*base
= index(i
);
123 if (base
&& base
->type_id() == bDict
)
124 return dynamic_cast<BDict
*>(base
);
129 BString
* BList::indexStr (unsigned int i
)
131 BBase
*base
= index(i
);
133 if (base
&& base
->type_id() == bString
)
134 return dynamic_cast<BString
*>(base
);
139 bool BList::writeToDevice(QIODevice
&device
)
144 const char *l_str
= "l";
145 const char *e_str
= "e";
146 Q_LONG written
= 0, result
= 0;
148 written
= device
.write (l_str
, 1);
151 if (written
< 0 || result
< 0)
154 result
= device
.write (l_str
, 1);
158 BBaseVectorIterator iter
;
159 for (iter
= begin(); iter
!= end(); ++iter
)
161 if (!((*iter
)->writeToDevice (device
)))
165 written
= device
.write (e_str
, 1);
168 if (written
< 0 || result
< 0)
171 result
= device
.write (e_str
, 1);
178 // vim: set et sw=4 ts=4: