00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: YCPTerm.h 00014 00015 Author: Klaus Kaempf <kkaempf@suse.de> 00016 Mathias Kettner <kettner@suse.de> 00017 Maintainer: Klaus Kaempf <kkaempf@suse.de> 00018 00019 /-*/ 00020 // -*- c++ -*- 00021 00022 #ifndef YCPTerm_h 00023 #define YCPTerm_h 00024 00025 00026 #include <ycp/YCPSymbol.h> 00027 #include <ycp/YCPList.h> 00028 #include <y2util/Ustring.h> 00029 00035 class YCPTermRep : public YCPValueRep 00036 { 00037 #define GLOBALNAME "_" 00038 00041 Ustring s; 00042 00046 YCPList l; 00047 00051 void setName (string name); 00052 00053 protected: 00054 friend class YCPTerm; 00055 00059 YCPTermRep(const string& s); 00060 00064 YCPTermRep(const string& s, const YCPList& l); 00065 00069 ~YCPTermRep() {} 00070 00071 public: 00075 string name() const; 00076 00081 YCPList args() const; 00082 00102 YCPOrder compare(const YCPTerm &v) const; 00103 00110 virtual const YCPElementRep* shallowCopy() const; 00111 00116 YCPTerm functionalAdd(const YCPValue& value) const; 00117 00124 string toString() const; 00125 00129 std::ostream & toStream (std::ostream & str) const; 00130 00134 bool isEmpty() const; 00135 00139 int size() const; 00140 00144 void reserve (int size); 00145 00149 YCPValue value(int n) const; 00150 00154 void set(const int n, const YCPValue& value); 00155 00159 void add(const YCPValue& value); 00160 00164 YCPValueType valuetype() const; 00165 }; 00166 00167 #define CONST_ELEMENT (static_cast<const YCPTermRep*>(element)) 00168 #define ELEMENT (const_cast<YCPTermRep*>(static_cast<const YCPTermRep*>(this->writeCopy ()))) 00169 00176 class YCPTerm : public YCPValue 00177 { 00178 DEF_COW_COMMON(Term, Value); 00179 public: 00180 YCPTerm(const string& s) : YCPValue(new YCPTermRep(s)) {} 00181 YCPTerm(const string& s, const YCPList& l) : YCPValue(new YCPTermRep(s, l)) {} 00182 YCPTerm(std::istream & str); 00183 00184 string name() const { return CONST_ELEMENT->name (); } 00185 YCPList args() const { return CONST_ELEMENT->args (); } 00186 YCPTerm functionalAdd(const YCPValue& value) const { return CONST_ELEMENT->functionalAdd (value); } 00187 bool isEmpty() const { return CONST_ELEMENT->isEmpty (); } 00188 int size() const { return CONST_ELEMENT->size (); } 00189 void reserve (int size) { ELEMENT->reserve (size); } 00190 YCPValue value(int n) const { return CONST_ELEMENT->value (n); } 00191 void set(const int n, const YCPValue& value) { ELEMENT->set (n, value); } 00192 void add(const YCPValue& value) { ELEMENT->add (value); } 00193 }; 00194 00195 #undef CONST_ELEMENT 00196 #undef ELEMENT 00197 00198 #endif // YCPTerm_h