Flip Reference

DataProviderFile Class Reference

Declared in

flip/contrib/DataProviderFile.h

class DataProviderFile;

Note: Classes part of contrib/ are not supported on every platform. This class is not supported on the WinRT platform.

Generally a data provider represents an abstraction of input serialized data that is platform (endianess and word size) independent.

flip::DataProviderFile is a specialization of data provider which input is a file.

Internally the data is presented in big-endian, and has byte alignment packing.

To input from memory instead of a file, see flip::DataProviderMemory

Member Functions Synopsys

Constructor

Constructs the DataProviderFile

Destructor

Destructs the DataProviderFile

operator >>

Extracts value from the provider

read_string

Extracts string from the provider

pull

Extracts raw data from the provider

pull

Returns the current reading position in the stream

seek_start

Seek reading position relative to the beginning of the stream

seek_relative

Seek reading position relative to the current position in the stream

Member Functions

Constructor

DataProviderFile (const char * path_0);

Constructor. The input of serialization will come from the file with path the null terminated string path_0.

Important: The encoding of path_0 is UTF-8

The path should make possible to open a file for reading. If any error occurs, the constructor will throw std::runtime_error.


Destructor

~DataProviderFile ();

Destructor.


operator >>

DataProviderFile & operator >> (bool & val);
DataProviderFile & operator >> (char & val);
DataProviderFile & operator >> (uint8_t & val);
DataProviderFile & operator >> (int32_t & val);
DataProviderFile & operator >> (uint32_t & val);
DataProviderFile & operator >> (int64_t & val);
DataProviderFile & operator >> (uint64_t & val);
DataProviderFile & operator >> (double & val);

Extracts value from the provider.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.

Example :

std::vector <uint8_t> data;
DataConsumerMemory consumer (data);
std::string str ("Flip");
consumer << true;
consumer << int32_t (2);
consumer << 2.5;
consumer << uint64_t (str.size ());
consumer << str;
DataProviderMemory provider (data);
bool val_b;
int32_t val_i;
double val_d;
std::string val_s;
consumer >> val_b; // true
consumer >> val_i; // 2
consumer >> val_d; // 2.5
uint64_t str_size;
consumer >> str_size;
val_s = consumer.read_string (str_size);   // "Flip"
char val_c;
consumer >> val_c; // throws std::runtime_error

read_string

std::string read_string (size_t size);

Extracts string from the provider.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.


pull

const uint8_t *   pull (size_t data_size);

Extracts data_size bytes of raw data from the provider. No byte swap is performed and the packing of data is not changed.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.


pull

size_t tell ();

Returns the current reading position in the stream.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.


seek_start

seek_start (size_t offset_abs = 0);

Seek reading position to offset_abs, relative to the beginning of the stream.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.


seek_relative

seek_start (size_t offset_rel = 0);

Seek reading position to offset_rel, relative to the current position in the stream.

If any error occurs (such as reading past the end of the stream), the method will throw std::runtime_error.