[Lemon-commits] Balazs Dezso: Section readers moved to distinct ...

Lemon HG hg at lemon.cs.elte.hu
Fri Jul 4 17:41:42 CEST 2008


details:   http://lemon.cs.elte.hu/hg/lemon/rev/a63ed81c57ba
changeset: 189:a63ed81c57ba
user:      Balazs Dezso <deba [at] inf.elte.hu>
date:      Fri Jul 04 15:21:48 2008 +0200
description:
	Section readers moved to distinct class

diffstat:

1 file changed, 248 insertions(+), 198 deletions(-)
lemon/lgf_reader.h |  446 ++++++++++++++++++++++++++++------------------------

diffs (truncated from 554 to 300 lines):

diff -r 70694e6bdcac -r a63ed81c57ba lemon/lgf_reader.h
--- a/lemon/lgf_reader.h	Thu Jul 03 12:40:04 2008 +0200
+++ b/lemon/lgf_reader.h	Fri Jul 04 15:21:48 2008 +0200
@@ -419,9 +419,7 @@
   /// By default the reader uses the first section in the file of the
   /// proper type. If a section has an optional name, then it can be
   /// selected for reading by giving an optional name parameter to the
-  /// \c nodes(), \c arcs() or \c attributes() functions. The readers
-  /// also can load extra sections with the \c sectionLines() and
-  /// sectionStream() functions.
+  /// \c nodes(), \c arcs() or \c attributes() functions.
   ///
   /// The \c useNodes() and \c useArcs() functions are used to tell the reader
   /// that the nodes or arcs should not be constructed (added to the
@@ -472,9 +470,6 @@
     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
       Attributes;
     Attributes _attributes;
-
-    typedef std::map<std::string, _reader_bits::Section*> Sections;
-    Sections _sections;
 
     bool _use_nodes;
     bool _use_arcs;
@@ -537,7 +532,6 @@
       _arcs_caption = other._arcs_caption;
       _attributes_caption = other._attributes_caption;
 
-      _sections.swap(other._sections);
     }
 
     /// \brief Destructor
@@ -554,11 +548,6 @@
 
       for (typename Attributes::iterator it = _attributes.begin(); 
 	   it != _attributes.end(); ++it) {
-	delete it->second;
-      }
-
-      for (typename Sections::iterator it = _sections.begin(); 
-	   it != _sections.end(); ++it) {
 	delete it->second;
       }
 
@@ -706,83 +695,6 @@
       return *this;
     }
 
-    /// @}
-
-    /// \name Section readers
-    /// @{
-
-    /// \brief Add a section processor with line oriented reading
-    ///
-    /// In the \e LGF file extra sections can be placed, which contain
-    /// any data in arbitrary format. These sections can be read with
-    /// this function line by line. The first parameter is the type
-    /// descriptor of the section, the second is a functor, which
-    /// takes just one \c std::string parameter. At the reading
-    /// process, each line of the section will be given to the functor
-    /// object. However, the empty lines and the comment lines are
-    /// filtered out, and the leading whitespaces are stipped from
-    /// each processed string.
-    ///
-    /// For example let's see a section, which contain several
-    /// integers, which should be inserted into a vector.
-    ///\code
-    ///  @numbers
-    ///  12 45 23
-    ///  4
-    ///  23 6
-    ///\endcode
-    ///
-    /// The functor is implemented as an struct:
-    ///\code
-    ///  struct NumberSection {
-    ///    std::vector<int>& _data;
-    ///    NumberSection(std::vector<int>& data) : _data(data) {}
-    ///    void operator()(const std::string& line) {
-    ///      std::istringstream ls(line);
-    ///      int value;
-    ///      while (ls >> value) _data.push_back(value);
-    ///    }
-    ///  };
-    ///
-    ///  // ...
-    ///
-    ///  reader.sectionLines("numbers", NumberSection(vec));  
-    ///\endcode
-    template <typename Functor>
-    DigraphReader& sectionLines(const std::string& type, Functor functor) {
-      LEMON_ASSERT(!type.empty(), "Type is not empty.");
-      LEMON_ASSERT(_sections.find(type) == _sections.end(), 
-		   "Multiple reading of section.");
-      LEMON_ASSERT(type != "nodes" && type != "arcs" && type != "edges" &&
-		   type != "attributes", "Multiple reading of section.");
-      _sections.insert(std::make_pair(type, 
-        new _reader_bits::LineSection<Functor>(functor)));
-      return *this;
-    }
-
-
-    /// \brief Add a section processor with stream oriented reading
-    ///
-    /// In the \e LGF file extra sections can be placed, which contain
-    /// any data in arbitrary format. These sections can be read
-    /// directly with this function. The first parameter is the type
-    /// of the section, the second is a functor, which takes an \c
-    /// std::istream& and an int& parameter, the latter regard to the
-    /// line number of stream. The functor can read the input while
-    /// the section go on, and the line number should be modified
-    /// accordingly.
-    template <typename Functor>
-    DigraphReader& sectionStream(const std::string& type, Functor functor) {
-      LEMON_ASSERT(!type.empty(), "Type is not empty.");
-      LEMON_ASSERT(_sections.find(type) == _sections.end(), 
-		   "Multiple reading of section.");
-      LEMON_ASSERT(type != "nodes" && type != "arcs" && type != "edges" &&
-		   type != "attributes", "Multiple reading of section.");
-      _sections.insert(std::make_pair(type, 
-	 new _reader_bits::StreamSection<Functor>(functor)));
-      return *this;
-    }    
-    
     /// @}
 
     /// \name Using previously constructed node or arc set
@@ -1188,7 +1100,6 @@
       bool nodes_done = _skip_nodes;
       bool arcs_done = _skip_arcs;
       bool attributes_done = false;
-      std::set<std::string> extra_sections;
 
       line_num = 0;      
       readLine();
@@ -1222,16 +1133,6 @@
 	      attributes_done = true;
 	    }
 	  } else {
-	    if (extra_sections.find(section) != extra_sections.end()) {
-	      std::ostringstream msg;
-	      msg << "Multiple occurence of section " << section;
-	      throw DataFormatError(msg.str().c_str());
-	    }
-	    Sections::iterator it = _sections.find(section);
-	    if (it != _sections.end()) {
-	      extra_sections.insert(section);
-	      it->second->process(*_is, line_num);
-	    }
 	    readLine();
 	    skipSection();
 	  }
@@ -1295,7 +1196,6 @@
     
   private:
 
-
     std::istream* _is;
     bool local_is;
 
@@ -1321,9 +1221,6 @@
     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
       Attributes;
     Attributes _attributes;
-
-    typedef std::map<std::string, _reader_bits::Section*> Sections;
-    Sections _sections;
 
     bool _use_nodes;
     bool _use_edges;
@@ -1386,7 +1283,6 @@
       _edges_caption = other._edges_caption;
       _attributes_caption = other._attributes_caption;
 
-      _sections.swap(other._sections);
     }
 
     /// \brief Destructor
@@ -1403,11 +1299,6 @@
 
       for (typename Attributes::iterator it = _attributes.begin(); 
 	   it != _attributes.end(); ++it) {
-	delete it->second;
-      }
-
-      for (typename Sections::iterator it = _sections.begin(); 
-	   it != _sections.end(); ++it) {
 	delete it->second;
       }
 
@@ -1601,83 +1492,6 @@
       return *this;
     }
 
-    /// @}
-
-    /// \name Section readers
-    /// @{
-
-    /// \brief Add a section processor with line oriented reading
-    ///
-    /// In the \e LGF file extra sections can be placed, which contain
-    /// any data in arbitrary format. These sections can be read with
-    /// this function line by line. The first parameter is the type
-    /// descriptor of the section, the second is a functor, which
-    /// takes just one \c std::string parameter. At the reading
-    /// process, each line of the section will be given to the functor
-    /// object. However, the empty lines and the comment lines are
-    /// filtered out, and the leading whitespaces are stipped from
-    /// each processed string.
-    ///
-    /// For example let's see a section, which contain several
-    /// integers, which should be inserted into a vector.
-    ///\code
-    ///  @numbers
-    ///  12 45 23
-    ///  4
-    ///  23 6
-    ///\endcode
-    ///
-    /// The functor is implemented as an struct:
-    ///\code
-    ///  struct NumberSection {
-    ///    std::vector<int>& _data;
-    ///    NumberSection(std::vector<int>& data) : _data(data) {}
-    ///    void operator()(const std::string& line) {
-    ///      std::istringstream ls(line);
-    ///      int value;
-    ///      while (ls >> value) _data.push_back(value);
-    ///    }
-    ///  };
-    ///
-    ///  // ...
-    ///
-    ///  reader.sectionLines("numbers", NumberSection(vec));  
-    ///\endcode
-    template <typename Functor>
-    GraphReader& sectionLines(const std::string& type, Functor functor) {
-      LEMON_ASSERT(!type.empty(), "Type is not empty.");
-      LEMON_ASSERT(_sections.find(type) == _sections.end(), 
-		   "Multiple reading of section.");
-      LEMON_ASSERT(type != "nodes" && type != "arcs" && type != "edges" &&
-		   type != "attributes", "Multiple reading of section.");
-      _sections.insert(std::make_pair(type, 
-        new _reader_bits::LineSection<Functor>(functor)));
-      return *this;
-    }
-
-
-    /// \brief Add a section processor with stream oriented reading
-    ///
-    /// In the \e LGF file extra sections can be placed, which contain
-    /// any data in arbitrary format. These sections can be read
-    /// directly with this function. The first parameter is the type
-    /// of the section, the second is a functor, which takes an \c
-    /// std::istream& and an int& parameter, the latter regard to the
-    /// line number of stream. The functor can read the input while
-    /// the section go on, and the line number should be modified
-    /// accordingly.
-    template <typename Functor>
-    GraphReader& sectionStream(const std::string& type, Functor functor) {
-      LEMON_ASSERT(!type.empty(), "Type is not empty.");
-      LEMON_ASSERT(_sections.find(type) == _sections.end(), 
-		   "Multiple reading of section.");
-      LEMON_ASSERT(type != "nodes" && type != "arcs" && type != "edges" &&
-		   type != "attributes", "Multiple reading of section.");
-      _sections.insert(std::make_pair(type, 
-	 new _reader_bits::StreamSection<Functor>(functor)));
-      return *this;
-    }    
-    
     /// @}
 
     /// \name Using previously constructed node or edge set
@@ -2081,7 +1895,6 @@
       bool nodes_done = _skip_nodes;
       bool edges_done = _skip_edges;
       bool attributes_done = false;
-      std::set<std::string> extra_sections;
 
       line_num = 0;      
       readLine();
@@ -2115,16 +1928,6 @@
 	      attributes_done = true;
 	    }
 	  } else {
-	    if (extra_sections.find(section) != extra_sections.end()) {
-	      std::ostringstream msg;
-	      msg << "Multiple occurence of section " << section;
-	      throw DataFormatError(msg.str().c_str());
-	    }
-	    Sections::iterator it = _sections.find(section);
-	    if (it != _sections.end()) {
-	      extra_sections.insert(section);
-	      it->second->process(*_is, line_num);
-	    }
 	    readLine();
 	    skipSection();
 	  }



More information about the Lemon-commits mailing list