Flip Reference

BackEndBinary Class Reference

Declared in

flip/BackEndBinary.h

class BackEndBinary;

flip::BackEndBinary represents a concrete format data type which, using a DataProvider or DataConsumer, allows to read or write and fill a generic back end representation of a document.

The object itself does not hold any data, and just act as a parser/formatter from the intermediate representation of the document to the provider/consumer.

BackEndBinary will format the data in binary :

See BackEndMl for a less compact, less robust, less secure and less performant format, but which is human readable and editable in any plain text editing software.

Normally, this class is used through the use of BackEndIR directly. See the documentation for more details.

DataProviders and DataConsumers provides an abstraction to the underlying storage media from which to read or write to.

Member Functions Synopsys

Constructor

Constructs the BackEndBinary

Destructor

Destructs the BackEndBinary

write

Format the data from the intermediate representation to the data consumer

read

Parse the data from the data provider to the intermediate representation

Member Functions

Constructor

BackEndBinary ();

Default constructor.


Destructor

~BackEndBinary ();

Destructor.


write

void  write (DataConsumerBase & consumer, const BackEndIR & ir);

Format the data from the intermediate representation of the document and feed them to the consumer.

Example :

#include "flip/BackEndBinary.h"
#include "flip/BackEndIR.h"
#include "flip/DataConsumerMemory.h"
Document document (Model::use (), user_id, manufacturer_id, component_id);
[...]
// put the result of document serialisation in 'data'
std::vector <uint8_t> data;
DataConsumerMemory consumer (data);
// get the backend intermediate representation
BackEndIR backend = document.write ();
// write the backend intermediate representation to binary, using the consumer
backend.write <BackEndBinary> (consumer);
// now 'data' is filled with the document serialisation in binary format

read

void   read (DataProviderBase & provider, BackEndIR & ir);

Parse the data from the data provider and fill the intermediate representation of the document.

Example :

#include "flip/BackEndBinary.h"
#include "flip/BackEndIR.h"
#include "flip/DataProviderMemory.h"
// data is filled with a previous document serialisation from 'write' above
std::vector <uint8_t> data = ...;
DataProviderMemory provider (data);
// tell the backend to automatically recognize the binary format
BackEndIR backend;
backend.register_backend <BackEndBinary> ();
bool ok_flag = backend.read (provider);
if (!ok_flag) return;   // a corruption occured
Document document (Model::use (), user_id, manufacturer_id, component_id);
// change the document with the content of the backend
document.read (backend);
// commit the changes
document.commit ();