The serializer subsystem allows declaring serializeable types, that can be easily memberwise saved and loaded to various storage entities, such as registry,
in a totally human-readable format. To declare such a structure, you should use the DECLARE_SERIALIZEABLE_STRUCx() macro, where
x represents the number of fields. Alternatively, you can use the DECLARE_SERIALIZEABLE_STRUCx_I() macro to declare structures with default field values (will be placed into generated default constructor).
The main idea of serializer is to provide a human-readable representation of certain internal program structures on some storage device (such as registry). The serializer should not be used for just saving some data into binary files. For that purpose C/C++ allow using extremely fast pointer-based save/load and other techniques. A serializeable structure will always have a default constructor and a constructor with parameters directly reflecting the field list. To serialize such structure use the SERIALIZE_OBJECT() macro. To deserialize - DESERIALIZE_OBJECT(). Here is a simple usage example:
DECLARE_SERIALIZEABLE_STRUC4(SomeParams,
int, SomeIntVal,
unsigned, SomeOtherIntVal,
String, SomeStringVal,
int, SomeOtherVal);
//---- OR ----
DECLARE_SERIALIZEABLE_STRUC4_I(SomeParams,
int, SomeIntVal, 123,
unsigned, SomeOtherIntVal, 456,
String, SomeStringVal, _T("InitialStringValue"),
int, SomeOtherVal, 789);
...
void SomeFunc()
{
SomeParams params(1, 2, _T("TestString"), 4);
RegistryKey key(HKEY_LOCAL_MACHINE, _T(...));
key.SerializeObject(params);
params = SomeParams();
key.DeserializeObject(params);
}
You can see the serializer usage example in SAMPLES\WINDOWS\REGISTRY.
- Attention:
- The serialized structures may only contain fields of the following types:
-
int
-
unsigned
-
bool
-
String
-
LONGLONG
-
ULONGLONG