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. More...
 
template<typename Base , typename T >
void serializeInlinedBase (T &t, unsigned version)
 Serialize the base class of this classtype. More...
 
bool isReverseSnapshot () const
 Is this a reverse-snapshot? More...
 
template<typename T >
void attribute (const char *name, T &t)
 Load/store an attribute from/in the archive. More...
 
void attribute (const char *name, const char *value)
 
bool hasAttribute (const char *)
 Check the presence of a (optional) attribute. More...
 
bool findAttribute (const char *, unsigned &)
 Optimization: combination of hasAttribute() and getAttribute(). More...
 
int countChildren () const
 Count the number of child tags. More...
 
void beginTag (const char *)
 Indicate begin of a tag. More...
 
void endTag (const char *)
 Indicate begin of a tag. More...
 

Static Public Attributes

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

Protected Member Functions

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

Detailed Description

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

Definition at line 76 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 27 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 232 of file serialize.hh.

References openmsx::serialize(), and t.

◆ beginTag()

template<typename Derived >
void openmsx::ArchiveBase< Derived >::beginTag ( const char *  )
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 289 of file serialize.hh.

Referenced by openmsx::InputArchiveBase< Derived >::doSerialize(), openmsx::OutputArchiveBase< Derived >::serialize(), openmsx::InputArchiveBase< Derived >::serialize(), openmsx::InputArchiveBase< Derived >::serializeChar(), openmsx::OutputArchiveBase< Derived >::serializeChar(), openmsx::OutputArchiveBase< Derived >::serializePointerID(), openmsx::InputArchiveBase< Derived >::serializePointerID(), and openmsx::OutputArchiveBase< Derived >::serializeWithID().

◆ 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 276 of file serialize.hh.

References UNREACHABLE.

◆ endTag()

template<typename Derived >
void openmsx::ArchiveBase< Derived >::endTag ( const char *  )
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 299 of file serialize.hh.

Referenced by openmsx::InputArchiveBase< Derived >::doSerialize(), openmsx::OutputArchiveBase< Derived >::serialize(), openmsx::InputArchiveBase< Derived >::serialize(), openmsx::InputArchiveBase< Derived >::serializeChar(), openmsx::OutputArchiveBase< Derived >::serializeChar(), openmsx::OutputArchiveBase< Derived >::serializePointerID(), openmsx::InputArchiveBase< Derived >::serializePointerID(), and openmsx::OutputArchiveBase< Derived >::serializeWithID().

◆ findAttribute()

template<typename Derived >
bool openmsx::ArchiveBase< Derived >::findAttribute ( const char *  ,
unsigned &   
)
inline

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

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

Definition at line 257 of file serialize.hh.

References UNREACHABLE.

◆ hasAttribute()

template<typename Derived >
bool openmsx::ArchiveBase< Derived >::hasAttribute ( const char *  )
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 249 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 219 of file serialize.hh.

◆ self()

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

Returns a reference to the most derived class.

Helper function to implement static polymorphism.

Definition at line 342 of file serialize.hh.

◆ 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 88 of file serialize.hh.

References openmsx::Keys::getName(), openmsx::serialize(), 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 differece 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 111 of file serialize.hh.

References 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 270 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 243 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 216 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 224 of file serialize.hh.


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