openMSX
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
openmsx::ArchiveBase< Derived > Class Template Reference

#include <serialize.hh>

Inheritance diagram for openmsx::ArchiveBase< Derived >:
Inheritance graph
[legend]

Public Member Functions

template<typename Base , typename T >
void serializeBase (T &t)
 Is this archive a loader or a saver.
 
template<typename Base , typename T >
void serializeInlinedBase (T &t, unsigned version)
 Serialize the base class of this classtype.
 
template<typename T >
void serialize_blob (const char *tag, std::span< T > data, bool diff=true)
 
template<typename T >
void serialize_blob (const char *tag, std::span< const T > data, bool diff=true)
 
bool isReverseSnapshot () const
 Is this a reverse-snapshot?
 
template<typename T >
void attribute (const char *name, T &t)
 Load/store an attribute from/in the archive.
 
void attribute (const char *name, const char *value)
 
bool hasAttribute (const char *) const
 Check the presence of a (optional) attribute.
 
template<typename T >
std::optional< T > findAttributeAs (const char *)
 Optimization: combination of hasAttribute() and getAttribute().
 
int countChildren () const
 Count the number of child tags.
 
void beginTag (const char *) const
 Indicate begin of a tag.
 
void endTag (const char *) const
 Indicate begin of a tag.
 

Static Public Attributes

static constexpr bool NEED_VERSION = true
 Does this archive store version information.
 
static constexpr bool TRANSLATE_ENUM_TO_STRING = false
 Does this archive store enums as strings.
 
static constexpr bool CAN_HAVE_OPTIONAL_ATTRIBUTES = false
 Some archives (like XML archives) can store optional attributes.
 
static constexpr bool CAN_COUNT_CHILDREN = false
 Some archives (like XML archives) can count the number of subtags that belong to the current tag.
 

Protected Member Functions

Derived & self ()
 Returns a reference to the most derived class.
 

Detailed Description

template<typename Derived>
class openmsx::ArchiveBase< Derived >

Definition at line 81 of file serialize.hh.

Member Function Documentation

◆ attribute() [1/2]

template<typename Derived >
void openmsx::ArchiveBase< Derived >::attribute ( const char *  name,
const char *  value 
)

Definition at line 30 of file serialize.cc.

◆ attribute() [2/2]

template<typename Derived >
template<typename T >
void openmsx::ArchiveBase< Derived >::attribute ( const char *  name,
T &  t 
)
inline

Load/store an attribute from/in the archive.

Depending on the underlying concrete stream, attributes are either stored like XML attributes or as regular values. Because of this (and thus unlike XML attributes) the order of attributes matter. It also matters whether an attribute is present or not.

Definition at line 248 of file serialize.hh.

References openmsx::ArchiveBase< Derived >::self(), and t.

◆ beginTag()

template<typename Derived >
void openmsx::ArchiveBase< Derived >::beginTag ( const char *  ) const
inline

Indicate begin of a tag.

Only XML archives use this, other archives ignore it. XML saver uses it as a name for the current tag, it doesn't interpret the name in any way. XML loader uses it only as a check: it checks whether the current tag name matches the given name. So we will NOT search the tag with the given name, the tags have to be in the correct order.

Definition at line 306 of file serialize.hh.

◆ countChildren()

template<typename Derived >
int openmsx::ArchiveBase< Derived >::countChildren ( ) const
inline

Count the number of child tags.

It's only allowed to call this method on archives that have support for this operation.

Definition at line 293 of file serialize.hh.

References UNREACHABLE.

◆ endTag()

template<typename Derived >
void openmsx::ArchiveBase< Derived >::endTag ( const char *  ) const
inline

Indicate begin of a tag.

Only XML archives use this, other archives ignore it. Both XML loader and saver only use the given tag name to do some internal checks (with checks disabled, the tag parameter has no influence at all on loading or saving of the stream).

Definition at line 316 of file serialize.hh.

◆ findAttributeAs()

template<typename Derived >
template<typename T >
std::optional< T > openmsx::ArchiveBase< Derived >::findAttributeAs ( const char *  )
inline

Optimization: combination of hasAttribute() and getAttribute().

Returns true if hasAttribute() and (if so) also fills in the value.

Definition at line 274 of file serialize.hh.

References UNREACHABLE.

◆ hasAttribute()

template<typename Derived >
bool openmsx::ArchiveBase< Derived >::hasAttribute ( const char *  ) const
inline

Check the presence of a (optional) attribute.

It's only allowed to call this method on archives that can have optional attributes.

Definition at line 265 of file serialize.hh.

References UNREACHABLE.

◆ isReverseSnapshot()

template<typename Derived >
bool openmsx::ArchiveBase< Derived >::isReverseSnapshot ( ) const
inline

Is this a reverse-snapshot?

Definition at line 235 of file serialize.hh.

◆ self()

template<typename Derived >
Derived & openmsx::ArchiveBase< Derived >::self ( )
inlineprotected

◆ serialize_blob() [1/2]

template<typename Derived >
template<typename T >
void openmsx::ArchiveBase< Derived >::serialize_blob ( const char *  tag,
std::span< const T >  data,
bool  diff = true 
)
inline

Definition at line 158 of file serialize.hh.

References openmsx::ArchiveBase< Derived >::self().

◆ serialize_blob() [2/2]

template<typename Derived >
template<typename T >
void openmsx::ArchiveBase< Derived >::serialize_blob ( const char *  tag,
std::span< T >  data,
bool  diff = true 
)
inline

Definition at line 153 of file serialize.hh.

References openmsx::ArchiveBase< Derived >::self().

◆ serializeBase()

template<typename Derived >
template<typename Base , typename T >
void openmsx::ArchiveBase< Derived >::serializeBase ( T &  t)
inline

Is this archive a loader or a saver.

static constexpr bool IS_LOADER = ...; Serialize the base class of this classtype. Should preferably be called as the first statement in the implementation of a serialize() method of a class type. See also serializeInlinedBase() below.

Definition at line 93 of file serialize.hh.

References openmsx::ArchiveBase< Derived >::self(), and t.

◆ serializeInlinedBase()

template<typename Derived >
template<typename Base , typename T >
void openmsx::ArchiveBase< Derived >::serializeInlinedBase ( T &  t,
unsigned  version 
)
inline

Serialize the base class of this classtype.

Should preferably be called as the first statement in the implementation of a serialize() method of a class type. See also serializeBase() above.

The difference between serializeBase() and serializeInlinedBase() is only relevant for versioned archives (see NEED_VERSION, e.g. XML archives). In XML archives serializeBase() will put the base class in a new subtag, serializeInlinedBase() puts the members of the base class (inline) in the current tag. The advantage of serializeBase() is that the base class can be versioned separately from the subclass. The disadvantage is that it exposes an internal implementation detail in the XML file, and thus makes it harder to for example change the class hierarchy or move members from base to subclass or vice-versa.

Definition at line 116 of file serialize.hh.

References openmsx::ArchiveBase< Derived >::self(), openmsx::serialize(), and t.

Member Data Documentation

◆ CAN_COUNT_CHILDREN

template<typename Derived >
constexpr bool openmsx::ArchiveBase< Derived >::CAN_COUNT_CHILDREN = false
staticconstexpr

Some archives (like XML archives) can count the number of subtags that belong to the current tag.

This method indicates whether that's the case for this archive or not. This can for example be used to make the XML files look prettier in case of serialization of collections: in that case we don't need to explicitly store the size of the collection, it can be derived from the number of subtags.

Definition at line 287 of file serialize.hh.

◆ CAN_HAVE_OPTIONAL_ATTRIBUTES

template<typename Derived >
constexpr bool openmsx::ArchiveBase< Derived >::CAN_HAVE_OPTIONAL_ATTRIBUTES = false
staticconstexpr

Some archives (like XML archives) can store optional attributes.

This method indicates whether that's the case or not. This can be used to for example in XML files don't store attributes with default values (thus to make the XML look prettier).

Definition at line 259 of file serialize.hh.

◆ NEED_VERSION

template<typename Derived >
constexpr bool openmsx::ArchiveBase< Derived >::NEED_VERSION = true
staticconstexpr

Does this archive store version information.

Definition at line 232 of file serialize.hh.

◆ TRANSLATE_ENUM_TO_STRING

template<typename Derived >
constexpr bool openmsx::ArchiveBase< Derived >::TRANSLATE_ENUM_TO_STRING = false
staticconstexpr

Does this archive store enums as strings.

See also struct serialize_as_enum.

Definition at line 240 of file serialize.hh.


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