yast2-core

YCPMap.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |  
00003 |                      __   __    ____ _____ ____                      |  
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |  
00005 |                       \ V / _` \___ \ | |   __) |                    |  
00006 |                        | | (_| |___) || |  / __/                     |  
00007 |                        |_|\__,_|____/ |_| |_____|                    |  
00008 |                                                                      |  
00009 |                               core system                            | 
00010 |                                                        (C) SuSE GmbH |  
00011 \----------------------------------------------------------------------/ 
00012 
00013    File:        YCPMap.h
00014 
00015    Authors:     Mathias Kettner <kettner@suse.de>
00016                 Arvin Schnell <aschnell@suse.de>
00017    Maintainer:  Thomas Roelz <tom@suse.de>
00018 
00019 /-*/
00020 // -*- c++ -*-
00021 
00022 #ifndef YCPMap_h
00023 #define YCPMap_h
00024 
00025 
00026 #include "YCPValue.h"
00027 #include "ycpless.h"
00028 
00029 
00030 // Only for backwards compatibility. See mail from aschnell on yast-devel on
00031 // 2009-01-07. http://lists.opensuse.org/yast-devel/2009-01/msg00016.html
00032 typedef map<YCPValue, YCPValue, ycp_less> YCPValueYCPValueMap;
00033 class YCPMapIterator;
00034  
00035 
00045 class YCPMapRep : public YCPValueRep
00046 {
00047 private:
00048 
00049     YCPValueYCPValueMap stl_map;
00050 
00051 protected:
00052 
00053     typedef YCPValueYCPValueMap::iterator iterator;
00054     typedef YCPValueYCPValueMap::const_iterator const_iterator;
00055     typedef YCPValueYCPValueMap::value_type value_type;
00056     typedef YCPValueYCPValueMap::const_reference const_reference;
00057     typedef YCPValueYCPValueMap::key_compare key_compare;
00058 
00059     friend class YCPMap;
00060 
00064     YCPMapRep();
00065 
00069     ~YCPMapRep() {}
00070 
00071 public:
00072 
00078     void add(const YCPValue& key, const YCPValue& value);
00079 
00084     YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const;
00085 
00091     virtual const YCPElementRep* shallowCopy() const;
00092 
00096     void remove(const YCPValue& key);
00097 
00101     bool isEmpty() const;
00102 
00106     long size() const;
00107 
00111     bool hasKey(const YCPValue& key) const;
00112 
00117     YCPValue value(const YCPValue& key) const;
00118 
00123     YCPMapIterator begin() const;
00124 
00129     YCPMapIterator end() const;
00130 
00141     YCPOrder compare(const YCPMap &v) const;
00142         
00148     string toString() const;
00149 
00153     std::ostream & toStream (std::ostream & str) const;
00154     std::ostream & toXml (std::ostream & str, int indent ) const;
00155 
00159     YCPValueType valuetype() const;
00160 };
00161 
00162 
00163 // Only for backwards compatibility. See mail from aschnell on yast-devel on
00164 // 2009-01-07. http://lists.opensuse.org/yast-devel/2009-01/msg00016.html
00165 struct YCPMapIterator : public YCPValueYCPValueMap::const_iterator
00166 {
00167     YCPMapIterator(YCPValueYCPValueMap::const_iterator it)
00168         : YCPValueYCPValueMap::const_iterator(it) {}
00169 
00170     YCPValue key() const __attribute__ ((deprecated)) { return (*this)->first; }
00171     YCPValue value() const __attribute__ ((deprecated)) { return (*this)->second; }
00172 };
00173 
00174 
00175 #define CONST_ELEMENT (static_cast<const YCPMapRep*>(element))
00176 #define ELEMENT (const_cast<YCPMapRep*>(static_cast<const YCPMapRep*>(this->writeCopy())))
00177 
00184 class YCPMap : public YCPValue
00185 {
00186     DEF_COW_COMMON(Map, Value);
00187 
00188 public:
00189 
00190     typedef YCPMapRep::iterator iterator;
00191     typedef YCPMapRep::const_iterator const_iterator;
00192     typedef YCPMapRep::value_type value_type;
00193     typedef YCPMapRep::const_reference const_reference;
00194     typedef YCPMapRep::key_compare key_compare;
00195 
00196     YCPMap() : YCPValue(new YCPMapRep()) {}
00197     YCPMap(bytecodeistream & str);
00198 
00199     void add(const YCPValue& key, const YCPValue& value) { ELEMENT->add (key,value); }
00200     YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const { return CONST_ELEMENT-> functionalAdd (key,value); }
00201     void remove(const YCPValue& key) { ELEMENT-> remove (key); }
00202     bool isEmpty() const { return CONST_ELEMENT->isEmpty(); }
00203     long size() const { return CONST_ELEMENT-> size (); }
00204     bool hasKey(const YCPValue& key) const { return CONST_ELEMENT->hasKey(key); }
00205     YCPValue value(const YCPValue& key) const { return CONST_ELEMENT-> value (key); }
00206     YCPMapIterator begin() const { return CONST_ELEMENT-> begin (); }
00207     YCPMapIterator end() const { return CONST_ELEMENT-> end (); }
00208 };
00209 
00210 #undef ELEMENT
00211 #undef CONST_ELEMENT
00212 
00213 #endif   // YCPMap_h

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