diff -r 469b3f628dd1 -r 78502c63f771 src/lemon/lemon_reader.h --- a/src/lemon/lemon_reader.h Sat May 14 17:40:45 2005 +0000 +++ b/src/lemon/lemon_reader.h Sat May 14 20:56:53 2005 +0000 @@ -1651,5 +1651,296 @@ Readers readers; }; + /// \ingroup io_group + /// \brief SectionReader for retrieve what is in the file. + /// + /// SectionReader for retrieve what is in the file. If you want + /// to know which sections, maps and items are in the file + /// use the next code: + /// \code + /// LemonReader reader("input.lgf"); + /// ContentReader content(reader); + /// reader.run(); + /// \endcode + class ContentReader : public LemonReader::SectionReader { + typedef LemonReader::SectionReader Parent; + public: + /// \brief Constructor. + /// + /// Constructor for + ContentReader(LemonReader& _reader) : Parent(_reader) {} + + /// \brief Desctructor. + /// + /// Desctructor. + virtual ~ContentReader() {} + + /// \brief Gives back how many nodesets are in the file. + /// + /// Gives back how many nodesets are in the file. + int nodeSetNum() const { + return nodesets.size(); + } + + /// \brief Gives back the name of nodeset on the indiced position. + /// + /// Gives back the name of nodeset on the indiced position. + std::string nodeSetName(int index) const { + return nodesets[index].name; + } + + /// \brief Gives back the map names of nodeset on the indiced position. + /// + /// Gives back the map names of nodeset on the indiced position. + const std::vector& nodeSetMaps(int index) const { + return nodesets[index].items; + } + + /// \brief Gives back how many edgesets are in the file. + /// + /// Gives back how many edgesets are in the file. + int edgeSetNum() const { + return edgesets.size(); + } + + /// \brief Gives back the name of edgeset on the indiced position. + /// + /// Gives back the name of edgeset on the indiced position. + std::string edgeSetName(int index) const { + return edgesets[index].name; + } + + /// \brief Gives back the map names of edgeset on the indiced position. + /// + /// Gives back the map names of edgeset on the indiced position. + const std::vector& edgeSetMaps(int index) const { + return edgesets[index].items; + } + + /// \brief Gives back how many undirected edgesets are in the file. + /// + /// Gives back how many undirected edgesets are in the file. + int undirEdgeSetNum() const { + return undiredgesets.size(); + } + + /// \brief Gives back the name of undirected edgeset on the indiced + /// position. + /// + /// Gives back the name of undirected edgeset on the indiced position. + std::string undirEdgeSetName(int index) const { + return undiredgesets[index].name; + } + + /// \brief Gives back the map names of undirected edgeset on the indiced + /// position. + /// + /// Gives back the map names of undirected edgeset on the indiced position. + const std::vector& undirEdgeSetMaps(int index) const { + return undiredgesets[index].items; + } + + /// \brief Gives back how many labeled nodes section are in the file. + /// + /// Gives back how many labeled nodes section are in the file. + int nodesNum() const { + return nodes.size(); + } + + /// \brief Gives back the name of labeled nodes section on the indiced + /// position. + /// + /// Gives back the name of labeled nodes section on the indiced position. + std::string nodesName(int index) const { + return nodes[index].name; + } + + /// \brief Gives back the names of the labeled nodes in the indiced + /// section. + /// + /// Gives back the names of the labeled nodes in the indiced section. + const std::vector& nodesItems(int index) const { + return nodes[index].items; + } + + /// \brief Gives back how many labeled edges section are in the file. + /// + /// Gives back how many labeled edges section are in the file. + int edgesNum() const { + return edges.size(); + } + + /// \brief Gives back the name of labeled edges section on the indiced + /// position. + /// + /// Gives back the name of labeled edges section on the indiced position. + std::string edgesName(int index) const { + return edges[index].name; + } + + /// \brief Gives back the names of the labeled edges in the indiced + /// section. + /// + /// Gives back the names of the labeled edges in the indiced section. + const std::vector& edgesItems(int index) const { + return edges[index].items; + } + + /// \brief Gives back how many labeled undirected edges section are + /// in the file. + /// + /// Gives back how many labeled undirected edges section are in the file. + int undirEdgesNum() const { + return undiredges.size(); + } + + /// \brief Gives back the name of labeled undirected edges section + /// on the indiced position. + /// + /// Gives back the name of labeled undirected edges section on the + /// indiced position. + std::string undirEdgesName(int index) const { + return undiredges[index].name; + } + + /// \brief Gives back the names of the labeled undirected edges in + /// the indiced section. + /// + /// Gives back the names of the labeled undirected edges in the + /// indiced section. + const std::vector& undirEdgesItems(int index) const { + return undiredges[index].items; + } + + + /// \brief Gives back how many attributes section are in the file. + /// + /// Gives back how many attributes section are in the file. + int attributesNum() const { + return attributes.size(); + } + + /// \brief Gives back the name of attributes section on the indiced + /// position. + /// + /// Gives back the name of attributes section on the indiced position. + std::string attributesName(int index) const { + return attributes[index].name; + } + + /// \brief Gives back the names of the attributes in the indiced section. + /// + /// Gives back the names of the attributes in the indiced section. + const std::vector& attributesItems(int index) const { + return attributes[index].items; + } + + const std::vector& otherSections() const { + return sections; + } + + protected: + + /// \brief Gives back true when the SectionReader can process + /// the section with the given header line. + /// + /// It gives back true when the section is common section. + bool header(const std::string& line) { + std::istringstream ls(line); + std::string command, name; + ls >> command >> name; + if (command == "@nodeset") { + current = command; + nodesets.push_back(SectionInfo(name)); + } else if (command == "@edgeset") { + current = command; + edgesets.push_back(SectionInfo(name)); + } else if (command == "@undiredgeset") { + current = command; + undiredgesets.push_back(SectionInfo(name)); + } else if (command == "@nodes") { + current = command; + nodes.push_back(SectionInfo(name)); + } else if (command == "@edges") { + current = command; + edges.push_back(SectionInfo(name)); + } else if (command == "@undiredges") { + current = command; + undiredges.push_back(SectionInfo(name)); + } else if (command == "@attributes") { + current = command; + attributes.push_back(SectionInfo(name)); + } else { + sections.push_back(line); + return false; + } + return true; + } + + /// \brief Retrieve the items from various sections. + /// + /// Retrieve the items from various sections. + void read(std::istream& is) { + if (current == "@nodeset") { + readMapNames(is, nodesets.back().items); + } else if (current == "@edgeset") { + readMapNames(is, edgesets.back().items); + } else if (current == "@undiredgeset") { + readMapNames(is, undiredgesets.back().items); + } else if (current == "@nodes") { + readItemNames(is, nodes.back().items); + } else if (current == "@edges") { + readItemNames(is, edges.back().items); + } else if (current == "@undiredges") { + readItemNames(is, undiredges.back().items); + } else if (current == "@attributes") { + readItemNames(is, attributes.back().items); + } + } + + private: + + void readMapNames(std::istream& is, std::vector& maps) { + std::string line, id; + std::getline(is, line); + std::istringstream ls(line); + while (ls >> id) { + maps.push_back(id); + } + while (getline(is, line)); + } + + void readItemNames(std::istream& is, std::vector& maps) { + std::string line, id; + while (std::getline(is, line)) { + std::istringstream ls(line); + ls >> id; + maps.push_back(id); + } + } + + struct SectionInfo { + std::string name; + std::vector items; + + SectionInfo(const std::string& _name) : name(_name) {} + }; + + std::vector nodesets; + std::vector edgesets; + std::vector undiredgesets; + + std::vector nodes; + std::vector edges; + std::vector undiredges; + + std::vector attributes; + + std::vector sections; + + std::string current; + + }; + } #endif