lemon/lemon_reader.h
changeset 2000 ebcc93ead7da
parent 1997 b7a70cdb5520
child 2001 c9e5de6e3eac
     1.1 --- a/lemon/lemon_reader.h	Mon Mar 06 10:28:37 2006 +0000
     1.2 +++ b/lemon/lemon_reader.h	Mon Mar 06 17:32:35 2006 +0000
     1.3 @@ -651,6 +651,11 @@
     1.4        ///
     1.5        /// It reads the content of the section.
     1.6        virtual void read(std::istream& is) = 0;
     1.7 +
     1.8 +      /// \brief The given section missing in the file.
     1.9 +      ///
    1.10 +      /// The given section missing in the file.
    1.11 +      virtual void missing() {};
    1.12      };
    1.13  
    1.14      /// \brief Constructor for LemonReader.
    1.15 @@ -684,7 +689,7 @@
    1.16      void operator=(const LemonReader&);
    1.17  
    1.18      void attach(SectionReader& reader) {
    1.19 -      readers.push_back(&reader);
    1.20 +      readers.push_back(std::make_pair(&reader, false));
    1.21      }
    1.22  
    1.23    public:
    1.24 @@ -695,19 +700,25 @@
    1.25        int line_num = 0;
    1.26        std::string line;
    1.27        try {
    1.28 +        SectionReaders::iterator it;
    1.29  	while ((++line_num, getline(*is, line)) && line.find("@end") != 0) {
    1.30 -	  SectionReaders::iterator it;
    1.31  	  for (it = readers.begin(); it != readers.end(); ++it) {
    1.32 -	    if ((*it)->header(line)) {
    1.33 +	    if (it->first->header(line)) {
    1.34 +              it->second = true;
    1.35  	      char buf[2048];
    1.36  	      FilterStreamBuf buffer(*is, line_num);
    1.37  	      buffer.pubsetbuf(buf, sizeof(buf));
    1.38  	      std::istream is(&buffer);
    1.39 -	      (*it)->read(is);
    1.40 +	      it->first->read(is);
    1.41  	      break;
    1.42  	    }
    1.43  	  }
    1.44  	}
    1.45 +        for (it = readers.begin(); it != readers.end(); ++it) {
    1.46 +          if (!it->second) {
    1.47 +            it->first->missing();
    1.48 +          }
    1.49 +        }
    1.50        } catch (DataFormatError& error) {
    1.51  	error.line(line_num);
    1.52  	throw error;
    1.53 @@ -720,7 +731,7 @@
    1.54      std::istream* is;
    1.55      bool own_is;
    1.56  
    1.57 -    typedef std::vector<SectionReader*> SectionReaders;
    1.58 +    typedef std::vector<std::pair<SectionReader*, bool> > SectionReaders;
    1.59      SectionReaders readers;
    1.60  
    1.61    };
    1.62 @@ -906,6 +917,13 @@
    1.63        }
    1.64      }
    1.65  
    1.66 +    virtual void missing() {
    1.67 +      if (readers.empty()) return;
    1.68 +      ErrorMessage msg;
    1.69 +      msg << "NodeSet section not found in file: " << name;
    1.70 +      throw IOParameterError(msg.message());
    1.71 +    }
    1.72 +
    1.73    public:
    1.74  
    1.75      /// \brief Returns true if the nodeset can give back the node by its label.
    1.76 @@ -1134,6 +1152,13 @@
    1.77        }
    1.78      }
    1.79  
    1.80 +    virtual void missing() {
    1.81 +      if (readers.empty()) return;
    1.82 +      ErrorMessage msg;
    1.83 +      msg << "EdgeSet section not found in file: " << name;
    1.84 +      throw IOParameterError(msg.message());
    1.85 +    }
    1.86 +
    1.87    public:
    1.88  
    1.89      /// \brief Returns true if the edgeset can give back the edge by its label.
    1.90 @@ -1430,6 +1455,13 @@
    1.91        }
    1.92      }
    1.93  
    1.94 +    virtual void missing() {
    1.95 +      if (readers.empty()) return;
    1.96 +      ErrorMessage msg;
    1.97 +      msg << "UEdgeSet section not found in file: " << name;
    1.98 +      throw IOParameterError(msg.message());
    1.99 +    }
   1.100 +
   1.101    public:
   1.102  
   1.103      /// \brief Returns true if the edgeset can give back the edge by its label.
   1.104 @@ -1579,6 +1611,13 @@
   1.105  	}
   1.106        }
   1.107      }
   1.108 +
   1.109 +    virtual void missing() {
   1.110 +      if (readers.empty()) return;
   1.111 +      ErrorMessage msg;
   1.112 +      msg << "Nodes section not found in file: " << name;
   1.113 +      throw IOParameterError(msg.message());
   1.114 +    }
   1.115      
   1.116    private:
   1.117  
   1.118 @@ -1685,6 +1724,13 @@
   1.119  	}
   1.120        }
   1.121      }
   1.122 +
   1.123 +    virtual void missing() {
   1.124 +      if (readers.empty()) return;
   1.125 +      ErrorMessage msg;
   1.126 +      msg << "Edges section not found in file: " << name;
   1.127 +      throw IOParameterError(msg.message());
   1.128 +    }
   1.129      
   1.130    private:
   1.131  
   1.132 @@ -1830,6 +1876,13 @@
   1.133  	}
   1.134        }
   1.135      }
   1.136 +
   1.137 +    virtual void missing() {
   1.138 +      if (edgeReaders.empty() && uEdgeReaders.empty()) return;
   1.139 +      ErrorMessage msg;
   1.140 +      msg << "UEdges section not found in file: " << name;
   1.141 +      throw IOParameterError(msg.message());
   1.142 +    }
   1.143      
   1.144    private:
   1.145  
   1.146 @@ -1951,6 +2004,13 @@
   1.147        }
   1.148      }    
   1.149  
   1.150 +    virtual void missing() {
   1.151 +      if (readers.empty()) return;
   1.152 +      ErrorMessage msg;
   1.153 +      msg << "Attribute section not found in file: " << name;
   1.154 +      throw IOParameterError(msg.message());
   1.155 +    }
   1.156 +
   1.157    private:
   1.158      std::string name;
   1.159