r5240@piscolita: duncan | 2007-05-02 19:08:37 +0200
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Sun, 6 May 2007 16:05:19 +0000 (16:05 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Sun, 6 May 2007 16:05:19 +0000 (16:05 +0000)
 Dictionary wrapper over ini parser, and test

zypp/parser/IniDict.cc [new file with mode: 0644]
zypp/parser/IniDict.h [new file with mode: 0644]

diff --git a/zypp/parser/IniDict.cc b/zypp/parser/IniDict.cc
new file mode 100644 (file)
index 0000000..b3ac336
--- /dev/null
@@ -0,0 +1,75 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/parser/IniDict.cc
+ *
+*/
+#include <iostream>
+//#include "zypp/base/Logger.h"
+#include <map>
+#include <string>
+#include "zypp/parser/IniDict.h"
+
+using namespace std;
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace parser
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : IniDict
+    //
+    ///////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // METHOD NAME : IniDict::IniDict
+    // METHOD TYPE : Ctor
+    //
+    IniDict::IniDict( const InputStream &is )
+    {
+      parse(is);
+    }
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // METHOD NAME : IniDict::~IniDict
+    // METHOD TYPE : Dtor
+    //
+    IniDict::~IniDict()
+    {}
+
+    void IniDict::consume( const std::string &section )
+    {
+      // do nothing for now.
+    }
+
+    void IniDict::consume( const std::string &section, const std::string &key, const std::string &value )
+    {
+      _dict[section][key] = value;
+    }
+
+
+    /******************************************************************
+    **
+    ** FUNCTION NAME : operator<<
+    ** FUNCTION TYPE : std::ostream &
+    */
+    std::ostream & operator<<( std::ostream & str, const IniDict & obj )
+    {
+      return str;
+    }
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace parser
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/parser/IniDict.h b/zypp/parser/IniDict.h
new file mode 100644 (file)
index 0000000..2274f20
--- /dev/null
@@ -0,0 +1,67 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/parser/IniDict.h
+ *
+*/
+#ifndef ZYPP_PARSER_INIDICT_H
+#define ZYPP_PARSER_INIDICT_H
+
+#include <iosfwd>
+#include <map>
+#include <string>
+
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/InputStream.h"
+#include "zypp/parser/IniParser.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace parser
+  { /////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : IniDict
+    //
+    /**
+     * 
+     */
+    class IniDict : public IniParser
+    {
+      friend std::ostream & operator<<( std::ostream & str, const IniDict & obj );
+    public:
+      /** Default ctor */
+      IniDict( const InputStream &is );
+      /** Dtor */
+      ~IniDict();
+
+    public:
+
+      /** Called when a section is found. */
+      virtual void consume( const std::string &section );
+      /** Called when a key value is found. */
+      virtual void consume( const std::string &section, const std::string &key, const std::string &value );
+
+    private:
+      std::map<std::string, std::map<std::string, std::string> > _dict;
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    /** \relates IniDict Stream output */
+    std::ostream & operator<<( std::ostream & str, const IniDict & obj );
+
+    /////////////////////////////////////////////////////////////////
+  } // namespace parser
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_PARSER_INIDICT_H