406 std::cout <<
"Storing " <<
num_nodes <<
" nodes ... ";
416 auto p = it.get_curr();
419 std::cout << i <<
" ";
428 std::cout <<
" done " << std::endl
429 <<
"Storing " << num_arcs <<
" arcs ... " << std::endl;
431 output.write(
reinterpret_cast<const char*
>(&num_arcs),
sizeof(num_arcs));
435 auto a = it.get_curr();
443 output.write(
reinterpret_cast<const char*
>(&
src_idx),
sizeof(
int));
444 output.write(
reinterpret_cast<const char*
>(&
tgt_idx),
sizeof(
int));
452 std::cout << std::endl;
456 std::cout <<
" done " << std::endl << std::endl;
474 <<
"Failed to read node count from binary stream";
477 std::cout <<
"Loading " <<
num_nodes <<
" nodes ...";
485 std::unique_ptr<typename GT::Node> p(
new typename GT::Node);
488 std::cout <<
" " << i;
492 <<
"Failed to load node " << i <<
" from binary stream";
499 input.read(
reinterpret_cast<char*
>(&num_arcs),
sizeof(num_arcs));
501 <<
"Failed to read arc count from binary stream";
504 std::cout <<
" done " << std::endl
505 <<
"Loading " << num_arcs <<
" arcs ... " << std::endl;
507 for (
size_t i = 0; i < num_arcs; ++i)
510 input.read(
reinterpret_cast<char*
>(&
src_idx),
sizeof(
int));
512 <<
"Failed to read source index for arc " << i;
517 input.read(
reinterpret_cast<char*
>(&
tgt_idx),
sizeof(
int));
519 <<
"Failed to read target index for arc " << i;
529 <<
"Failed to load arc " << i <<
" data";
532 std::cout << std::endl;
536 std::cout <<
" done " << std::endl << std::endl;
564 << num_arcs << std::endl;
567 std::cout <<
"Storing " <<
num_nodes <<
" nodes ... ";
575 typename GT::Node * p = it.get_curr();
578 std::cout << i <<
" ";
585 std::cout <<
" done " << std::endl
586 <<
"Storing " << num_arcs <<
" arcs ... " << std::endl;
590 auto a = it.get_curr();
606 std::cout << std::endl;
610 std::cout <<
" done " << std::endl << std::endl;
630 <<
"Failed to read node/arc count from text stream";
635 std::cout <<
"Loading " <<
num_nodes <<
" nodes ...";
643 std::unique_ptr<typename GT::Node> p(
new typename GT::Node);
646 std::cout <<
" " << i;
650 <<
"Failed to load node " << i <<
" from text stream";
657 std::cout <<
" done " << std::endl
658 <<
"Loading " << num_arcs <<
" arcs ... " << std::endl;
660 for (
size_t i = 0; i < num_arcs; ++i)
667 <<
"Failed to read arc " << i <<
" indices from text stream";
678 <<
"Failed to load arc " << i <<
" data from text stream";
681 std::cout << std::endl;
685 std::cout <<
" done " << std::endl << std::endl;
Exception handling system with formatted messages for Aleph-w.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
T & insert(const T &item)
Insert a new item by copy.
Dynamic map implemented with a treap.
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
Graph serialization and deserialization class.
void save(std::ofstream &output)
Save graph to binary stream.
void set_store_arc(const Store_Arc &sa)
Set the arc storage functor.
IO_Graph(GT &__g) noexcept
Construct from graph reference.
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.
void load(std::ifstream &input)
Load graph from binary stream.
void set_arc_filter(const AF &af)
Set the arc filter for save operations.
bool is_verbose() const noexcept
Check if verbose mode is enabled.
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.
IO_Graph(GT *gptr) noexcept
Construct from graph pointer.
void set_verbose(bool v) noexcept
Enable or disable verbose mode.
void set_node_filter(const NF &nf)
Set the node filter for save operations.
void set_load_node(const Load_Node &ln)
Set the node loading functor.
virtual Node * insert_node(Node *node) noexcept
Insertion of a node already allocated.
typename Node::Node_Type Node_Type
The arc class type.
Arc * insert_arc(Node *src_node, Node *tgt_node, void *a)
typename Arc::Arc_Type Arc_Type
The type of data stored in the arc.
Filtered iterator on the nodes of a graph.
ArcInfo & get_info() noexcept
Return a modifiable reference to the arc data.
NodeInfo & get_info() noexcept
Return a modifiable reference to the data contained in the node.
Node * get_src_node(Arc *arc) const noexcept
Return the source node of arc (only for directed graphs)
constexpr size_t get_num_nodes() const noexcept
Return the total of nodes of graph.
constexpr size_t get_num_arcs() const noexcept
Node * get_tgt_node(Arc *arc) const noexcept
Return the target node of arc (only for directed graphs)
List_Graph< Graph_Node< int >, Graph_Arc< int > > GT
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Filtered iterator on all the arcs of a graph.
Default arc loading functor for binary and text modes.
void operator()(std::ifstream &input, GT &g, typename GT::Arc *a)
Load arc from binary stream.
void operator()(std::istream &input, GT &g, typename GT::Arc *a)
Load arc from text stream.
Default node loading functor for binary and text modes.
void operator()(std::istream &input, GT &g, typename GT::Node *p)
Load node from text stream.
void operator()(std::ifstream &input, GT &g, typename GT::Node *p)
Load node from binary stream.
Default filter for filtered iterators on arcs.
Default filter for the graph nodes.
Default arc storage functor for binary and text modes.
void operator()(std::ostream &output, GT &g, typename GT::Arc *a)
Store arc to text stream.
void operator()(std::ofstream &output, GT &g, typename GT::Arc *a)
Store arc to binary stream.
Default node storage functor for binary and text modes.
void operator()(std::ofstream &output, GT &g, typename GT::Node *p)
Store node to binary stream.
void operator()(std::ostream &output, GT &g, typename GT::Node *p)
Store node to text stream.
Arc of graph implemented with double-linked adjacency lists.
Generic graph and digraph implementations.