|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Graph serialization and deserialization class. More...
#include <io_graph.H>
Classes | |
| class | Loaded_Nodes |
| The nodes that a load has read, by their index in the stream. More... | |
Public Member Functions | |
| void | set_verbose (bool v) noexcept |
| Enable or disable verbose mode. | |
| bool | is_verbose () const noexcept |
| Check if verbose mode is enabled. | |
| void | set_load_node (const Load_Node &ln) |
| Set the node loading functor. | |
| void | set_store_node (const Store_Node &sn) |
| Set the node storage functor. | |
| void | set_load_arc (const Load_Arc &la) |
| Set the arc loading functor. | |
| void | set_store_arc (const Store_Arc &sa) |
| Set the arc storage functor. | |
| void | set_node_filter (const NF &nf) |
| Set the node filter for save operations. | |
| void | set_arc_filter (const AF &af) |
| Set the arc filter for save operations. | |
| IO_Graph (GT &__g) noexcept | |
| Construct from graph reference. | |
| IO_Graph (GT *gptr) noexcept | |
| Construct from graph pointer. | |
| IO_Graph (GT &__g, AF af) | |
| Construct from graph reference, with the arc filter. | |
| IO_Graph (GT *gptr, AF af) | |
| Construct from graph pointer, with the arc filter. | |
| void | save (std::ofstream &output) |
| Save graph to binary stream. | |
| void | load (std::ifstream &input) |
| Load graph from binary stream. | |
| void | save_in_text_mode (std::ostream &output) |
| Save graph to text stream. | |
| void | load_in_text_mode (std::istream &input) |
| Load graph from text stream. | |
Private Member Functions | |
| size_t | number_shown_nodes (DynMapTreap< typename GT::Node *, int > &nodes_table) |
| Gives each node that the node filter shows its number in the file, in the order of the saves, and returns how many there are. | |
| size_t | count_shown_arcs (const DynMapTreap< typename GT::Node *, int > &nodes_table) |
| The arcs that the arc filter shows whose two ends are numbered. | |
Private Attributes | |
| GT & | g |
| Load_Node | load_node = Load_Node() |
| Store_Node | store_node = Store_Node() |
| Load_Arc | load_arc = Load_Arc() |
| Store_Arc | store_arc = Store_Arc() |
| NF | node_filter = NF() |
| AF | arc_filter = AF() |
| bool | verbose_mode = false |
Graph serialization and deserialization class.
IO_Graph provides methods for saving and loading graphs to/from binary and text streams. The serialization format is customizable through template parameters for node/arc load and store functors.
| GT | Graph type (List_Graph, List_Digraph, etc.) |
| Load_Node | Functor for loading node data. Must provide: |
| Store_Node | Functor for storing node data. Must provide: |
| Load_Arc | Functor for loading arc data. Must provide: |
| Store_Arc | Functor for storing arc data. Must provide: |
| NF | Node filter functor (only nodes passing filter are saved) |
| AF | Arc filter functor (only arcs passing filter are saved) |
Definition at line 343 of file io_graph.H.
|
inlineexplicitnoexcept |
Construct from graph reference.
The arc filter is AF(): one without a default constructor goes to the constructor that takes it.
| __g | Reference to the graph to save/load |
Definition at line 417 of file io_graph.H.
|
inlineexplicitnoexcept |
Construct from graph pointer.
The arc filter is AF(), as in the constructor from a reference.
| gptr | Pointer to the graph to save/load |
Definition at line 426 of file io_graph.H.
|
inline |
Construct from graph reference, with the arc filter.
| __g | Reference to the graph to save/load |
| af | the filter of the arcs that the save operations write |
Definition at line 433 of file io_graph.H.
|
inline |
Construct from graph pointer, with the arc filter.
| gptr | Pointer to the graph to save/load |
| af | the filter of the arcs that the save operations write |
Definition at line 439 of file io_graph.H.
|
inlineprivate |
The arcs that the arc filter shows whose two ends are numbered.
Definition at line 454 of file io_graph.H.
References Aleph::and, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::arc_filter, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), and Aleph::DynMapTree< Key, Data, Tree, Compare >::search().
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode().
|
inlinenoexcept |
Check if verbose mode is enabled.
Definition at line 371 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
|
inline |
Load graph from binary stream.
Reads a graph in binary format and adds its nodes and arcs to the graph, which it does not clear. If the stream fails or is corrupted, as with an arc whose end is not a node of the stream, the nodes and arcs that the load added are removed: the graph is as it was.
| input | Binary input stream (must be opened with std::ios::binary) |
| std::runtime_error | If read operations fail or stream is corrupted |
Definition at line 552 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::add(), ah_runtime_error_if, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_arc, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_node, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::node(), num_nodes, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::remove_from(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Load graph from text stream.
Reads a graph in text format and adds its nodes and arcs to the graph, which it does not clear. If the stream fails or is corrupted, as with an arc whose end is not a node of the stream, the nodes and arcs that the load added are removed: the graph is as it was.
| input | Text input stream |
| std::runtime_error | If read operations fail or stream is corrupted |
Definition at line 712 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::add(), ah_runtime_error_if, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_arc, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_node, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::node(), num_nodes, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::remove_from(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlineprivate |
Gives each node that the node filter shows its number in the file, in the order of the saves, and returns how many there are.
Definition at line 445 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, Aleph::DynMapTree< Key, Data, Tree, Compare >::insert(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::node_filter.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode().
|
inline |
Save graph to binary stream.
Writes the graph in binary format:
| output | Binary output stream (must be opened with std::ios::binary) |
| std::runtime_error | If write operations fail |
Definition at line 482 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::arc_filter, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::count_shown_arcs(), Aleph::DynMapTree< Key, Data, Tree, Compare >::find(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::node_filter, num_nodes, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::number_shown_nodes(), output, Aleph::DynMapTree< Key, Data, Tree, Compare >::search(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_arc, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_node, and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Save graph to text stream.
Writes the graph in human-readable text format:
| output | Text output stream |
| std::runtime_error | If write operations fail |
Definition at line 644 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::arc_filter, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::count_shown_arcs(), Aleph::DynMapTree< Key, Data, Tree, Compare >::find(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::g, GraphCommon< GT, Node, Arc >::get_src_node(), GraphCommon< GT, Node, Arc >::get_tgt_node(), Aleph::Filter_Iterator< Container, It, Show_Item >::next_ne(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::node_filter, num_nodes, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::number_shown_nodes(), output, Aleph::DynMapTree< Key, Data, Tree, Compare >::search(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_arc, Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_node, and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inline |
Set the arc filter for save operations.
It assigns the filter: one that cannot be assigned goes to the constructor.
| af | Arc filter functor (arcs passing filter are saved) |
Definition at line 405 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::arc_filter.
|
inline |
Set the arc loading functor.
| la | Arc loading functor to use |
Definition at line 386 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_arc.
Referenced by TEST_F().
|
inline |
Set the node loading functor.
| ln | Node loading functor to use |
Definition at line 376 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_node.
Referenced by TEST_F().
|
inline |
Set the node filter for save operations.
| nf | Node filter functor (nodes passing filter are saved) |
Definition at line 396 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::node_filter.
|
inline |
Set the arc storage functor.
| sa | Arc storage functor to use |
Definition at line 391 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_arc.
Referenced by TEST_F().
|
inline |
Set the node storage functor.
| sn | Node storage functor to use |
Definition at line 381 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::store_node.
Referenced by TEST_F().
|
inlinenoexcept |
Enable or disable verbose mode.
When enabled, progress information is printed to std::cout during save and load operations.
| v | True to enable verbose output, false to disable |
Definition at line 366 of file io_graph.H.
References Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::verbose_mode.
Referenced by TEST_F().
|
private |
Definition at line 353 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::count_shown_arcs(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_arc_filter().
|
private |
Definition at line 345 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::add(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::count_shown_arcs(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_in_text_mode(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::number_shown_nodes(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::Loaded_Nodes::remove_from(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode().
|
private |
Definition at line 349 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_load_arc().
|
private |
Definition at line 347 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_load_node().
|
private |
Definition at line 352 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::number_shown_nodes(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_node_filter().
|
private |
Definition at line 350 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_store_arc().
|
private |
Definition at line 348 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_store_node().
|
private |
Definition at line 355 of file io_graph.H.
Referenced by Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::is_verbose(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::load_in_text_mode(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save(), Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::save_in_text_mode(), and Aleph::IO_Graph< GT, Load_Node, Store_Node, Load_Arc, Store_Arc, NF, AF >::set_verbose().