Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
UppHub
Status & Roadmap
FAQ
Authors & License
Forums
Funding U++
Search on this site











SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Serialization utilities

 

Function List

 

Stream& Pack16(Stream& s, int& i)

Serializes 32-bit data, optimizing it for 16-bit values. If value is in -32767-32767 range, it is serialized as 2 bytes, otherwise 6 bytes are used.

s

Stream.

i

Data to serialize.

Return value

s for chaining.

 


 

Stream& Pack16(Stream& s, int& i1, int& i2)

Stream& Pack16(Stream& s, int& i1, int& i2, int& i3)

Stream& Pack16(Stream& s, int& i1, int& i2, int& i3, int& i4)

Stream& Pack16(Stream& s, int& i1, int& i2, int& i3, int& i4, int& i5)

Calls Pack16 for each of individual 32-bit integer parameters.

 


 

bool Store(Event<Stream&> serialize, Stream& stream, int version = Null)

Serialization save with some additional data to ensure data integrity. Data to serialize are represented by Event. If version is not Null, it is stored with data and must be specified with Load - only the same version number will successfully be Loaded.

 


 

bool Load(Event<Stream&> serialize, Stream& stream, int version = Null)

Smart serialization restore. Data to serialize is represented by Event. First, backup of current state of data is performed and stored in the memory. Then data is loaded from the specified stream. If restoring of data is successful (no LoadingError exception is thrown), Load returns true. If LoadingError is thrown, it is caught by Load, data are restored from backup copy and Load returns false. If version is not Null, Load loads it from the stream (at appropriate unspecified point) and checks that the version is the same as used with Store.

 


 

bool LoadFromFile(Event<Stream&> serialize, const char *file = 0, int version = Null)

Using Load, restores data from the file.

 


 

bool StoreToFile(Event<Stream&> serialize, const char *file = 0, int version = Null)

Using Store, stores data to the file.

 


 

template <class T> bool Load(T& x, Stream& s, int version = Null)

Using Load and T::Serialize, loads x from the stream s.

 


 

template <class T> bool Store(T& x, Stream& s, int version = Null)

Using Store and T::Serialize, stores x to the stream.

 


 

template <class T> bool LoadFromFile(T& x, const char *name = 0, int version = Null)

Using LoadFromFile and T::Serialize, loads x from the stream.

 


 

template <class T> bool StoreToFile(T& x, const char *name = 0, int version = Null)

Using LoadFromFile and T::Serialize, stores x to the stream.

 


 

template <class T> String StoreAsString(T& x)

Stores x using its Serialize method and StringStream.

 


 

template <class T> bool LoadFromString(T& x, const String& s)

Restores serialized data from the String (e.g. previously stored by StoreAsString).

 

 

Global modular serialization support

Modular serialization is a viable option for storing configuration of applications consisting of many modules. It allows individual storing/loading data for given global configuration key and also serialization of all such data with single stream.

 

Function List

 

void RegisterGlobalConfig(const char *name)

Registers name as global configuration key.

 


 

void RegisterGlobalSerialize(const char *name, Event<Stream&WhenSerialize)

Registers name as global configuration key. WhenSerialize is directly used to serialize data, unlike other variants, where data are stored / retrieved using LoadFromGlobal / StoreToGlobal.

 


 

void RegisterGlobalConfig(const char *name, Event<> WhenFlush)

Registers name as global configuration key. WhenFlush  is called before storing of all configuration keys is performed by SerializeGlobalConfigs - this is useful when StoreToGlobal has to be explicitly triggered before storing configuration.

 


 

template <class T> bool LoadFromGlobal(T& x, const char *name)

Loads x from global configuration key name, using Serialize method of T.

 


 

template <class T> void StoreToGlobal(T& x, const char *name)

Stores x to global configuration key name, using Serialize method of T.

 


 

bool LoadFromGlobal(Event<Stream&serialize, const char *name)

Loads x from global configuration key name, using serialize as serialization function.

 


 

void StoreToGlobal(Event<Stream&x, const char *name)

Stores x to global configuration key name, using serialize as serialization function.

 


 

void SerializeGlobalConfigs(Stream& s)

Serializes all registered global configuration data from/to single stream.

 

 

Do you want to contribute?