lemon/lgf_reader.h
changeset 179 289266783a0b
parent 174 2ec3c1bbc687
child 180 4b9ab1324c3b
equal deleted inserted replaced
10:6172a468e27d 11:8e5a68e13419
  2068     return tmp;
  2068     return tmp;
  2069   }
  2069   }
  2070 
  2070 
  2071   /// \ingroup lemon_io
  2071   /// \ingroup lemon_io
  2072   ///
  2072   ///
  2073   /// \brief Reader for the content of the \ref lgf-format "LGF" file 
  2073   /// \brief Reader for the contents of the \ref lgf-format "LGF" file 
  2074   ///
  2074   ///
  2075   /// This class can be used to read the sections, the map names and
  2075   /// This class can be used to read the sections, the map names and
  2076   /// the attributes from a file. Usually, the Lemon programs know
  2076   /// the attributes from a file. Usually, the Lemon programs know
  2077   /// that, which type of graph, which maps and which attributes
  2077   /// that, which type of graph, which maps and which attributes
  2078   /// should be read from a file, but in general tools (like glemon)
  2078   /// should be read from a file, but in general tools (like glemon)
  2079   /// the content of an LGF file should be guessed somehow. This class
  2079   /// the contents of an LGF file should be guessed somehow. This class
  2080   /// reads the graph and stores the appropriate information for
  2080   /// reads the graph and stores the appropriate information for
  2081   /// reading the graph.
  2081   /// reading the graph.
  2082   ///
  2082   ///
  2083   ///\code LgfContent content("graph.lgf"); 
  2083   ///\code LgfContents contents("graph.lgf"); 
  2084   /// content.run();
  2084   /// contents.run();
  2085   ///
  2085   ///
  2086   /// // does it contain any node section and arc section
  2086   /// // does it contain any node section and arc section
  2087   /// if (content.nodeSectionNum() == 0 || content.arcSectionNum()) {
  2087   /// if (contents.nodeSectionNum() == 0 || contents.arcSectionNum()) {
  2088   ///   std::cerr << "Failure, cannot find graph" << std::endl;
  2088   ///   std::cerr << "Failure, cannot find graph" << std::endl;
  2089   ///   return -1;
  2089   ///   return -1;
  2090   /// }
  2090   /// }
  2091   /// std::cout << "The name of the default node section : " 
  2091   /// std::cout << "The name of the default node section : " 
  2092   ///           << content.nodeSection(0) << std::endl;
  2092   ///           << contents.nodeSection(0) << std::endl;
  2093   /// std::cout << "The number of the arc maps : " 
  2093   /// std::cout << "The number of the arc maps : " 
  2094   ///           << content.arcMaps(0).size() << std::endl;
  2094   ///           << contents.arcMaps(0).size() << std::endl;
  2095   /// std::cout << "The name of second arc map : " 
  2095   /// std::cout << "The name of second arc map : " 
  2096   ///           << content.arcMaps(0)[1] << std::endl;
  2096   ///           << contents.arcMaps(0)[1] << std::endl;
  2097   ///\endcode
  2097   ///\endcode
  2098   class LgfContent {    
  2098   class LgfContents {    
  2099   private:
  2099   private:
  2100 
  2100 
  2101     std::istream* _is;
  2101     std::istream* _is;
  2102     bool local_is;
  2102     bool local_is;
  2103 
  2103 
  2119     
  2119     
  2120   public:
  2120   public:
  2121 
  2121 
  2122     /// \brief Constructor
  2122     /// \brief Constructor
  2123     ///
  2123     ///
  2124     /// Construct an \e LGF content reader, which reads from the given
  2124     /// Construct an \e LGF contents reader, which reads from the given
  2125     /// input stream.
  2125     /// input stream.
  2126     LgfContent(std::istream& is) 
  2126     LgfContents(std::istream& is) 
  2127       : _is(&is), local_is(false) {}
  2127       : _is(&is), local_is(false) {}
  2128 
  2128 
  2129     /// \brief Constructor
  2129     /// \brief Constructor
  2130     ///
  2130     ///
  2131     /// Construct an \e LGF content reader, which reads from the given
  2131     /// Construct an \e LGF contents reader, which reads from the given
  2132     /// file.
  2132     /// file.
  2133     LgfContent(const std::string& fn) 
  2133     LgfContents(const std::string& fn) 
  2134       : _is(new std::ifstream(fn.c_str())), local_is(true) {}
  2134       : _is(new std::ifstream(fn.c_str())), local_is(true) {}
  2135 
  2135 
  2136     /// \brief Constructor
  2136     /// \brief Constructor
  2137     ///
  2137     ///
  2138     /// Construct an \e LGF content reader, which reads from the given
  2138     /// Construct an \e LGF contents reader, which reads from the given
  2139     /// file.
  2139     /// file.
  2140     LgfContent(const char* fn)
  2140     LgfContents(const char* fn)
  2141       : _is(new std::ifstream(fn)), local_is(true) {}
  2141       : _is(new std::ifstream(fn)), local_is(true) {}
  2142 
  2142 
  2143     /// \brief Copy constructor
  2143     /// \brief Copy constructor
  2144     ///
  2144     ///
  2145     /// The copy constructor transfers all data from the other reader,
  2145     /// The copy constructor transfers all data from the other reader,
  2146     /// therefore the copied reader will not be usable more. 
  2146     /// therefore the copied reader will not be usable more. 
  2147     LgfContent(LgfContent& other)
  2147     LgfContents(LgfContents& other)
  2148       : _is(other._is), local_is(other.local_is) {
  2148       : _is(other._is), local_is(other.local_is) {
  2149       
  2149       
  2150       other._is = 0;
  2150       other._is = 0;
  2151       other.local_is = false;
  2151       other.local_is = false;
  2152       
  2152       
  2161       _edge_maps.swap(other._edge_maps);
  2161       _edge_maps.swap(other._edge_maps);
  2162       _attributes.swap(other._attributes);
  2162       _attributes.swap(other._attributes);
  2163     }
  2163     }
  2164     
  2164     
  2165     /// \brief Destructor
  2165     /// \brief Destructor
  2166     ~LgfContent() {
  2166     ~LgfContents() {
  2167       if (local_is) delete _is;
  2167       if (local_is) delete _is;
  2168     }
  2168     }
  2169 
  2169 
  2170 
  2170 
  2171     /// \name Node sections
  2171     /// \name Node sections
  2357       line.putback(c);
  2357       line.putback(c);
  2358     }
  2358     }
  2359 
  2359 
  2360   public:
  2360   public:
  2361 
  2361 
  2362     /// \name Execution of the content reader    
  2362     /// \name Execution of the contents reader    
  2363     /// @{
  2363     /// @{
  2364 
  2364 
  2365     /// \brief Start the reading
  2365     /// \brief Start the reading
  2366     ///
  2366     ///
  2367     /// This function starts the reading
  2367     /// This function starts the reading