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 "YCPValue.h"
00026
00027
00028
00029 class YCPCodeCompare;
00030
00043 class YCPListRep : public YCPValueRep
00044 {
00045 vector<YCPValue> elements;
00046
00047 protected:
00048 friend class YCPList;
00049
00053 YCPListRep();
00054
00058 ~YCPListRep() {}
00059
00060 public:
00064 int size() const;
00065
00069 void reserve (int size);
00070
00074 bool isEmpty() const;
00075
00081 void add(const YCPValue& value);
00082
00088 void set(const int n, const YCPValue& value);
00089
00093 void remove(const int n);
00094
00099 void swap(int x, int y);
00100
00104 bool contains (const YCPValue& value) const;
00105
00109 void sortlist();
00110
00114 void lsortlist();
00115
00120 void fsortlist(const YCPCodeCompare& cmp);
00121
00127 virtual const YCPElementRep* shallowCopy() const;
00128
00136 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const;
00137
00141 YCPValue value(int n) const;
00142
00161 YCPOrder compare(const YCPList &v) const;
00162
00168 string toString() const;
00169
00173 std::ostream & toStream (std::ostream & str) const;
00174 std::ostream & toXml (std::ostream & str, int indent ) const;
00175
00179 YCPValueType valuetype() const;
00180
00186 string commaList() const;
00187 };
00188
00189 #define CONST_ELEMENT (static_cast<const YCPListRep*>(element))
00190 #define ELEMENT (const_cast<YCPListRep*>(static_cast<const YCPListRep*>(this->writeCopy())))
00191
00198 class YCPList : public YCPValue
00199 {
00200 DEF_COW_COMMON(List, Value);
00201 public:
00202 YCPList() : YCPValue(new YCPListRep()) {}
00203 YCPList(bytecodeistream & str);
00204
00205 int size() const { return CONST_ELEMENT->size (); }
00206 void reserve (int size) { ELEMENT->reserve (size); }
00207 bool isEmpty() const { return CONST_ELEMENT->isEmpty (); }
00208 void add(const YCPValue& value) { ELEMENT->add (value); }
00209 void set(const int n, const YCPValue& value) { ELEMENT->set (n, value); }
00210 void remove(const int n) { ELEMENT->remove (n); }
00211 void swap(int x, int y) { ELEMENT->swap (x, y); }
00212 bool contains (const YCPValue& value) const { return CONST_ELEMENT->contains (value); }
00213 void sortlist() { ELEMENT->sortlist (); }
00214 void lsortlist() { ELEMENT->lsortlist (); }
00215 void fsortlist(const YCPCodeCompare& cmp) { ELEMENT->fsortlist (cmp); }
00216
00217 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const
00218 { return CONST_ELEMENT->functionalAdd (value, prepend); }
00219 YCPValue value(int n) const { return CONST_ELEMENT->value (n); }
00220 string commaList() const { return CONST_ELEMENT->commaList (); }
00221 };
00222
00223 #undef CONST_ELEMENT
00224 #undef ELEMENT
00225
00226 #endif // YCPList_h