Candidate_v1.7.0
stable
|
Last change
on this file since 38bcbe was c52abd, checked in by Frederik Heber <frederik.heber@…>, 7 years ago |
|
Added unit test for Graph6Reader.
|
-
Property mode
set to
100644
|
|
File size:
1.6 KB
|
| Line | |
|---|
| 1 | /*
|
|---|
| 2 | * Graph6Reader.hpp
|
|---|
| 3 | *
|
|---|
| 4 | * Created on: Sep 26, 2017
|
|---|
| 5 | * Author: heber
|
|---|
| 6 | */
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 | #ifndef GRAPH_GRAPH6READER_HPP_
|
|---|
| 10 | #define GRAPH_GRAPH6READER_HPP_
|
|---|
| 11 |
|
|---|
| 12 | // include config.h
|
|---|
| 13 | #ifdef HAVE_CONFIG_H
|
|---|
| 14 | #include <config.h>
|
|---|
| 15 | #endif
|
|---|
| 16 |
|
|---|
| 17 | #include <istream>
|
|---|
| 18 | #include <iterator>
|
|---|
| 19 | #include <string>
|
|---|
| 20 | #include <vector>
|
|---|
| 21 |
|
|---|
| 22 | class Graph6ReaderUnitTest;
|
|---|
| 23 |
|
|---|
| 24 | /** This functor parses graph6 formatted strings and returns number of nodes
|
|---|
| 25 | * and a edge list.
|
|---|
| 26 | *
|
|---|
| 27 | * This is inspired by https://github.com/adrianN/graph6/, only I found the code
|
|---|
| 28 | * there quite ugly and unnecessarily complicated: inheriting from std::iterator,
|
|---|
| 29 | * overriding all the operators (++, *, ...) for no apparent reason instead of
|
|---|
| 30 | * adding normal functions, ...
|
|---|
| 31 | *
|
|---|
| 32 | */
|
|---|
| 33 | struct Graph6Reader
|
|---|
| 34 | {
|
|---|
| 35 | //!> grant unit test access to private parts
|
|---|
| 36 | friend class Graph6ReaderUnitTest;
|
|---|
| 37 |
|
|---|
| 38 | typedef std::pair<int, int> edge_t;
|
|---|
| 39 | typedef std::vector< edge_t > edges_t;
|
|---|
| 40 |
|
|---|
| 41 | Graph6Reader() :
|
|---|
| 42 | column(1),
|
|---|
| 43 | row(-1),
|
|---|
| 44 | eos(false),
|
|---|
| 45 | bit_pos(-1),
|
|---|
| 46 | num_nodes(0)
|
|---|
| 47 | {}
|
|---|
| 48 |
|
|---|
| 49 | void operator()(std::istream &_graph_string);
|
|---|
| 50 |
|
|---|
| 51 | int get_num_nodes() const
|
|---|
| 52 | { return num_nodes; }
|
|---|
| 53 |
|
|---|
| 54 | const edges_t& get_edges() const
|
|---|
| 55 | { return edges; }
|
|---|
| 56 |
|
|---|
| 57 | private:
|
|---|
| 58 |
|
|---|
| 59 | void scan_num_nodes(std::istream_iterator<unsigned char> &_it);
|
|---|
| 60 | void scan_edges(std::istream_iterator<unsigned char> &_it);
|
|---|
| 61 | void next_edge(std::istream_iterator<unsigned char> &_it);
|
|---|
| 62 |
|
|---|
| 63 | private:
|
|---|
| 64 | int column;
|
|---|
| 65 | int row;
|
|---|
| 66 | bool eos;
|
|---|
| 67 | int bit_pos;
|
|---|
| 68 | static const int packet_size;
|
|---|
| 69 |
|
|---|
| 70 | //!> contains number of edges
|
|---|
| 71 | int num_nodes;
|
|---|
| 72 | //!> contains edge list
|
|---|
| 73 | std::vector< edge_t > edges;
|
|---|
| 74 | };
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | #endif /* GRAPH_GRAPH6READER_HPP_ */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.