00001 /*---------------------------------------------------------------------\ 00002 | | 00003 | __ __ ____ _____ ____ | 00004 | \ \ / /_ _/ ___|_ _|___ \ | 00005 | \ V / _` \___ \ | | __) | | 00006 | | | (_| |___) || | / __/ | 00007 | |_|\__,_|____/ |_| |_____| | 00008 | | 00009 | core system | 00010 | (C) SuSE GmbH | 00011 \----------------------------------------------------------------------/ 00012 00013 File: YCPPath.h 00014 00015 Author: Mathias Kettner <kettner@suse.de> 00016 Maintainer: Thomas Roelz <tom@suse.de> 00017 00018 /-*/ 00019 // -*- c++ -*- 00020 00021 #ifndef YCPPath_h 00022 #define YCPPath_h 00023 00024 00025 #include "YCPValue.h" 00026 #include <y2util/Ustring.h> 00027 00028 #include "ycp/SymbolEntry.h" 00029 00040 class YCPPathRep : public YCPValueRep 00041 { 00042 struct Component 00043 { 00044 Ustring component; // component string 00045 bool complex; // true if component is quoted by " in source. false otherwise (component contains only a-zA-Z0-9-_) 00046 Component() : component (SymbolEntry::emptyUstring), complex (false) {} 00047 Component(string s); // for initial creation. Unquotes and unescapes 00048 Component(std::istream & str); // for initial creation 00049 int compare(const Component&to) const { 00050 return component.asString().compare(to.component.asString()); 00051 } 00052 string toString() const; 00053 std::ostream & toStream (std::ostream & str) const; 00054 }; 00055 00056 vector<Component> components; 00057 00058 protected: 00059 friend class YCPPath; 00060 00065 YCPPathRep(); 00066 00070 YCPPathRep(const char *r); 00071 00075 void append(const Component&c); 00076 public: 00077 00081 bool isRoot() const; 00082 00091 YCPValue select(const YCPValue& val); 00092 00096 void append(const YCPPath&p); 00097 00101 void append(string c); 00102 00107 long length() const; 00108 00116 bool isPrefixOf(const YCPPath& p) const; 00117 00123 YCPPath at(long index) const; 00124 00129 string component_str(long index) const; 00130 00138 YCPOrder compare(const YCPPath &v) const; 00139 00146 string toString() const; 00147 00151 std::ostream & toStream (std::ostream & str) const; 00152 00156 YCPValueType valuetype() const; 00157 }; 00158 00165 class YCPPath : public YCPValue 00166 { 00167 DEF_COMMON(Path, Value); 00168 public: 00169 YCPPath() : YCPValue(new YCPPathRep()) {} 00170 YCPPath(const char *r) : YCPValue(new YCPPathRep(r)) {} 00171 YCPPath(string s) : YCPValue(new YCPPathRep(s.c_str())) {} 00172 YCPPath(std::istream & str); 00173 }; 00174 00175 #endif // YCPPath_h