[Lemon-commits] [lemon_svn] deba: r2610 - in hugo/trunk: lemon test

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 20:53:54 CET 2006


Author: deba
Date: Mon Mar  6 18:32:35 2006
New Revision: 2610

Modified:
   hugo/trunk/lemon/lemon_reader.h
   hugo/trunk/test/dijkstra_test.lgf

Log:
Checking missing section reader




Modified: hugo/trunk/lemon/lemon_reader.h
==============================================================================
--- hugo/trunk/lemon/lemon_reader.h	(original)
+++ hugo/trunk/lemon/lemon_reader.h	Mon Mar  6 18:32:35 2006
@@ -651,6 +651,11 @@
       ///
       /// It reads the content of the section.
       virtual void read(std::istream& is) = 0;
+
+      /// \brief The given section missing in the file.
+      ///
+      /// The given section missing in the file.
+      virtual void missing() {};
     };
 
     /// \brief Constructor for LemonReader.
@@ -684,7 +689,7 @@
     void operator=(const LemonReader&);
 
     void attach(SectionReader& reader) {
-      readers.push_back(&reader);
+      readers.push_back(std::make_pair(&reader, false));
     }
 
   public:
@@ -695,19 +700,25 @@
       int line_num = 0;
       std::string line;
       try {
+        SectionReaders::iterator it;
 	while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
-	  SectionReaders::iterator it;
 	  for (it = readers.begin(); it != readers.end(); ++it) {
-	    if ((*it)->header(line)) {
+	    if (it->first->header(line)) {
+              it->second = true;
 	      char buf[2048];
 	      FilterStreamBuf buffer(*is, line_num);
 	      buffer.pubsetbuf(buf, sizeof(buf));
 	      std::istream is(&buffer);
-	      (*it)->read(is);
+	      it->first->read(is);
 	      break;
 	    }
 	  }
 	}
+        for (it = readers.begin(); it != readers.end(); ++it) {
+          if (!it->second) {
+            it->first->missing();
+          }
+        }
       } catch (DataFormatError& error) {
 	error.line(line_num);
 	throw error;
@@ -720,7 +731,7 @@
     std::istream* is;
     bool own_is;
 
-    typedef std::vector<SectionReader*> SectionReaders;
+    typedef std::vector<std::pair<SectionReader*, bool> > SectionReaders;
     SectionReaders readers;
 
   };
@@ -906,6 +917,13 @@
       }
     }
 
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "NodeSet section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
+
   public:
 
     /// \brief Returns true if the nodeset can give back the node by its label.
@@ -1134,6 +1152,13 @@
       }
     }
 
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "EdgeSet section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
+
   public:
 
     /// \brief Returns true if the edgeset can give back the edge by its label.
@@ -1430,6 +1455,13 @@
       }
     }
 
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "UEdgeSet section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
+
   public:
 
     /// \brief Returns true if the edgeset can give back the edge by its label.
@@ -1579,6 +1611,13 @@
 	}
       }
     }
+
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "Nodes section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
     
   private:
 
@@ -1685,6 +1724,13 @@
 	}
       }
     }
+
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "Edges section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
     
   private:
 
@@ -1830,6 +1876,13 @@
 	}
       }
     }
+
+    virtual void missing() {
+      if (edgeReaders.empty() && uEdgeReaders.empty()) return;
+      ErrorMessage msg;
+      msg << "UEdges section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
     
   private:
 
@@ -1951,6 +2004,13 @@
       }
     }    
 
+    virtual void missing() {
+      if (readers.empty()) return;
+      ErrorMessage msg;
+      msg << "Attribute section not found in file: " << name;
+      throw IOParameterError(msg.message());
+    }
+
   private:
     std::string name;
 

Modified: hugo/trunk/test/dijkstra_test.lgf
==============================================================================
--- hugo/trunk/test/dijkstra_test.lgf	(original)
+++ hugo/trunk/test/dijkstra_test.lgf	Mon Mar  6 18:32:35 2006
@@ -1000,7 +1000,7 @@
 2	
 1	
 0	
- at edgeset
+ at edgeset 
 		label	capacity	
 75	377	6906	27	
 417	515	6905	69	



More information about the Lemon-commits mailing list