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 "y2/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(bytecodeistream & 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 std::ostream & toXml (std::ostream & str, int indent ) const; 00055 }; 00056 00057 vector<Component> components; 00058 00059 protected: 00060 friend class YCPPath; 00061 00066 YCPPathRep(); 00067 00071 YCPPathRep(const char *r); 00072 00076 void append(const Component&c); 00077 public: 00078 00082 bool isRoot() const; 00083 00092 YCPValue select(const YCPValue& val); 00093 00097 void append(const YCPPath&p); 00098 00102 void append(string c); 00103 00108 long length() const; 00109 00117 bool isPrefixOf(const YCPPath& p) const; 00118 00124 YCPPath at(long index) const; 00125 00132 YCPPath prefix(long index) const; 00133 00138 string component_str(long index) const; 00139 00147 YCPOrder compare(const YCPPath &v) const; 00148 00155 string toString() const; 00156 00160 std::ostream & toStream (std::ostream & str) const; 00161 std::ostream & toXml (std::ostream & str, int indent ) const; 00162 00166 YCPValueType valuetype() const; 00167 }; 00168 00175 class YCPPath : public YCPValue 00176 { 00177 DEF_COMMON(Path, Value); 00178 public: 00179 YCPPath() : YCPValue(new YCPPathRep()) {} 00180 YCPPath(const char *r) : YCPValue(new YCPPathRep(r)) {} 00181 YCPPath(string s) : YCPValue(new YCPPathRep(s.c_str())) {} 00182 YCPPath(bytecodeistream & str); 00183 }; 00184 00185 #endif // YCPPath_h