00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef YCPList_h
00022 #define YCPList_h
00023
00024
00025 #include <iterator>
00026 #include "YCPValue.h"
00027
00028
00029 typedef vector<YCPValue> YCPValueList;
00030 class YCPListIterator;
00031 class YCPCodeCompare;
00032
00033
00046 class YCPListRep : public YCPValueRep
00047 {
00048 YCPValueList elements;
00049
00050 protected:
00051
00052 typedef YCPValueList::iterator iterator;
00053 typedef YCPValueList::const_iterator const_iterator;
00054 typedef YCPValueList::value_type value_type;
00055 typedef YCPValueList::const_reference const_reference;
00056
00057 friend class YCPList;
00058
00062 YCPListRep();
00063
00067 ~YCPListRep() {}
00068
00069 public:
00073 int size() const;
00074
00078 void reserve (int size);
00079
00083 bool isEmpty() const;
00084
00090 void add(const YCPValue& value);
00091
00097 void push_back(const YCPValue& value);
00098
00104 void set(const int n, const YCPValue& value);
00105
00109 void remove(const int n);
00110
00115 void swap(int x, int y);
00116
00120 bool contains (const YCPValue& value) const;
00121
00125 void sortlist();
00126
00130 void lsortlist();
00131
00136 void fsortlist(const YCPCodeCompare& cmp);
00137
00143 virtual const YCPElementRep* shallowCopy() const;
00144
00152 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const;
00153
00157 YCPValue value(int n) const;
00158
00164 YCPListIterator begin() const;
00165
00171 YCPListIterator end() const;
00172
00191 YCPOrder compare(const YCPList &v) const;
00192
00198 string toString() const;
00199
00203 std::ostream & toStream (std::ostream & str) const;
00204 std::ostream & toXml (std::ostream & str, int indent ) const;
00205
00209 YCPValueType valuetype() const;
00210
00216 string commaList() const;
00217 };
00218
00219
00223 class YCPListIterator
00224 {
00225 friend class YCPListRep;
00226
00227 YCPValueList::const_iterator position;
00228
00229 public:
00230
00231 typedef std::bidirectional_iterator_tag iterator_category;
00232 typedef ptrdiff_t difference_type;
00233 typedef const YCPValue value_type;
00234 typedef const YCPValue* pointer;
00235 typedef const YCPValue& reference;
00236
00237 protected:
00238
00239 YCPListIterator(YCPValueList::const_iterator position)
00240 : position(position) {}
00241
00242 public:
00243
00247 reference operator*() const { return position.operator*(); }
00248
00252 friend bool operator==(const YCPListIterator &x, const YCPListIterator &y) {
00253 return x.position == y.position;
00254 }
00255
00259 friend bool operator!=(const YCPListIterator &x, const YCPListIterator &y) {
00260 return !(x == y);
00261 }
00262
00266 void operator++() { ++position; }
00267 void operator++(int) { ++position; }
00268
00269 };
00270
00271
00272 #define CONST_ELEMENT (static_cast<const YCPListRep*>(element))
00273 #define ELEMENT (const_cast<YCPListRep*>(static_cast<const YCPListRep*>(this->writeCopy())))
00274
00281 class YCPList : public YCPValue
00282 {
00283 DEF_COW_COMMON(List, Value);
00284 public:
00285
00286 typedef YCPListRep::iterator iterator;
00287 typedef YCPListRep::const_iterator const_iterator;
00288 typedef YCPListRep::value_type value_type;
00289 typedef YCPListRep::const_reference const_reference;
00290
00291 YCPList() : YCPValue(new YCPListRep()) {}
00292 YCPList(bytecodeistream & str);
00293
00294 int size() const { return CONST_ELEMENT->size (); }
00295 void reserve (int size) { ELEMENT->reserve (size); }
00296 bool isEmpty() const { return CONST_ELEMENT->isEmpty (); }
00297 void add(const YCPValue& value) { ELEMENT->add (value); }
00298 void push_back(const YCPValue& value) { ELEMENT->push_back(value); }
00299 void set(const int n, const YCPValue& value) { ELEMENT->set (n, value); }
00300 void remove(const int n) { ELEMENT->remove (n); }
00301 void swap(int x, int y) { ELEMENT->swap (x, y); }
00302 bool contains (const YCPValue& value) const { return CONST_ELEMENT->contains (value); }
00303 void sortlist() { ELEMENT->sortlist (); }
00304 void lsortlist() { ELEMENT->lsortlist (); }
00305 void fsortlist(const YCPCodeCompare& cmp) { ELEMENT->fsortlist (cmp); }
00306
00307 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const
00308 { return CONST_ELEMENT->functionalAdd (value, prepend); }
00309 YCPValue value(int n) const { return CONST_ELEMENT->value (n); }
00310 YCPListIterator begin() const { return CONST_ELEMENT->begin(); }
00311 YCPListIterator end() const { return CONST_ELEMENT->end(); }
00312 string commaList() const { return CONST_ELEMENT->commaList (); }
00313 };
00314
00315 #undef CONST_ELEMENT
00316 #undef ELEMENT
00317
00318 #endif // YCPList_h