Serialization of Graph-like C++ Structures

N

Nordlöw

Does anyone know of any convenient interface/API (Database) that
transparently encodes/decodes (serialization) graph-like C++
structures and relations between them to and from disk?

Of course the programmer needs explicitly specify the serialization
of
the data-members of the struct/class typically using the member
functions

- Obj::encode(std::eek:stream & os) const
- Obj::decode(std::istream & is) const

I have also implemented "automatic management" of two-way-relations
to
realized unordered graph structures.

These are realized as enum-typed double-linked/way pointers.
These could be (un)serialized automatically

Could we reuse boost::graph and boost::serialization somehow?
If not, what structures (balanced tree, hashmap, sorted arrays, ...)
should I use to construct file-format?

Thanks in advance,
Nordlöw
 
J

Jonathan Lee

Does anyone know of any convenient interface/API (Database) that
transparently encodes/decodes (serialization) graph-like C++
structures and relations between them to and from disk?

No, but I recently wrote a serialization routine for my own Graph
class. It wrote the class as an adjacency list with the form (using
grammar notation -- not pointer notation)

((sourceNode)(destNodeID*) Terminator1)* Terminator2

Then I (naively) iterate over every node:

void Graph::serialize(ostream& o) {
for (int i = 0; i < numNodes; ++i) {
o << node; // assume node is serializable
for (int j = 0; j < numNodes; ++j) {
if (adjacent(i,j)) encode(o, j);
}
o << Terminator1;
}
o << Terminator2;
}

In practice encode(o,j) writes j as a UTF-8 like variable length
integer. Then Terminator1 == '\0xFE' and Terminator2 == '\0xFF' for
the simple reason that 0xFE and 0xFF cannot occur in that encoding.

--Jonathan
 
L

Lynette Angley

Is this some kinda next gen P2P application? 'Coz bittorrents have this feature.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top