IniDict.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include <map>
00015 #include <string>
00016 #include "zypp/parser/IniDict.h"
00017 
00018 using namespace std;
00020 namespace zypp
00021 { 
00022 
00023   namespace parser
00024   { 
00025 
00026     //
00027     //  CLASS NAME : IniDict
00028     //
00030 
00032     //
00033     //  METHOD NAME : IniDict::IniDict
00034     //  METHOD TYPE : Ctor
00035     //
00036     IniDict::IniDict( const InputStream &is,
00037                       const ProgressData::ReceiverFnc & progress )
00038     {
00039       read(is, progress );
00040     }
00041 
00042     IniDict::IniDict()
00043     {
00044     }
00045 
00046     void IniDict::read( const InputStream &is,
00047                         const ProgressData::ReceiverFnc & progress )
00048     {
00049       parse(is, progress );
00050     }
00051 
00053     //
00054     //  METHOD NAME : IniDict::~IniDict
00055     //  METHOD TYPE : Dtor
00056     //
00057     IniDict::~IniDict()
00058     {}
00059 
00060     void IniDict::consume( const std::string &section )
00061     {
00062       // do nothing for now.
00063     }
00064 
00065     void IniDict::consume( const std::string &section, const std::string &key, const std::string &value )
00066     {
00067       //MIL << endl;
00068       _dict[section][key] = value;
00069       //MIL << this->size() << endl;
00070     }
00071 
00072 
00073     IniDict::entry_const_iterator IniDict::entriesBegin(const std::string &section) const
00074     {
00075       SectionSet::const_iterator secit = _dict.find(section);
00076       if ( secit == _dict.end() )
00077       {
00078         return _empty_map.begin();
00079       }
00080       
00081       return (secit->second).begin();
00082     }
00083     
00084     IniDict::entry_const_iterator IniDict::entriesEnd(const std::string &section) const
00085     {
00086       SectionSet::const_iterator secit = _dict.find(section);
00087       if ( secit == _dict.end() )
00088       {
00089         return _empty_map.end();
00090       }
00091       
00092       return (secit->second).end();
00093     }
00094     
00095     
00096     IniDict::section_const_iterator IniDict::sectionsBegin() const
00097     {
00098       return make_map_key_begin( _dict );
00099     }
00100     
00101     IniDict::section_const_iterator IniDict::sectionsEnd() const
00102     {
00103       return make_map_key_end( _dict );
00104     }
00105     
00106     void IniDict::insertEntry( const std::string &section,
00107                                const std::string &key,
00108                                const std::string &value )
00109     {
00110       consume( section, key, value );
00111     }
00112       
00113     void IniDict::deleteSection( const std::string &section )
00114     {
00115       _dict.erase(section);
00116     }
00117     
00118     bool IniDict::hasSection( const std::string &section ) const
00119     {
00120       SectionSet::const_iterator secit = _dict.find(section);
00121       if ( secit == _dict.end() )
00122         return false;
00123       return true;
00124     }
00125 
00126     bool IniDict::hasEntry( const std::string &section,
00127                             const std::string &entry ) const
00128     {
00129       SectionSet::const_iterator secit = _dict.find(section);
00130       if ( secit == _dict.end() )
00131         return false;
00132       
00133       EntrySet::const_iterator entryit = (secit->second).find(entry);
00134       if ( entryit == (secit->second).end() )
00135         return false;
00136 
00137       return true;
00138     }
00139 
00140     /******************************************************************
00141     **
00142     **  FUNCTION NAME : operator<<
00143     **  FUNCTION TYPE : std::ostream &
00144     */
00145     std::ostream & operator<<( std::ostream & str, const IniDict & obj )
00146     {
00147       for ( IniDict::section_const_iterator si = obj.sectionsBegin();
00148             si != obj.sectionsEnd();
00149             ++si )
00150       {
00151         str << "[" << *si << "]" << endl;
00152         for ( IniDict::entry_const_iterator ei = obj.entriesBegin(*si);
00153               ei != obj.entriesEnd(*si);
00154               ++ei )
00155         {
00156           str << ei->first << " = " << ei->second << endl;
00157         }
00158         str << endl;
00159       }
00160       return str;
00161     }
00162 
00164   } // namespace parser
00167 } // namespace zypp

Generated on Tue Sep 25 19:23:02 2007 for libzypp by  doxygen 1.5.3