diff -r 2ff283124dfc -r ebcc93ead7da lemon/lemon_reader.h --- a/lemon/lemon_reader.h Mon Mar 06 10:28:37 2006 +0000 +++ b/lemon/lemon_reader.h Mon Mar 06 17:32:35 2006 +0000 @@ -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 SectionReaders; + typedef std::vector > 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;