yast2-core
YCPMap.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: YCPMap.h
14 
15  Authors: Mathias Kettner <kettner@suse.de>
16  Arvin Schnell <aschnell@suse.de>
17  Maintainer: Thomas Roelz <tom@suse.de>
18 
19 /-*/
20 // -*- c++ -*-
21 
22 #ifndef YCPMap_h
23 #define YCPMap_h
24 
25 
26 #include "YCPValue.h"
27 #include "ycpless.h"
28 
29 
30 // Only for backwards compatibility. See mail from aschnell on yast-devel on
31 // 2009-01-07. http://lists.opensuse.org/yast-devel/2009-01/msg00016.html
32 typedef map<YCPValue, YCPValue, ycp_less> YCPValueYCPValueMap;
33 class YCPMapIterator;
34 
35 
45 class YCPMapRep : public YCPValueRep
46 {
47 private:
48 
50 
51 protected:
52 
53  typedef YCPValueYCPValueMap::iterator iterator;
54  typedef YCPValueYCPValueMap::const_iterator const_iterator;
55  typedef YCPValueYCPValueMap::value_type value_type;
56  typedef YCPValueYCPValueMap::const_reference const_reference;
57  typedef YCPValueYCPValueMap::key_compare key_compare;
58 
59  friend class YCPMap;
60 
64  YCPMapRep();
65 
70 
71 public:
72 
78  void add(const YCPValue& key, const YCPValue& value);
79 
84  YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const;
85 
91  virtual const YCPElementRep* shallowCopy() const;
92 
96  void remove(const YCPValue& key);
97 
101  bool isEmpty() const;
102 
106  long size() const;
107 
111  bool hasKey(const YCPValue& key) const;
112 
117  YCPValue value(const YCPValue& key) const;
118 
123  YCPMapIterator begin() const;
124 
129  YCPMapIterator end() const;
130 
141  YCPOrder compare(const YCPMap &v) const;
142 
148  string toString() const;
149 
153  std::ostream & toStream (std::ostream & str) const;
154  std::ostream & toXml (std::ostream & str, int indent ) const;
155 
159  YCPValueType valuetype() const;
160 };
161 
162 
163 // Only for backwards compatibility. See mail from aschnell on yast-devel on
164 // 2009-01-07. http://lists.opensuse.org/yast-devel/2009-01/msg00016.html
165 struct YCPMapIterator : public YCPValueYCPValueMap::const_iterator
166 {
167  YCPMapIterator(YCPValueYCPValueMap::const_iterator it)
168  : YCPValueYCPValueMap::const_iterator(it) {}
169 
170  YCPValue key() const __attribute__ ((deprecated)) { return (*this)->first; }
171  YCPValue value() const __attribute__ ((deprecated)) { return (*this)->second; }
172 };
173 
174 
175 #define CONST_ELEMENT (static_cast<const YCPMapRep*>(element))
176 #define ELEMENT (const_cast<YCPMapRep*>(static_cast<const YCPMapRep*>(this->writeCopy())))
177 
184 class YCPMap : public YCPValue
185 {
186  DEF_COW_COMMON(Map, Value);
187 
188 public:
189 
195 
196  YCPMap() : YCPValue(new YCPMapRep()) {}
198 
199  void add(const YCPValue& key, const YCPValue& value) { ELEMENT->add (key,value); }
200  YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const { return CONST_ELEMENT-> functionalAdd (key,value); }
201  void remove(const YCPValue& key) { ELEMENT-> remove (key); }
202  bool isEmpty() const { return CONST_ELEMENT->isEmpty(); }
203  long size() const { return CONST_ELEMENT-> size (); }
204  bool hasKey(const YCPValue& key) const { return CONST_ELEMENT->hasKey(key); }
205  YCPValue value(const YCPValue& key) const { return CONST_ELEMENT-> value (key); }
206  YCPMapIterator begin() const { return CONST_ELEMENT-> begin (); }
207  YCPMapIterator end() const { return CONST_ELEMENT-> end (); }
208 };
209 
210 #undef ELEMENT
211 #undef CONST_ELEMENT
212 
213 #endif // YCPMap_h
DEF_COW_COMMON(Map, Value)
YCPValueYCPValueMap stl_map
Definition: YCPMap.h:49
void add(const YCPValue &key, const YCPValue &value)
Definition: YCPMap.cc:50
YCPMap()
Definition: YCPMap.h:196
bool hasKey(const YCPValue &key) const
Definition: YCPMap.cc:141
#define str
Definition: scanner.cc:997
void add(const YCPValue &key, const YCPValue &value)
Definition: YCPMap.h:199
YCPMapRep::value_type value_type
Definition: YCPMap.h:192
~YCPMapRep()
Definition: YCPMap.h:69
YCPValue value(const YCPValue &key) const
Definition: YCPMap.h:205
YCPMapIterator(YCPValueYCPValueMap::const_iterator it)
Definition: YCPMap.h:167
map< YCPValue, YCPValue, ycp_less > YCPValueYCPValueMap
Definition: YCPMap.h:32
A mapping from keys to values. A map is also called assiciative array. It is a mapping from a set of ...
Definition: YCPMap.h:45
YCPValueYCPValueMap::value_type value_type
Definition: YCPMap.h:55
bool isEmpty() const
Definition: YCPMap.h:202
bool hasKey(const YCPValue &key) const
Definition: YCPMap.h:204
Definition: YCPMap.h:165
YCPMapIterator end() const
Definition: YCPMap.h:207
string toString() const
Definition: YCPMap.cc:202
YCPValueType
Value Type Defines constants for the Value types. The Value type specifies the class the YCPValueRep ...
Definition: YCPValue.h:36
YCPMapRep()
Definition: YCPMap.cc:30
YCPValueType valuetype() const
Definition: YCPMap.cc:219
YCPMap functionalAdd(const YCPValue &key, const YCPValue &value) const
Definition: YCPMap.h:200
Wrapper for YCPMapRep This class realizes an automatic memory management via YCPElement. Access the functionality of YCPMapRep with the arrow operator. See YCPMapRep.
Definition: YCPMap.h:184
std::ostream & toXml(std::ostream &str, int indent) const
Definition: YCPMap.cc:244
YCPValue key() const __attribute__((deprecated))
Definition: YCPMap.h:170
long size() const
Definition: YCPMap.h:203
YCPMapIterator begin() const
Definition: YCPMap.cc:36
virtual const YCPElementRep * shallowCopy() const
Definition: YCPMap.cc:115
YCPMapIterator end() const
Definition: YCPMap.cc:43
YCPMapRep::const_reference const_reference
Definition: YCPMap.h:193
YCPOrder
Definition: YCPValue.h:57
YCPOrder compare(const YCPMap &v) const
Definition: YCPMap.cc:160
YCPMapRep::const_iterator const_iterator
Definition: YCPMap.h:191
YCPValueYCPValueMap::iterator iterator
Definition: YCPMap.h:53
YCPValue value(const YCPValue &key) const
Definition: YCPMap.cc:148
Abstract base class of all YCP values. Abstract base class of all YCP elements that can be used as pr...
Definition: YCPValue.h:71
Abstract base class of all YCP elements.
Definition: YCPElement.h:222
#define CONST_ELEMENT
Definition: YCPMap.h:175
#define ELEMENT
Definition: YCPMap.h:176
YCPMapIterator begin() const
Definition: YCPMap.h:206
YCPMapRep::iterator iterator
Definition: YCPMap.h:190
YCPValueYCPValueMap::const_reference const_reference
Definition: YCPMap.h:56
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
YCPValue value() const __attribute__((deprecated))
Definition: YCPMap.h:171
std::ostream & toStream(std::ostream &str) const
Definition: YCPMap.cc:229
long size() const
Definition: YCPMap.cc:134
YCPMapRep::key_compare key_compare
Definition: YCPMap.h:194
An istream that remembers some data about the bytecode.
Definition: Bytecode.h:42
bool isEmpty() const
Definition: YCPMap.cc:127
YCPValueYCPValueMap::key_compare key_compare
Definition: YCPMap.h:57
YCPMap functionalAdd(const YCPValue &key, const YCPValue &value) const
Definition: YCPMap.cc:79
YCPValueYCPValueMap::const_iterator const_iterator
Definition: YCPMap.h:54

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