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 friend class YCPList;
00052
00056 YCPListRep();
00057
00061 ~YCPListRep() {}
00062
00063 public:
00067 int size() const;
00068
00072 void reserve (int size);
00073
00077 bool isEmpty() const;
00078
00084 void add(const YCPValue& value);
00085
00091 void set(const int n, const YCPValue& value);
00092
00096 void remove(const int n);
00097
00102 void swap(int x, int y);
00103
00107 bool contains (const YCPValue& value) const;
00108
00112 void sortlist();
00113
00117 void lsortlist();
00118
00123 void fsortlist(const YCPCodeCompare& cmp);
00124
00130 virtual const YCPElementRep* shallowCopy() const;
00131
00139 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const;
00140
00144 YCPValue value(int n) const;
00145
00151 YCPListIterator begin() const;
00152
00158 YCPListIterator end() const;
00159
00178 YCPOrder compare(const YCPList &v) const;
00179
00185 string toString() const;
00186
00190 std::ostream & toStream (std::ostream & str) const;
00191 std::ostream & toXml (std::ostream & str, int indent ) const;
00192
00196 YCPValueType valuetype() const;
00197
00203 string commaList() const;
00204 };
00205
00206
00210 class YCPListIterator
00211 {
00212 friend class YCPListRep;
00213
00214 YCPValueList::const_iterator position;
00215
00216 public:
00217
00218 typedef std::bidirectional_iterator_tag iterator_category;
00219 typedef ptrdiff_t difference_type;
00220 typedef const YCPValue value_type;
00221 typedef const YCPValue* pointer;
00222 typedef const YCPValue& reference;
00223
00224 protected:
00225
00226 YCPListIterator(YCPValueList::const_iterator position)
00227 : position(position) {}
00228
00229 public:
00230
00234 reference operator*() const { return position.operator*(); }
00235
00239 friend bool operator==(const YCPListIterator &x, const YCPListIterator &y) {
00240 return x.position == y.position;
00241 }
00242
00246 friend bool operator!=(const YCPListIterator &x, const YCPListIterator &y) {
00247 return !(x == y);
00248 }
00249
00253 void operator++() { ++position; }
00254 void operator++(int) { ++position; }
00255
00256 };
00257
00258
00259 #define CONST_ELEMENT (static_cast<const YCPListRep*>(element))
00260 #define ELEMENT (const_cast<YCPListRep*>(static_cast<const YCPListRep*>(this->writeCopy())))
00261
00268 class YCPList : public YCPValue
00269 {
00270 DEF_COW_COMMON(List, Value);
00271 public:
00272 YCPList() : YCPValue(new YCPListRep()) {}
00273 YCPList(bytecodeistream & str);
00274
00275 int size() const { return CONST_ELEMENT->size (); }
00276 void reserve (int size) { ELEMENT->reserve (size); }
00277 bool isEmpty() const { return CONST_ELEMENT->isEmpty (); }
00278 void add(const YCPValue& value) { ELEMENT->add (value); }
00279 void set(const int n, const YCPValue& value) { ELEMENT->set (n, value); }
00280 void remove(const int n) { ELEMENT->remove (n); }
00281 void swap(int x, int y) { ELEMENT->swap (x, y); }
00282 bool contains (const YCPValue& value) const { return CONST_ELEMENT->contains (value); }
00283 void sortlist() { ELEMENT->sortlist (); }
00284 void lsortlist() { ELEMENT->lsortlist (); }
00285 void fsortlist(const YCPCodeCompare& cmp) { ELEMENT->fsortlist (cmp); }
00286
00287 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const
00288 { return CONST_ELEMENT->functionalAdd (value, prepend); }
00289 YCPValue value(int n) const { return CONST_ELEMENT->value (n); }
00290 YCPListIterator begin() const { return CONST_ELEMENT->begin(); }
00291 YCPListIterator end() const { return CONST_ELEMENT->end(); }
00292 string commaList() const { return CONST_ELEMENT->commaList (); }
00293 };
00294
00295 #undef CONST_ELEMENT
00296 #undef ELEMENT
00297
00298 #endif // YCPList_h