yast2-core
YCPPath.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | |
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
8 | |
9 | core system |
10 | (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12 
13  File: YCPPath.h
14 
15  Author: Mathias Kettner <kettner@suse.de>
16  Maintainer: Thomas Roelz <tom@suse.de>
17 
18 /-*/
19 // -*- c++ -*-
20 
21 #ifndef YCPPath_h
22 #define YCPPath_h
23 
24 
25 #include "YCPValue.h"
26 #include <y2util/Ustring.h>
27 
28 #include "y2/SymbolEntry.h"
29 
40 class YCPPathRep : public YCPValueRep
41 {
42  struct Component
43  {
44  Ustring component; // component string
45  bool complex; // true if component is quoted by " in source. false otherwise (component contains only a-zA-Z0-9-_)
46  Component() : component (SymbolEntry::emptyUstring), complex (false) {}
47  Component(string s); // for initial creation. Unquotes and unescapes
48  Component(bytecodeistream & str); // for initial creation
49  int compare(const Component&to) const {
50  return component.asString().compare(to.component.asString());
51  }
52  string toString() const;
53  std::ostream & toStream (std::ostream & str) const;
54  std::ostream & toXml (std::ostream & str, int indent ) const;
55  };
56 
57  vector<Component> components;
58 
59 protected:
60  friend class YCPPath;
61 
66  YCPPathRep();
67 
71  YCPPathRep(const char *r);
72 
76  void append(const Component&c);
77 public:
78 
82  bool isRoot() const;
83 
92  YCPValue select(const YCPValue& val);
93 
97  void append(const YCPPath&p);
98 
102  void append(string c);
103 
108  long length() const;
109 
117  bool isPrefixOf(const YCPPath& p) const;
118 
124  YCPPath at(long index) const;
125 
132  YCPPath prefix(long index) const;
133 
138  string component_str(long index) const;
139 
147  YCPOrder compare(const YCPPath &v) const;
148 
155  string toString() const;
156 
160  std::ostream & toStream (std::ostream & str) const;
161  std::ostream & toXml (std::ostream & str, int indent ) const;
162 
166  YCPValueType valuetype() const;
167 };
168 
175 class YCPPath : public YCPValue
176 {
177  DEF_COMMON(Path, Value);
178 public:
180  YCPPath(const char *r) : YCPValue(new YCPPathRep(r)) {}
181  YCPPath(string s) : YCPValue(new YCPPathRep(s.c_str())) {}
183 };
184 
185 #endif // YCPPath_h
Definition: SymbolEntry.h:41
#define str
Definition: scanner.cc:997
int compare(const Component &to) const
Definition: YCPPath.h:49
long length() const
Definition: YCPPath.cc:125
std::ostream & toStream(std::ostream &str) const
Definition: YCPPath.cc:336
bool isRoot() const
Definition: YCPPath.cc:84
YCPOrder compare(const YCPPath &v) const
Definition: YCPPath.cc:169
YCPValueType valuetype() const
Definition: YCPPath.cc:198
YCPValueType
Value Type Defines constants for the Value types. The Value type specifies the class the YCPValueRep ...
Definition: YCPValue.h:36
bool isPrefixOf(const YCPPath &p) const
Definition: YCPPath.cc:132
string toString() const
Definition: YCPPath.cc:184
YCPPathRep()
Definition: YCPPath.cc:28
DEF_COMMON(Path, Value)
YCPPath prefix(long index) const
Definition: YCPPath.cc:152
YCPPath(const char *r)
Definition: YCPPath.h:180
Definition: YCPPath.h:42
Component()
Definition: YCPPath.h:46
Unique strings.
Definition: Ustring.h:124
string component_str(long index) const
Definition: YCPPath.cc:162
YCPOrder
Definition: YCPValue.h:57
Ustring component
Definition: YCPPath.h:44
Abstract base class of all YCP values. Abstract base class of all YCP elements that can be used as pr...
Definition: YCPValue.h:71
const std::string & asString() const
Definition: Ustring.h:155
void append(const Component &c)
Definition: YCPPath.cc:100
YCPPath()
Definition: YCPPath.h:179
YCPPath(string s)
Definition: YCPPath.h:181
bool complex
Definition: YCPPath.h:45
std::ostream & toStream(std::ostream &str) const
Definition: YCPPath.cc:353
Wrapper for YCPValueRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPValueRep with the arrow operator. See YCPValueRep.
Definition: YCPValue.h:275
string toString() const
Definition: YCPPath.cc:279
Wrapper for YCPPathRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPPathRep with the arrow operator. See YCPPathRep.
Definition: YCPPath.h:175
An istream that remembers some data about the bytecode.
Definition: Bytecode.h:42
std::ostream & toXml(std::ostream &str, int indent) const
Definition: YCPPath.cc:371
YCPPath at(long index) const
Definition: YCPPath.cc:143
vector< Component > components
Definition: YCPPath.h:57
YCPValueRep representing a data path A YCP path describes a subtree in a YCP data structure...
Definition: YCPPath.h:40
YCPValue select(const YCPValue &val)
Definition: YCPPath.cc:117
std::ostream & toXml(std::ostream &str, int indent) const
Definition: YCPPath.cc:343

Generated on a sunny day for yast2-core by doxygen 1.8.8