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.
|
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 Load(Callback1<Stream&> serialize, Stream& stream)
Smart serialization restore. Data to serialize are represented by Callback. First, backup of current state of data is performed and stored in memory. Then data are 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.
|
serialize |
Callback to the serialization function. |
|
Return value |
true indicates success. |
bool Store(Callback1<Stream&> serialize, Stream& stream)
Serialization save. Data to serialize are represented by Callback.
|
serialize |
Callback to the serialization function. |
|
Return value |
true if data were properly stored to the stream. |
bool LoadFromFile(Callback1<Stream&> serialize, const char *file = NULL)
Using Load, data are restored from the file.
|
serialize |
Callback to the serialization function. |
|
Return value |
true indicates success. |
bool StoreToFile(Callback1<Stream&> serialize, const char *file = NULL)
Using Store data are saved to the file.
|
serialize |
Callback to the serialization function. |
|
Return value |
true indicates success. |
template <class T> bool Load(T& x, Stream& s)
Calls Load with callback(&x, &T::Serialize) as serialization callback. In other words, x is restored using its Serialize method.
|
T |
Type of object to restore. |
|
x |
Reference to the object. |
|
Return value |
true indicates success. |
template <class T> bool Store(T& x, Stream& s)
Calls Store with callback(&x, &T::Serialize) as serialization callback. In other words, x is stored using its Serialize method.
|
T |
Type of object to restore. |
|
x |
Reference to the object. |
|
Return value |
true indicates success. |
template <class T> bool LoadFromFile(T& x, const char *name = NULL)
Calls LoadFromFile with callback(&x, &T::Serialize) as serialization callback. In other words, x is restored from the file using its Serialize method.
|
T |
Type of object to restore. |
|
x |
Reference to the object. |
|
Return value |
true indicates success. |
template <class T> bool StoreToFile(T& x, const char *name = NULL)
Calls StoreToFile with callback(&x, &T::Serialize) as serialization callback. In other words, x is stored to the file using its Serialize method.
|
T |
Type of object to store. |
|
x |
Reference to the object. |
|
Return value |
true indicates success. |
template <class T> String StoreAsString(T& x)
Stores x using its Serialize method and StringStream.
|
T |
Type of object to store. |
|
x |
Reference to the object. |
|
Return value |
String containing serialized x. |
template <class T> bool LoadFromString(T& x, const String& s)
Restores serialized data from the String (e.g. previously stored by StoreAsString).
|
T |
Type of object to restore. |
|
s |
String containing serialized x. |
|
Return value |
true indicates success. |
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.
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 of global config key, 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.
|