libfoedus-core
FOEDUS Core Library
Object Externalization

Object Externalization. More...

Detailed Description

Object Externalization.

Overview
Analogous to java.io.Externalizable. We externalize savepoint and configuration objects. We never use them for main data files, so the code here does not have to be seriously optimized.
tinyxml2 rather than boost::serialize
boost::serialize is not header-only. Rather, we contain tinyxml2, a handy zlib-licensed library with a CMake project file. This gives an added benefit of pretty XML file as the resulting file, which can be hand-editted with text editor. For more details of tinyxml2, see http://www.grinninglizard.com/tinyxml2/
Terminology: Externalization vs Serialization
I just picked the word Externalize because serialization, or serializable, has totally different meanings in DBMS and lock-free algorithm.
Collaboration diagram for Object Externalization:

Classes

struct  foedus::externalize::Externalizable
 Represents an object that can be written to and read from files/bytes in XML format. More...
 
struct  foedus::externalize::TinyxmlGetter< T >
 Functor to help use tinyxml2's Element QueryXxxText(). More...
 
struct  foedus::externalize::TinyxmlSetter< T >
 Functor to help use tinyxml2's Element SetText(). More...
 

Macros

#define EXTERNALIZE_SAVE_ELEMENT(element, attribute, comment)   CHECK_ERROR(add_element(element, EX_EXPAND(attribute), comment, attribute))
 Adds an xml element to represent a member variable of this object. More...
 
#define EXTERNALIZE_SAVE_ENUM_ELEMENT(element, attribute, comment)   CHECK_ERROR(add_enum_element(element, EX_EXPAND(attribute), comment, attribute))
 Adds an xml element to represent a member variable of this object. More...
 
#define EXTERNALIZE_LOAD_ELEMENT(element, attribute)   CHECK_ERROR(get_element(element, EX_EXPAND(attribute), & attribute))
 Reads a child xml element to load a member variable of this object. More...
 
#define EXTERNALIZE_LOAD_ELEMENT_OPTIONAL(element, attribute, default_value)   CHECK_ERROR(get_element(element, EX_EXPAND(attribute), & attribute, true, default_value))
 Reads a child xml element to load a member variable of this object. More...
 
#define EXTERNALIZE_LOAD_ENUM_ELEMENT(element, attribute)   CHECK_ERROR(get_enum_element(element, EX_EXPAND(attribute), & attribute))
 Reads a child xml element to load a member variable of this object. More...
 
#define EXTERNALIZE_LOAD_ENUM_ELEMENT_OPTIONAL(element, attribute, default_value)   CHECK_ERROR(get_enum_element(element, EX_EXPAND(attribute), & attribute, true, default_value))
 Reads a child xml element to load a member variable of this object. More...
 
#define EXTERNALIZABLE(clazz)
 Macro to declare/define essential methods for an externalizable class. More...
 

Macro Definition Documentation

#define EXTERNALIZABLE (   clazz)
Value:
ErrorStack load(tinyxml2::XMLElement* element) CXX11_OVERRIDE;\
ErrorStack save(tinyxml2::XMLElement* element) const CXX11_OVERRIDE;\
const char* get_tag_name() const CXX11_OVERRIDE { return EX_EXPAND(clazz); }\
*this = *dynamic_cast< const clazz * >(other);\
}\
friend std::ostream& operator<<(std::ostream& o, const clazz & v) {\
v.save_to_stream(&o);\
return o;\
}
Represents an object that can be written to and read from files/bytes in XML format.
#define CXX11_OVERRIDE
Used in public headers in place of "override" of C++11.
Definition: cxx11.hpp:134
#define EX_EXPAND(str)
std::ostream & operator<<(std::ostream &o, const Hex &v)

Macro to declare/define essential methods for an externalizable class.

Each externalizable class should invoke this macro in public scope of class definition. Then, it should define load() and save() in cpp.

Definition at line 294 of file externalizable.hpp.

#define EXTERNALIZE_LOAD_ELEMENT (   element,
  attribute 
)    CHECK_ERROR(get_element(element, EX_EXPAND(attribute), & attribute))
#define EXTERNALIZE_LOAD_ELEMENT_OPTIONAL (   element,
  attribute,
  default_value 
)    CHECK_ERROR(get_element(element, EX_EXPAND(attribute), & attribute, true, default_value))

Reads a child xml element to load a member variable of this object.

Parameters
[in]elementthe current XML element that represents this, in other words parent of the element to read.
[in]attributethe member variable of this to save. This is also used as tag name.
[in]default_valueIf the element doesn't exist, this value is set to the variable.

For optional elements, use this.

Definition at line 264 of file externalizable.hpp.

#define EXTERNALIZE_LOAD_ENUM_ELEMENT (   element,
  attribute 
)    CHECK_ERROR(get_enum_element(element, EX_EXPAND(attribute), & attribute))

Reads a child xml element to load a member variable of this object.

Parameters
[in]elementthe current XML element that represents this, in other words parent of the element to read.
[in]attributethe member variable of this to save. This is also used as tag name.

For enum, use this one.

Definition at line 274 of file externalizable.hpp.

Referenced by foedus::thread::ThreadOptions::load(), foedus::soc::SocOptions::load(), and foedus::debugging::DebuggingOptions::load().

#define EXTERNALIZE_LOAD_ENUM_ELEMENT_OPTIONAL (   element,
  attribute,
  default_value 
)    CHECK_ERROR(get_enum_element(element, EX_EXPAND(attribute), & attribute, true, default_value))

Reads a child xml element to load a member variable of this object.

Parameters
[in]elementthe current XML element that represents this, in other words parent of the element to read.
[in]attributethe member variable of this to save. This is also used as tag name.
[in]default_valueIf the element doesn't exist, this value is set to the variable.

For optional elements, use this.

For optional enum, use this one.

Definition at line 283 of file externalizable.hpp.

#define EXTERNALIZE_SAVE_ELEMENT (   element,
  attribute,
  comment 
)    CHECK_ERROR(add_element(element, EX_EXPAND(attribute), comment, attribute))

Adds an xml element to represent a member variable of this object.

Parameters
[in]elementthe current XML element that represents this, in other words parent of the new element.
[in]attributethe member variable of this to save. This is also used as tag name.
[in]commentthis is output as an XML comment.

Definition at line 234 of file externalizable.hpp.

Referenced by foedus::savepoint::SavepointOptions::save(), foedus::snapshot::SnapshotMetadata::save(), foedus::storage::StorageOptions::save(), foedus::thread::ThreadOptions::save(), foedus::xct::XctOptions::save(), foedus::fs::DeviceEmulationOptions::save(), foedus::proc::ProcOptions::save(), foedus::soc::SocOptions::save(), foedus::cache::CacheOptions::save(), foedus::debugging::DebuggingOptions::save(), foedus::log::LogOptions::save(), foedus::savepoint::Savepoint::save(), foedus::memory::MemoryOptions::save(), and foedus::snapshot::SnapshotOptions::save().

#define EXTERNALIZE_SAVE_ENUM_ELEMENT (   element,
  attribute,
  comment 
)    CHECK_ERROR(add_enum_element(element, EX_EXPAND(attribute), comment, attribute))

Adds an xml element to represent a member variable of this object.

Parameters
[in]elementthe current XML element that represents this, in other words parent of the new element.
[in]attributethe member variable of this to save. This is also used as tag name.
[in]commentthis is output as an XML comment.

For enums, use this one.

Definition at line 243 of file externalizable.hpp.

Referenced by foedus::thread::ThreadOptions::save(), foedus::soc::SocOptions::save(), and foedus::debugging::DebuggingOptions::save().