/* * Graph6Reader.hpp * * Created on: Sep 26, 2017 * Author: heber */ #ifndef GRAPH_GRAPH6READER_HPP_ #define GRAPH_GRAPH6READER_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include /** This functor parses graph6 formatted strings and returns number of nodes * and a edge list. * * This is inspired by https://github.com/adrianN/graph6/, only I found the code * there quite ugly and unnecessarily complicated: inheriting from std::iterator, * overriding all the operators (++, *, ...) for no apparent reason instead of * adding normal functions, ... * */ struct Graph6Reader { typedef std::pair edge_t; typedef std::vector< edge_t > edges_t; Graph6Reader() : column(1), row(-1), eos(false), bit_pos(-1), num_nodes(0) {} void operator()(std::istream &_graph_string); int get_num_nodes() const { return num_nodes; } const edges_t& get_edges() const { return edges; } private: void scan_num_nodes(std::istream_iterator &_it); void scan_edges(std::istream_iterator &_it); void next_edge(std::istream_iterator &_it); private: int column; int row; bool eos; int bit_pos; static const int packet_size; //!> contains number of edges int num_nodes; //!> contains edge list std::vector< edge_t > edges; }; #endif /* GRAPH_GRAPH6READER_HPP_ */