|
yast2-core
|
00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: YCPList.h 00014 00015 Authors: Mathias Kettner <kettner@suse.de> 00016 Arvin Schnell <aschnell@suse.de> 00017 Maintainer: Thomas Roelz <tom@suse.de> 00018 00019 /-*/ 00020 // -*- c++ -*- 00021 00022 #ifndef YCPList_h 00023 #define YCPList_h 00024 00025 00026 #include "YCPValue.h" 00027 00028 00029 class YCPCodeCompare; 00030 00031 00044 class YCPListRep : public YCPValueRep 00045 { 00046 private: 00047 00048 typedef vector<YCPValue> YCPValueList; 00049 00050 YCPValueList elements; 00051 00052 protected: 00053 00054 typedef YCPValueList::iterator iterator; 00055 typedef YCPValueList::const_iterator const_iterator; 00056 typedef YCPValueList::value_type value_type; 00057 typedef YCPValueList::const_reference const_reference; 00058 00059 friend class YCPList; 00060 00064 YCPListRep(); 00065 00069 ~YCPListRep() {} 00070 00071 public: 00072 00076 int size() const; 00077 00081 void reserve (int size); 00082 00086 bool isEmpty() const; 00087 00093 void add(const YCPValue& value); 00094 00100 void push_back(const YCPValue& value); 00101 00107 void set(const int n, const YCPValue& value); 00108 00112 void remove(const int n); 00113 00118 void swap(int x, int y); 00119 00123 bool contains (const YCPValue& value) const; 00124 00128 void sortlist(); 00129 00133 void lsortlist(); 00134 00139 void fsortlist(const YCPCodeCompare& cmp); 00140 00146 virtual const YCPElementRep* shallowCopy() const; 00147 00155 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const; 00156 00160 YCPValue value(int n) const; 00161 00166 const_iterator begin() const; 00167 00172 const_iterator end() const; 00173 00192 YCPOrder compare(const YCPList &v) const; 00193 00199 string toString() const; 00200 00204 std::ostream & toStream (std::ostream & str) const; 00205 std::ostream & toXml (std::ostream & str, int indent ) const; 00206 00210 YCPValueType valuetype() const; 00211 00217 string commaList() const; 00218 }; 00219 00220 00221 #define CONST_ELEMENT (static_cast<const YCPListRep*>(element)) 00222 #define ELEMENT (const_cast<YCPListRep*>(static_cast<const YCPListRep*>(this->writeCopy()))) 00223 00230 class YCPList : public YCPValue 00231 { 00232 DEF_COW_COMMON(List, Value); 00233 00234 public: 00235 00236 typedef YCPListRep::iterator iterator; 00237 typedef YCPListRep::const_iterator const_iterator; 00238 typedef YCPListRep::value_type value_type; 00239 typedef YCPListRep::const_reference const_reference; 00240 00241 YCPList() : YCPValue(new YCPListRep()) {} 00242 YCPList(bytecodeistream & str); 00243 00244 int size() const { return CONST_ELEMENT->size (); } 00245 void reserve (int size) { ELEMENT->reserve (size); } 00246 bool isEmpty() const { return CONST_ELEMENT->isEmpty (); } 00247 void add(const YCPValue& value) { ELEMENT->add (value); } 00248 void push_back(const YCPValue& value) { ELEMENT->push_back(value); } 00249 void set(const int n, const YCPValue& value) { ELEMENT->set (n, value); } 00250 void remove(const int n) { ELEMENT->remove (n); } 00251 void swap(int x, int y) { ELEMENT->swap (x, y); } 00252 bool contains (const YCPValue& value) const { return CONST_ELEMENT->contains (value); } 00253 void sortlist() { ELEMENT->sortlist (); } 00254 void lsortlist() { ELEMENT->lsortlist (); } 00255 void fsortlist(const YCPCodeCompare& cmp) { ELEMENT->fsortlist (cmp); } 00256 00257 YCPList functionalAdd(const YCPValue& value, bool prepend = false) const 00258 { return CONST_ELEMENT->functionalAdd (value, prepend); } 00259 YCPValue value(int n) const { return CONST_ELEMENT->value (n); } 00260 const_iterator begin() const { return CONST_ELEMENT->begin(); } 00261 const_iterator end() const { return CONST_ELEMENT->end(); } 00262 string commaList() const { return CONST_ELEMENT->commaList (); } 00263 }; 00264 00265 #undef CONST_ELEMENT 00266 #undef ELEMENT 00267 00268 #endif // YCPList_h
1.7.3