2 #ifndef ANDRES_GRAPH_DIGRAPH_HDF5_HXX
3 #define ANDRES_GRAPH_DIGRAPH_HDF5_HXX
10 #include "../digraph.hxx"
17 template<
class VISITOR>
18 struct GraphTraitsHDF5<
Digraph<VISITOR> > {
21 template<
class VISITOR>
22 const int GraphTraitsHDF5<Digraph<VISITOR> >::ID = 10001;
24 template <
class VISITOR>
27 template <
class VISITOR>
30 template <
class VISITOR>
33 const hid_t parentHandle,
34 const std::string& graphName,
37 HandleCheck<ANDRES_GRAPH_HDF5_DEBUG> handleCheck;
38 hid_t groupHandle =
openGroup(parentHandle, graphName,
true);
46 std::vector<std::size_t> vecIJ;
48 std::size_t *ptrI = &vecIJ[0];
56 }
catch (std::exception& e) {
58 throw std::runtime_error(
"error saving digraph: " + std::string(e.what()));
64 template <
class VISITOR>
67 const hid_t parentHandle,
68 const std::string& graphName,
71 HandleCheck<ANDRES_GRAPH_HDF5_DEBUG> handleCheck;
72 hid_t groupHandle =
openGroup(parentHandle, graphName);
78 load(groupHandle,
"graph-type-id",
id);
80 sError =
"graph type id mismatch.";
84 std::size_t numberOfVertices = 0;
85 load(groupHandle,
"number-of-vertices", numberOfVertices);
87 std::size_t numberOfEdges = 0;
88 load(groupHandle,
"number-of-edges", numberOfEdges);
90 graph.
assign(numberOfVertices);
92 if(numberOfEdges != 0) {
95 std::vector<std::size_t> bufferIJ;
97 std::vector<std::size_t> shape;
98 load(groupHandle,
"edges", shape, bufferIJ);
99 if(shape.size() != 2) {
100 sError =
"edges dataset is not 2-dimensional.";
103 if(shape[0] != numberOfEdges || shape[1] != 2) {
104 sError =
"edges dataset has incorrect shape.";
107 assert(shape[0] * 2 == bufferIJ.size());
109 std::size_t* ptrI = &bufferIJ[0];
110 std::size_t* ptrJ = &bufferIJ[numberOfEdges];
112 unsigned char multipleEdgesEnabled;
113 load(groupHandle,
"multiple-edges-enabled", multipleEdgesEnabled);
116 for(std::size_t i=0;i<numberOfEdges;++i) {
117 const std::size_t s = *(ptrI++);
118 const std::size_t t = *(ptrJ++);
119 if(s >= numberOfVertices || t >= numberOfVertices) {
120 sError =
"vertex index out of bounds.";
126 }
catch(std::exception& e) {
132 if(!sError.empty()) {
133 throw std::runtime_error(
"error loading digraph: " + sError);
141 #endif // #ifndef ANDRES_GRAPH_DIGRAPH_HDF5_HXX