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    Author:     Mathias Kettner <kettner@suse.de>
00016    Maintainer: Thomas Roelz <tom@suse.de>
00017 
00018 /-*/
00019 // -*- c++ -*-
00020 
00021 #ifndef YCPMap_h
00022 #define YCPMap_h
00023 
00024 
00025 #include "YCPValue.h"
00026 #include "ycpless.h"
00027 
00028 
00029 typedef map<YCPValue, YCPValue, ycpless> YCPValueYCPValueMap;
00030 class YCPMapIterator;
00031  
00041 class YCPMapRep : public YCPValueRep
00042 {
00043     YCPValueYCPValueMap stl_map;
00044 
00045 protected:
00046     friend class YCPMap;
00047 
00051     YCPMapRep();
00052 
00056     ~YCPMapRep() {}
00057 
00058 public:
00064     void add(const YCPValue& key, const YCPValue& value);
00065 
00070     YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const;
00071 
00077     virtual const YCPElementRep* shallowCopy() const;
00078 
00082     void remove(const YCPValue& key);
00083 
00087     long size() const;
00088 
00093     YCPValue value(const YCPValue& key) const;
00094 
00100     YCPMapIterator begin() const;
00101 
00107     YCPMapIterator end() const;
00108 
00119     YCPOrder compare(const YCPMap &v) const;
00120         
00126     string toString() const;
00127 
00131     std::ostream & toStream (std::ostream & str) const;
00132     std::ostream & toXml (std::ostream & str, int indent ) const;
00133 
00137     YCPValueType valuetype() const;
00138     
00139 
00140 private:
00147     YCPMapIterator findKey(const YCPValue& key) const;
00148 };
00149 
00153 class YCPMapIterator
00154 {
00155     friend class YCPMapRep;
00156 
00157     YCPValueYCPValueMap::const_iterator position;
00158 
00159 protected:
00160     YCPMapIterator(YCPValueYCPValueMap::const_iterator position)
00161         : position(position) {}
00162 
00163 public:
00167     YCPValue key() const { return position->first; }
00168 
00172     YCPValue value() const { return position->second; }
00173 
00177     friend bool operator==(const YCPMapIterator &x, const YCPMapIterator &y) {
00178         return x.position == y.position;
00179     }
00180 
00184     friend bool operator!=(const YCPMapIterator &x, const YCPMapIterator &y) {
00185         return !(x == y);
00186     }
00187 
00191     void operator++() { ++position; }
00192     void operator++(int) { ++position; }
00193 };
00194 
00195 
00196 #define CONST_ELEMENT (static_cast<const YCPMapRep*>(element))
00197 #define ELEMENT (const_cast<YCPMapRep*>(static_cast<const YCPMapRep*>(this->writeCopy())))
00198 
00205 class YCPMap : public YCPValue
00206 {
00207     DEF_COW_COMMON(Map, Value);
00208 public:
00209     YCPMap() : YCPValue(new YCPMapRep()) {}
00210     YCPMap(bytecodeistream & str);
00211 
00212     void add(const YCPValue& key, const YCPValue& value) { ELEMENT->add (key,value); }
00213     YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const { return CONST_ELEMENT-> functionalAdd (key,value); }
00214     void remove(const YCPValue& key) { ELEMENT-> remove (key); }
00215     long size() const { return CONST_ELEMENT-> size (); }
00216     YCPValue value(const YCPValue& key) const { return CONST_ELEMENT-> value (key); }
00217     YCPMapIterator begin() const { return CONST_ELEMENT-> begin (); }
00218     YCPMapIterator end() const { return CONST_ELEMENT-> end (); }
00219 };
00220 
00221 #undef ELEMENT
00222 #undef CONST_ELEMENT
00223 
00224 #endif   // YCPMap_h

Generated on Tue Nov 6 01:27:46 2007 for yast2-core by  doxygen 1.5.3