Subject: Mathemagix
List archive
- From: Joris van der Hoeven <address@concealed>
- To: address@concealed
- Subject: [Mathemagix] Binary input/output and inspection
- Date: Wed, 20 Jan 2010 19:11:22 +0100
Hi all,
I added a new helper class 'binary_helper<C>' for binary input/output
and introspection of data. Although not mandatory, we recommend
a partial specization for each data type C, in a similar way as flatten.
The reasons behind 'binary_helper' are the following:
1) We need a way for fast communication of Mathemagix objects between
different processes or different computers on a network.
2) This will in turn be needed when additional parallelism will be added
to the language.
3) Besides pretty printed output, as generated by flatten,
we need human readable output from which the original object
can be recomputed in a reliable way.
4) For debugging purposes, it is nice to be able to investigate
the internal representation of data structures.
The 'binary_helper<C>' class comes with the following static member functions:
static string short_type_name ()
A short and unique name for the type C.
Convention: start atomic types with a capital followed by lowercase
letters.
Similarly for compound types, next concatenate with the short names of
the argument types
This method is used for binary input/output of generic objects.
static generic full_type_name ()
The full type of C, as used in the interpreter or compiler.
Here we also intend to make the name accessible from within C++.
We may want to change the behaviour of this routine later.
static generic disassemble (const C& x)
return as<generic> (x); }
static inline C assemble (const generic& x) {
return as<C> (x); }
static inline void write (const port& out, const C& x) {
generic d= binary_disassemble<C> (x);
ASSERT (is<string> (d) || !is<C> (d), "binary write not implemented");
binary_write<generic> (out, d); }
static inline C read (const port& in) {
return binary_assemble<C> (binary_read<generic> (in)); }
static inline nat size (const C& x) {
return vector_size (disassemble (x)); }
static inline generic access (const C& x, nat i) {
return vector_access (disassemble (x), i); }
- [Mathemagix] Binary input/output and inspection, Joris van der Hoeven, 01/20/2010
Archive powered by MHonArc 2.6.18.