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 
00136     YCPValueType valuetype() const;
00137     
00138 
00139 private:
00146     YCPMapIterator findKey(const YCPValue& key) const;
00147 };
00148 
00152 class YCPMapIterator
00153 {
00154     friend class YCPMapRep;
00155 
00156     YCPValueYCPValueMap::const_iterator position;
00157 
00158 protected:
00159     YCPMapIterator(YCPValueYCPValueMap::const_iterator position)
00160         : position(position) {}
00161 
00162 public:
00166     YCPValue key() const { return position->first; }
00167 
00171     YCPValue value() const { return position->second; }
00172 
00176     friend bool operator==(const YCPMapIterator &x, const YCPMapIterator &y) {
00177         return x.position == y.position;
00178     }
00179 
00183     friend bool operator!=(const YCPMapIterator &x, const YCPMapIterator &y) {
00184         return !(x == y);
00185     }
00186 
00190     void operator++() { ++position; }
00191     void operator++(int) { ++position; }
00192 };
00193 
00194 
00195 #define CONST_ELEMENT (static_cast<const YCPMapRep*>(element))
00196 #define ELEMENT (const_cast<YCPMapRep*>(static_cast<const YCPMapRep*>(this->writeCopy())))
00197 
00204 class YCPMap : public YCPValue
00205 {
00206     DEF_COW_COMMON(Map, Value);
00207 public:
00208     YCPMap() : YCPValue(new YCPMapRep()) {}
00209     YCPMap(bytecodeistream & str);
00210 
00211     void add(const YCPValue& key, const YCPValue& value) { ELEMENT->add (key,value); }
00212     YCPMap functionalAdd(const YCPValue& key, const YCPValue& value) const { return CONST_ELEMENT-> functionalAdd (key,value); }
00213     void remove(const YCPValue& key) { ELEMENT-> remove (key); }
00214     long size() const { return CONST_ELEMENT-> size (); }
00215     YCPValue value(const YCPValue& key) const { return CONST_ELEMENT-> value (key); }
00216     YCPMapIterator begin() const { return CONST_ELEMENT-> begin (); }
00217     YCPMapIterator end() const { return CONST_ELEMENT-> end (); }
00218 };
00219 
00220 #undef ELEMENT
00221 #undef CONST_ELEMENT
00222 
00223 #endif   // YCPMap_h

Generated on Fri Jun 16 18:07:45 2006 for yast2-core by  doxygen 1.4.6