ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members

Represents an input/output persistence archive for object serialization. More...

#include <IArchive.h>

Inheritance diagram for iser::IArchive:
istd::IPolymorphic iser::CArchiveBase iser::CReadArchiveBase iser::CWriteArchiveBase iser::CBinaryReadArchiveBase iser::CTextReadArchiveBase iser::CBinaryWriteArchiveBase iser::CTextWriteArchiveBase ifile::CFileReadArchive iser::CMemoryReadArchive iqt::CSettingsReadArchive iser::CCompactXmlReadArchiveBase iser::CJsonReadArchiveBase iser::CXmlReadArchiveBase ifile::CFileWriteArchive iser::CMemoryWriteArchive iqt::CSettingsWriteArchive iser::CCompactXmlWriteArchiveBase iser::CJsonWriteArchiveBase iser::CXmlWriteArchiveBase

Public Types

enum  MessageId { MI_TAG_ERROR = 0x3f320a0 , MI_TAG_SKIPPED }
 

Public Member Functions

virtual bool IsStoring () const =0
 Checks if this archive is in storing (writing) or loading (reading) mode.
 
virtual bool IsTagSkippingSupported () const =0
 Checks if skipping to the end of a tag on EndTag() is supported.
 
virtual const IVersionInfoGetVersionInfo () const =0
 Gets version information for the archived stream.
 
virtual bool BeginTag (const CArchiveTag &tag)=0
 Begins a tagged section in the archive.
 
virtual bool BeginMultiTag (const CArchiveTag &tag, const CArchiveTag &subTag, int &count)=0
 Begins a tagged section containing multiple elements of the same type.
 
virtual bool EndTag (const CArchiveTag &tag)=0
 Ends a tagged section in the archive.
 
virtual bool Process (bool &value)=0
 Processes (reads or writes) a boolean value.
 
virtual bool Process (char &value)=0
 Process primitive type.
 
virtual bool Process (quint8 &value)=0
 Process primitive type.
 
virtual bool Process (qint8 &value)=0
 Process primitive type.
 
virtual bool Process (quint16 &value)=0
 Process primitive type.
 
virtual bool Process (qint16 &value)=0
 Process primitive type.
 
virtual bool Process (quint32 &value)=0
 Process primitive type.
 
virtual bool Process (qint32 &value)=0
 Process primitive type.
 
virtual bool Process (quint64 &value)=0
 Process primitive type.
 
virtual bool Process (qint64 &value)=0
 Process primitive type.
 
virtual bool Process (float &value)=0
 Process primitive type.
 
virtual bool Process (double &value)=0
 Process primitive type.
 
virtual bool Process (QByteArray &value)=0
 Process primitive type.
 
virtual bool Process (QString &value)=0
 Process primitive type.
 
template<typename Primitive >
bool TagAndProcess (const CArchiveTag &tag, Primitive &value)
 
virtual bool ProcessData (void *dataPtr, int size)=0
 Process binary data block.
 
virtual bool ProcessBits (void *dataPtr, int bitsCount, int bytesCount)=0
 Process binary data block.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Detailed Description

Represents an input/output persistence archive for object serialization.

Purpose

IArchive provides an abstract interface for serializing and deserializing objects to and from various storage media. It acts as a bridge between the logical structure of your data and the physical representation (binary file, XML, JSON, memory buffer, etc.). This abstraction allows the same serialization code to work with different archive types.

Archive Types

ACF provides several archive implementations:

Key Concepts

Tags**: Archives organize data using tags (similar to XML elements). Each tag has a name and describes a logical unit of data. Tags can be nested to create hierarchical structures.

Bidirectional**: The same Process() methods are used for both reading and writing. Use IsStoring() to determine the direction.

Type Safety**: Archive provides Process() overloads for common types (int, double, QString, etc.), ensuring type-safe serialization.

Usage Example

// Example serializable class
class CPerson: public iser::ISerializable
{
public:
QString m_name;
int m_age;
QList<QString> m_hobbies;
// Implement Serialize method
virtual bool Serialize(iser::IArchive& archive) override
{
bool result = true;
// Serialize name
static iser::CArchiveTag nameTag("Name", "Person's name");
result = result && archive.BeginTag(nameTag);
result = result && archive.Process(m_name);
result = result && archive.EndTag(nameTag);
// Serialize age
static iser::CArchiveTag ageTag("Age", "Person's age");
result = result && archive.BeginTag(ageTag);
result = result && archive.Process(m_age);
result = result && archive.EndTag(ageTag);
// Serialize hobbies list
static iser::CArchiveTag hobbiesTag("Hobbies", "List of hobbies");
static iser::CArchiveTag hobbyTag("Hobby", "Single hobby");
int count = m_hobbies.count();
result = result && archive.BeginMultiTag(hobbiesTag, hobbyTag, count);
if (archive.IsStoring()) {
// Writing: iterate and save each hobby
for (const QString& hobby : m_hobbies) {
QString temp = hobby;
result = result && archive.BeginTag(hobbyTag);
result = result && archive.Process(temp);
result = result && archive.EndTag(hobbyTag);
}
} else {
// Reading: count is set by BeginMultiTag
m_hobbies.clear();
for (int i = 0; i < count; ++i) {
QString hobby;
result = result && archive.BeginTag(hobbyTag);
result = result && archive.Process(hobby);
result = result && archive.EndTag(hobbyTag);
m_hobbies.append(hobby);
}
}
result = result && archive.EndTag(hobbiesTag);
return result;
}
};
// Usage: Save to file
{
CPerson person;
person.m_name = "Alice";
person.m_age = 30;
person.m_hobbies << "Reading" << "Hiking" << "Coding";
ifile::CFileWriteArchive archive("person.dat");
if (archive.IsOpen()) {
person.Serialize(archive);
}
}
// Usage: Load from file
{
CPerson person;
ifile::CFileReadArchive archive("person.dat");
if (archive.IsOpen()) {
person.Serialize(archive);
// person now contains loaded data
}
}
// Usage: Save to XML
{
CPerson person;
person.m_name = "Bob";
person.m_age = 25;
ifile::CSimpleXmlFileWriteArchive xmlArchive("person.xml");
if (xmlArchive.IsOpen()) {
person.Serialize(xmlArchive);
}
}
Simple implementation of archive reading from own ACF format binary file.
Simple implementation of archive writing to own ACF format binary file.
Simple implementation of archive for writing in XML format.
Process tag used to group data in archive stream.
Definition CArchiveTag.h:22
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
virtual bool Process(bool &value)=0
Processes (reads or writes) a boolean value.
virtual bool EndTag(const CArchiveTag &tag)=0
Ends a tagged section in the archive.
virtual bool BeginMultiTag(const CArchiveTag &tag, const CArchiveTag &subTag, int &count)=0
Begins a tagged section containing multiple elements of the same type.
virtual bool IsStoring() const =0
Checks if this archive is in storing (writing) or loading (reading) mode.
virtual bool BeginTag(const CArchiveTag &tag)=0
Begins a tagged section in the archive.
Common class for all classes which objects can be archived or restored from archive.

Best Practices

See also
iser::ISerializable, iser::CArchiveTag, ifile::CFileReadArchive, ifile::CFileWriteArchive, ifile::CJsonFileReadArchive

Definition at line 163 of file IArchive.h.

Member Enumeration Documentation

◆ MessageId

Enumerator
MI_TAG_ERROR 
MI_TAG_SKIPPED 

Definition at line 166 of file IArchive.h.

Member Function Documentation

◆ BeginMultiTag()

virtual bool iser::IArchive::BeginMultiTag ( const CArchiveTag tag,
const CArchiveTag subTag,
int &  count 
)
pure virtual

Begins a tagged section containing multiple elements of the same type.

BeginMultiTag is used for serializing collections, arrays, or lists where you have multiple items of the same structure. The count parameter works differently for reading vs. writing:

  • Writing: Pass the number of elements you will serialize
  • Reading: The archive sets count to the number of elements stored
Parameters
tagMain container tag for the entire collection
subTagTag type for each individual element in the collection
count[in/out] For writing: number of elements to serialize For reading: set by archive to number of stored elements
Returns
true if successful, false on error
// Writing a list
if (archive.IsStoring()) {
int count = m_items.count();
archive.BeginMultiTag(listTag, itemTag, count);
for (const Item& item : m_items) {
archive.BeginTag(itemTag);
item.Serialize(archive);
archive.EndTag(itemTag);
}
archive.EndTag(listTag);
}
// Reading a list
else {
int count;
archive.BeginMultiTag(listTag, itemTag, count);
m_items.clear();
for (int i = 0; i < count; ++i) {
archive.BeginTag(itemTag);
Item item;
item.Serialize(archive);
m_items.append(item);
archive.EndTag(itemTag);
}
archive.EndTag(listTag);
}
See also
BeginTag(), EndTag()

Implemented in iser::CArchiveBase, iser::CXmlReadArchiveBase, iser::CXmlWriteArchiveBase, iqt::CSettingsReadArchive, iqt::CSettingsWriteArchive, iser::CCompactXmlReadArchiveBase, iser::CCompactXmlWriteArchiveBase, iser::CJsonReadArchiveBase, and iser::CJsonWriteArchiveBase.

Referenced by imath::TFastVector< MaxSize, Element >::Serialize(), imath::TMathVectorWrap< Base >::Serialize(), iattr::TMultiAttribute< Value >::Serialize(), ibase::TFactorisableContainer< InterfaceClass >::Serialize(), ibase::TSerializableContainer< ItemClass, ContainerType >::Serialize(), icmm::TComposedColor< Size >::Serialize(), idoc::TMultiPageDocumentWrap< Base >::Serialize(), imath::TFulcrumGrid< Position, Fulcrums >::Serialize(), iser::CPrimitiveTypesSerializer::SerializeAssociativeContainer(), iser::CPrimitiveTypesSerializer::SerializeAssociativeObjectContainer(), iser::CPrimitiveTypesSerializer::SerializeContainer(), and iser::CPrimitiveTypesSerializer::SerializeObjectContainer().

◆ BeginTag()

virtual bool iser::IArchive::BeginTag ( const CArchiveTag tag)
pure virtual

Begins a tagged section in the archive.

Tags organize data into logical units with names and descriptions. Every BeginTag() must be matched with an EndTag() call. Tags can be nested to create hierarchical data structures.

Parameters
tagThe tag object describing this section. Use static CArchiveTag instances to avoid repeated construction overhead.
Returns
true if the tag was successfully opened, false on error
Note
Always match BeginTag() with EndTag()
Check the return value and propagate errors
For collections, use BeginMultiTag() instead
static iser::CArchiveTag personTag("Person", "Person data");
if (archive.BeginTag(personTag)) {
archive.Process(name);
archive.Process(age);
archive.EndTag(personTag);
}
See also
EndTag(), BeginMultiTag(), CArchiveTag

Implemented in iser::CBinaryReadArchiveBase, iser::CBinaryWriteArchiveBase, iser::CXmlReadArchiveBase, iser::CXmlWriteArchiveBase, ifile::CFileReadArchive, ifile::CFileWriteArchive, iqt::CSettingsReadArchive, iqt::CSettingsWriteArchive, iser::CCompactXmlReadArchiveBase, iser::CCompactXmlWriteArchiveBase, iser::CJsonReadArchiveBase, and iser::CJsonWriteArchiveBase.

Referenced by imath::TFastVector< MaxSize, Element >::Serialize(), imath::TMathVectorWrap< Base >::Serialize(), imath::TMatrix< Width, Height, Element >::Serialize(), iattr::TAttribute< Value >::Serialize(), iattr::TMultiAttribute< Value >::Serialize(), ibase::TFactorisableContainer< InterfaceClass >::Serialize(), ibase::TSerializableContainer< ItemClass, ContainerType >::Serialize(), icmm::TComposedColor< Size >::Serialize(), idoc::TMultiPageDocumentWrap< Base >::Serialize(), ilog::TExtMessage< Element >::Serialize(), imath::TFulcrumGrid< Position, Fulcrums >::Serialize(), imath::TMultidimensionalPolynomial< Dimensions, Element >::Serialize(), Model::Serialize(), iser::CPrimitiveTypesSerializer::SerializeAssociativeContainer(), iser::CPrimitiveTypesSerializer::SerializeAssociativeObjectContainer(), iser::CPrimitiveTypesSerializer::SerializeContainer(), iser::CPrimitiveTypesSerializer::SerializeObjectContainer(), idoc::TMultiPageDocumentWrap< Base >::SerializePage(), iser::CPrimitiveTypesSerializer::SerializeRange(), and TagAndProcess().

◆ EndTag()

virtual bool iser::IArchive::EndTag ( const CArchiveTag tag)
pure virtual

Ends a tagged section in the archive.

Must be called after BeginTag() or BeginMultiTag() to close the section. If tag skipping is supported and not all data was read, this will skip to the end of the tag section, enabling forward compatibility.

Parameters
tagThe same tag object passed to BeginTag() or BeginMultiTag()
Returns
true if successful, false on error
Note
Always call EndTag() even if errors occurred within the tag
The tag parameter must match the one used in BeginTag()
If IsTagSkippingSupported() returns false, you must read all data before calling EndTag()
static iser::CArchiveTag dataTag("Data", "My data");
if (archive.BeginTag(dataTag)) {
bool success = archive.Process(myData);
archive.EndTag(dataTag); // Always call, even if Process failed
if (!success) return false;
}
See also
BeginTag(), BeginMultiTag(), IsTagSkippingSupported()

Implemented in iser::CBinaryReadArchiveBase, iser::CBinaryWriteArchiveBase, iser::CXmlReadArchiveBase, iser::CXmlWriteArchiveBase, ifile::CFileReadArchive, ifile::CFileWriteArchive, iqt::CSettingsReadArchive, iqt::CSettingsWriteArchive, iser::CCompactXmlReadArchiveBase, iser::CCompactXmlWriteArchiveBase, iser::CJsonReadArchiveBase, and iser::CJsonWriteArchiveBase.

Referenced by imath::TFastVector< MaxSize, Element >::Serialize(), imath::TMathVectorWrap< Base >::Serialize(), imath::TMatrix< Width, Height, Element >::Serialize(), iattr::TAttribute< Value >::Serialize(), iattr::TMultiAttribute< Value >::Serialize(), ibase::TFactorisableContainer< InterfaceClass >::Serialize(), ibase::TSerializableContainer< ItemClass, ContainerType >::Serialize(), icmm::TComposedColor< Size >::Serialize(), idoc::TMultiPageDocumentWrap< Base >::Serialize(), ilog::TExtMessage< Element >::Serialize(), imath::TFulcrumGrid< Position, Fulcrums >::Serialize(), imath::TMultidimensionalPolynomial< Dimensions, Element >::Serialize(), Model::Serialize(), iser::CPrimitiveTypesSerializer::SerializeAssociativeContainer(), iser::CPrimitiveTypesSerializer::SerializeAssociativeObjectContainer(), iser::CPrimitiveTypesSerializer::SerializeContainer(), iser::CPrimitiveTypesSerializer::SerializeObjectContainer(), idoc::TMultiPageDocumentWrap< Base >::SerializePage(), iser::CPrimitiveTypesSerializer::SerializeRange(), and TagAndProcess().

◆ GetVersionInfo()

virtual const IVersionInfo & iser::IArchive::GetVersionInfo ( ) const
pure virtual

Gets version information for the archived stream.

Version information allows handling compatibility between different versions of your data format. You can query the version to decide whether to read optional or newly added fields.

Returns
Reference to version information object
const IVersionInfo& version = archive.GetVersionInfo();
if (version.GetVersion() >= CMyClass::VERSION_WITH_NEW_FIELD) {
// New field exists, read it
archive.Process(m_newField);
}
Provides access to version information.
See also
iser::IVersionInfo, iser::CMinimalVersionInfo

Implemented in iser::CReadArchiveBase, and iser::CWriteArchiveBase.

Referenced by ilog::TExtMessage< Element >::Serialize().

◆ IsStoring()

virtual bool iser::IArchive::IsStoring ( ) const
pure virtual

Checks if this archive is in storing (writing) or loading (reading) mode.

This method is fundamental for implementing bidirectional serialization. The same Serialize() method is used for both reading and writing, and IsStoring() tells you which operation is being performed.

Returns
true if the archive is writing/storing data, false if reading/loading data
virtual bool Serialize(iser::IArchive& archive)
{
if (archive.IsStoring()) {
// Prepare data for writing
int count = m_items.size();
archive.Process(count);
for (const Item& item : m_items) {
// Write items
}
} else {
// Read data
int count;
archive.Process(count);
m_items.clear();
for (int i = 0; i < count; ++i) {
// Read items
}
}
}
See also
Process()

Implemented in iser::CReadArchiveBase, and iser::CWriteArchiveBase.

Referenced by imath::TFastVector< MaxSize, Element >::Serialize(), imath::TMathVectorWrap< Base >::Serialize(), imath::TMatrix< Width, Height, Element >::Serialize(), iattr::TAttribute< Value >::Serialize(), iattr::TMultiAttribute< Value >::Serialize(), ibase::TFactorisableContainer< InterfaceClass >::Serialize(), ibase::TSerializableContainer< ItemClass, ContainerType >::Serialize(), icmm::TComposedColor< Size >::Serialize(), idoc::TMultiPageDocumentWrap< Base >::Serialize(), imath::TFulcrumGrid< Position, Fulcrums >::Serialize(), imath::TMultidimensionalPolynomial< Dimensions, Element >::Serialize(), iser::CPrimitiveTypesSerializer::SerializeAssociativeContainer(), iser::CPrimitiveTypesSerializer::SerializeAssociativeObjectContainer(), iser::CPrimitiveTypesSerializer::SerializeContainer(), iser::CPrimitiveTypesSerializer::SerializeEnum(), iser::CPrimitiveTypesSerializer::SerializeObjectContainer(), and iser::CPrimitiveTypesSerializer::SerializeQEnum().

◆ IsTagSkippingSupported()

virtual bool iser::IArchive::IsTagSkippingSupported ( ) const
pure virtual

Checks if skipping to the end of a tag on EndTag() is supported.

Some archive types (like XML) support skipping unread content within a tag, allowing forward compatibility. When reading an archive created by a newer version that added fields, this feature lets you skip unknown data.

Returns
true if the archive supports tag skipping, false otherwise
Note
Binary archives typically don't support skipping, requiring all data to be read sequentially.
XML and JSON archives usually support skipping.
if (archive.IsTagSkippingSupported()) {
// Can safely skip new fields added in future versions
} else {
// Must read all data in exact order
}
See also
EndTag()

Implemented in ifile::CFileReadArchive, ifile::CFileWriteArchive, iser::CArchiveBase, iser::CCompactXmlReadArchiveBase, iser::CCompactXmlWriteArchiveBase, iser::CJsonWriteArchiveBase, iser::CXmlReadArchiveBase, and iser::CXmlWriteArchiveBase.

◆ Process() [1/14]

virtual bool iser::IArchive::Process ( bool &  value)
pure virtual

◆ Process() [2/14]

virtual bool iser::IArchive::Process ( char &  value)
pure virtual

◆ Process() [3/14]

virtual bool iser::IArchive::Process ( double &  value)
pure virtual

◆ Process() [4/14]

virtual bool iser::IArchive::Process ( float &  value)
pure virtual

◆ Process() [5/14]

virtual bool iser::IArchive::Process ( QByteArray &  value)
pure virtual

◆ Process() [6/14]

virtual bool iser::IArchive::Process ( qint16 &  value)
pure virtual

◆ Process() [7/14]

virtual bool iser::IArchive::Process ( qint32 &  value)
pure virtual

◆ Process() [8/14]

virtual bool iser::IArchive::Process ( qint64 &  value)
pure virtual

◆ Process() [9/14]

virtual bool iser::IArchive::Process ( qint8 &  value)
pure virtual

◆ Process() [10/14]

virtual bool iser::IArchive::Process ( QString &  value)
pure virtual

◆ Process() [11/14]

virtual bool iser::IArchive::Process ( quint16 &  value)
pure virtual

◆ Process() [12/14]

virtual bool iser::IArchive::Process ( quint32 &  value)
pure virtual

◆ Process() [13/14]

virtual bool iser::IArchive::Process ( quint64 &  value)
pure virtual

◆ Process() [14/14]

virtual bool iser::IArchive::Process ( quint8 &  value)
pure virtual

◆ ProcessBits()

virtual bool iser::IArchive::ProcessBits ( void *  dataPtr,
int  bitsCount,
int  bytesCount 
)
pure virtual

Process binary data block.

Parameters
dataPtrpointer to memory block.
bitsCountnumber of bits.
bytesCountsize of memory block in bytes.

Implemented in iser::CBitMemoryWriteArchive, iser::CBitMemoryReadArchive, iser::CReadArchiveBase, and iser::CWriteArchiveBase.

◆ ProcessData()

virtual bool iser::IArchive::ProcessData ( void *  dataPtr,
int  size 
)
pure virtual

◆ TagAndProcess()

template<typename Primitive >
bool iser::IArchive::TagAndProcess ( const CArchiveTag tag,
Primitive &  value 
)
inline

Definition at line 437 of file IArchive.h.

References BeginTag(), EndTag(), and Process().


The documentation for this class was generated from the following file: