[Lemon-commits] [lemon_svn] deba: r1893 - hugo/trunk/src/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:48:31 CET 2006
Author: deba
Date: Sat May 14 22:56:53 2005
New Revision: 1893
Modified:
hugo/trunk/src/lemon/lemon_reader.h
Log:
ContentReader
Retrieve information from the input file.
Modified: hugo/trunk/src/lemon/lemon_reader.h
==============================================================================
--- hugo/trunk/src/lemon/lemon_reader.h (original)
+++ hugo/trunk/src/lemon/lemon_reader.h Sat May 14 22:56:53 2005
@@ -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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& attributesItems(int index) const {
+ return attributes[index].items;
+ }
+
+ const std::vector<std::string>& 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<std::string>& 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<std::string>& 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<std::string> items;
+
+ SectionInfo(const std::string& _name) : name(_name) {}
+ };
+
+ std::vector<SectionInfo> nodesets;
+ std::vector<SectionInfo> edgesets;
+ std::vector<SectionInfo> undiredgesets;
+
+ std::vector<SectionInfo> nodes;
+ std::vector<SectionInfo> edges;
+ std::vector<SectionInfo> undiredges;
+
+ std::vector<SectionInfo> attributes;
+
+ std::vector<std::string> sections;
+
+ std::string current;
+
+ };
+
}
#endif
More information about the Lemon-commits
mailing list