libfoedus-core
FOEDUS Core Library
|
Represents an object that can be written to and read from files/bytes in XML format. More...
Represents an object that can be written to and read from files/bytes in XML format.
Derived classes must implement load() and save().
Definition at line 53 of file externalizable.hpp.
#include <externalizable.hpp>
Public Member Functions | |
virtual ErrorStack | load (tinyxml2::XMLElement *element)=0 |
Reads the content of this object from the given XML element. More... | |
virtual ErrorStack | save (tinyxml2::XMLElement *element) const =0 |
Writes the content of this object to the given XML element. More... | |
virtual const char * | get_tag_name () const =0 |
Returns an XML tag name for this object as a root element. More... | |
virtual void | assign (const foedus::externalize::Externalizable *other)=0 |
Polymorphic assign operator. More... | |
ErrorStack | load_from_string (const std::string &xml) |
Load the content of this object from the given XML string. More... | |
void | save_to_stream (std::ostream *ptr) const |
Invokes save() and directs the resulting XML text to the given stream. More... | |
ErrorStack | load_from_file (const fs::Path &path) |
Load the content of this object from the specified XML file. More... | |
ErrorStack | save_to_file (const fs::Path &path) const |
Atomically and durably writes out this object to the specified XML file. More... | |
Static Public Member Functions | |
static ErrorStack | insert_comment (tinyxml2::XMLElement *element, const std::string &comment) |
static ErrorStack | append_comment (tinyxml2::XMLElement *parent, const std::string &comment) |
static ErrorStack | create_element (tinyxml2::XMLElement *parent, const std::string &name, tinyxml2::XMLElement **out) |
template<typename T > | |
static ErrorStack | add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, T value) |
Only declaration in header. More... | |
template<uint MAXLEN, typename CHAR > | |
static ErrorStack | add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const assorted::FixedString< MAXLEN, CHAR > &value) |
template<typename T > | |
static ErrorStack | add_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const std::vector< T > &value) |
vector version More... | |
template<typename ENUM > | |
static ErrorStack | add_enum_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, ENUM value) |
enum version More... | |
static ErrorStack | add_child_element (tinyxml2::XMLElement *parent, const std::string &tag, const std::string &comment, const Externalizable &child) |
child Externalizable version More... | |
template<typename T > | |
static ErrorStack | get_element (tinyxml2::XMLElement *parent, const std::string &tag, T *out, bool optional=false, T value=0) |
Only declaration in header. More... | |
static ErrorStack | get_element (tinyxml2::XMLElement *parent, const std::string &tag, std::string *out, bool optional=false, const char *value="") |
string type is bit special. More... | |
template<uint MAXLEN, typename CHAR > | |
static ErrorStack | get_element (tinyxml2::XMLElement *parent, const std::string &tag, assorted::FixedString< MAXLEN, CHAR > *out, bool optional=false, const assorted::FixedString< MAXLEN, CHAR > &value=assorted::FixedString< MAXLEN, CHAR >()) |
template<typename ENUM > | |
static ErrorStack | get_enum_element (tinyxml2::XMLElement *parent, const std::string &tag, ENUM *out, bool optional=false, ENUM default_value=static_cast< ENUM >(0)) |
enum version More... | |
template<typename T > | |
static ErrorStack | get_element (tinyxml2::XMLElement *parent, const std::string &tag, std::vector< T > *out, bool optional=false) |
vector version. More... | |
static ErrorStack | get_child_element (tinyxml2::XMLElement *parent, const std::string &tag, Externalizable *child, bool optional=false) |
child Externalizable version More... | |
|
static |
child Externalizable version
Definition at line 221 of file externalizable.cpp.
References CHECK_ERROR, CHECK_OUTOFMEMORY, foedus::externalize::insert_comment_impl(), foedus::kRetOk, and save().
Referenced by foedus::log::LogOptions::save(), foedus::EngineOptions::save(), foedus::snapshot::SnapshotOptions::save(), foedus::storage::save_to_xml_array(), foedus::storage::save_to_xml_hash(), foedus::storage::save_to_xml_masstree(), and foedus::storage::save_to_xml_sequential().
|
static |
Only declaration in header.
Explicitly instantiated in cpp for each type this func handles.
Definition at line 200 of file externalizable.cpp.
References CHECK_ERROR, CHECK_OUTOFMEMORY, foedus::externalize::insert_comment_impl(), and foedus::kRetOk.
Referenced by add_element(), add_enum_element(), foedus::storage::sequential::SequentialMetadataSerializer::save(), foedus::storage::hash::HashMetadataSerializer::save(), foedus::storage::array::ArrayMetadataSerializer::save(), foedus::storage::masstree::MasstreeMetadataSerializer::save(), and foedus::storage::MetadataSerializer::save_base().
|
inlinestatic |
Definition at line 134 of file externalizable.hpp.
References foedus::assorted::FixedString< MAXLEN, CHAR >::str().
|
inlinestatic |
vector version
Definition at line 144 of file externalizable.hpp.
References add_element(), append_comment(), CHECK_ERROR, foedus::assorted::get_pretty_type_name(), and foedus::kRetOk.
|
inlinestatic |
enum version
Definition at line 159 of file externalizable.hpp.
References add_element().
Referenced by foedus::storage::MetadataSerializer::save_base().
|
static |
Definition at line 181 of file externalizable.cpp.
References CHECK_OUTOFMEMORY, and foedus::kRetOk.
Referenced by add_element().
|
pure virtual |
Polymorphic assign operator.
This should invoke operator= of the derived class.
[in] | other | assigned value. It must be dynamic-castable to the assignee class. |
Implemented in foedus::snapshot::SnapshotOptions, foedus::EngineOptions, foedus::storage::masstree::MasstreeMetadataSerializer, foedus::memory::MemoryOptions, foedus::savepoint::Savepoint, foedus::log::LogOptions, foedus::debugging::DebuggingOptions, foedus::cache::CacheOptions, foedus::soc::SocOptions, foedus::storage::array::ArrayMetadataSerializer, foedus::storage::hash::HashMetadataSerializer, foedus::storage::sequential::SequentialMetadataSerializer, foedus::proc::ProcOptions, foedus::fs::DeviceEmulationOptions, foedus::thread::ThreadOptions, foedus::xct::XctOptions, foedus::storage::StorageOptions, foedus::snapshot::SnapshotMetadata, foedus::savepoint::SavepointOptions, and foedus::restart::RestartOptions.
|
static |
Definition at line 191 of file externalizable.cpp.
References CHECK_OUTOFMEMORY, and foedus::kRetOk.
|
static |
child Externalizable version
Definition at line 293 of file externalizable.cpp.
References ERROR_STACK_MSG, foedus::kErrorCodeConfMissingElement, foedus::kRetOk, and load().
Referenced by foedus::log::LogOptions::load(), foedus::EngineOptions::load(), and foedus::snapshot::SnapshotOptions::load().
|
static |
Only declaration in header.
Explicitly instantiated in cpp for each type this func handles.
Definition at line 232 of file externalizable.cpp.
References ERROR_STACK_MSG, foedus::kErrorCodeConfInvalidElement, foedus::kErrorCodeConfMissingElement, and foedus::kRetOk.
Referenced by get_element(), foedus::storage::sequential::SequentialMetadataSerializer::load(), foedus::storage::hash::HashMetadataSerializer::load(), foedus::storage::array::ArrayMetadataSerializer::load(), foedus::storage::masstree::MasstreeMetadataSerializer::load(), foedus::storage::MetadataSerializer::load_all_storages_from_xml(), and foedus::storage::MetadataSerializer::load_base().
|
static |
string type is bit special.
Definition at line 260 of file externalizable.cpp.
|
inlinestatic |
Definition at line 178 of file externalizable.hpp.
References foedus::assorted::FixedString< MAXLEN, CHAR >::assign(), CHECK_ERROR, get_element(), and foedus::kRetOk.
|
static |
vector version.
Only declaration in header. Explicitly instantiated in cpp for each type this func handles.
Definition at line 266 of file externalizable.cpp.
References ERROR_STACK_MSG, foedus::kErrorCodeConfInvalidElement, foedus::kErrorCodeConfMissingElement, and foedus::kRetOk.
|
inlinestatic |
enum version
Definition at line 192 of file externalizable.hpp.
References CHECK_ERROR, ERROR_STACK_MSG, foedus::kErrorCodeConfValueOutofrange, and foedus::kRetOk.
Referenced by foedus::storage::MetadataSerializer::load_all_storages_from_xml(), and foedus::storage::MetadataSerializer::load_base().
|
pure virtual |
Returns an XML tag name for this object as a root element.
We might want to give a different name for same externalizable objects, so this is used only when it is the root element of xml.
Implemented in foedus::snapshot::SnapshotOptions, foedus::EngineOptions, foedus::storage::masstree::MasstreeMetadataSerializer, foedus::memory::MemoryOptions, foedus::savepoint::Savepoint, foedus::log::LogOptions, foedus::debugging::DebuggingOptions, foedus::cache::CacheOptions, foedus::soc::SocOptions, foedus::storage::array::ArrayMetadataSerializer, foedus::storage::hash::HashMetadataSerializer, foedus::storage::sequential::SequentialMetadataSerializer, foedus::proc::ProcOptions, foedus::fs::DeviceEmulationOptions, foedus::thread::ThreadOptions, foedus::xct::XctOptions, foedus::storage::StorageOptions, foedus::snapshot::SnapshotMetadata, foedus::savepoint::SavepointOptions, and foedus::restart::RestartOptions.
Referenced by save_to_file(), and save_to_stream().
|
static |
Definition at line 177 of file externalizable.cpp.
References foedus::externalize::insert_comment_impl().
Referenced by foedus::restart::RestartOptions::save(), foedus::savepoint::SavepointOptions::save(), foedus::snapshot::SnapshotMetadata::save(), foedus::storage::StorageOptions::save(), foedus::xct::XctOptions::save(), foedus::thread::ThreadOptions::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(), foedus::EngineOptions::save(), and foedus::snapshot::SnapshotOptions::save().
|
pure virtual |
Reads the content of this object from the given XML element.
[in] | element | the XML element that represents this object |
Expect errors due to missing-elements, out-of-range values, etc.
Implemented in foedus::snapshot::SnapshotOptions, foedus::EngineOptions, foedus::storage::masstree::MasstreeMetadataSerializer, foedus::memory::MemoryOptions, foedus::savepoint::Savepoint, foedus::log::LogOptions, foedus::debugging::DebuggingOptions, foedus::cache::CacheOptions, foedus::soc::SocOptions, foedus::storage::array::ArrayMetadataSerializer, foedus::storage::hash::HashMetadataSerializer, foedus::storage::sequential::SequentialMetadataSerializer, foedus::proc::ProcOptions, foedus::fs::DeviceEmulationOptions, foedus::thread::ThreadOptions, foedus::xct::XctOptions, foedus::storage::StorageOptions, foedus::snapshot::SnapshotMetadata, foedus::savepoint::SavepointOptions, and foedus::restart::RestartOptions.
Referenced by get_child_element(), load_from_file(), and load_from_string().
ErrorStack foedus::externalize::Externalizable::load_from_file | ( | const fs::Path & | path | ) |
Load the content of this object from the specified XML file.
[in] | path | path of the XML file. |
Expect errors due to missing-elements, out-of-range values, etc.
Definition at line 75 of file externalizable.cpp.
References foedus::fs::Path::c_str(), CHECK_ERROR, ERROR_STACK_MSG, foedus::fs::exists(), foedus::kErrorCodeConfEmptyXml, foedus::kErrorCodeConfFileNotFount, foedus::kErrorCodeConfParseFailed, foedus::kRetOk, and load().
Referenced by foedus::savepoint::SavepointManagerPimpl::initialize_once(), and foedus::snapshot::SnapshotManagerPimpl::read_snapshot_metadata().
ErrorStack foedus::externalize::Externalizable::load_from_string | ( | const std::string & | xml | ) |
Load the content of this object from the given XML string.
[in] | xml | XML string. |
Expect errors due to missing-elements, out-of-range values, etc.
Definition at line 38 of file externalizable.cpp.
References CHECK_ERROR, ERROR_STACK_MSG, foedus::kErrorCodeConfEmptyXml, foedus::kErrorCodeConfParseFailed, foedus::kRetOk, and load().
Referenced by foedus::soc::SharedMemoryRepo::attach_shared_memories().
|
pure virtual |
Writes the content of this object to the given XML element.
[in] | element | the XML element that represents this object |
Expect only out-of-memory error. We receive the XML element this object will represent, so this method does not determine the XML element name of itself. The parent object determines children's tag names because one parent object might have multiple child objects of the same type with different XML element name.
Implemented in foedus::snapshot::SnapshotOptions, foedus::EngineOptions, foedus::storage::masstree::MasstreeMetadataSerializer, foedus::memory::MemoryOptions, foedus::savepoint::Savepoint, foedus::log::LogOptions, foedus::debugging::DebuggingOptions, foedus::cache::CacheOptions, foedus::soc::SocOptions, foedus::storage::array::ArrayMetadataSerializer, foedus::storage::hash::HashMetadataSerializer, foedus::storage::sequential::SequentialMetadataSerializer, foedus::proc::ProcOptions, foedus::fs::DeviceEmulationOptions, foedus::thread::ThreadOptions, foedus::xct::XctOptions, foedus::storage::StorageOptions, foedus::snapshot::SnapshotMetadata, foedus::savepoint::SavepointOptions, and foedus::restart::RestartOptions.
Referenced by add_child_element(), save_to_file(), and save_to_stream().
ErrorStack foedus::externalize::Externalizable::save_to_file | ( | const fs::Path & | path | ) | const |
Atomically and durably writes out this object to the specified XML file.
[in] | path | path of the XML file. |
If the file exists, this method atomically overwrites it via POSIX's atomic rename semantics. If the parent folder doesn't exist, this method automatically creates the folder. Expect errors due to file-permission (and other file I/O issue), out-of-memory, etc.
Definition at line 96 of file externalizable.cpp.
References foedus::memory::AlignedMemory::alloc(), CHECK_ERROR, CHECK_OUTOFMEMORY, foedus::fs::DirectIoFile::close(), foedus::fs::create_directories(), foedus::fs::durable_atomic_rename(), ERROR_STACK_MSG, foedus::fs::exists(), foedus::fs::fsync(), get_tag_name(), foedus::kErrorCodeConfCouldNotRename, foedus::kErrorCodeConfCouldNotWrite, foedus::kErrorCodeConfMkdirsFailed, foedus::memory::AlignedMemory::kPosixMemalign, foedus::kRetOk, foedus::fs::DirectIoFile::open(), foedus::assorted::os_error(), foedus::fs::Path::parent_path(), save(), foedus::fs::unique_name(), WRAP_ERROR_CODE, and foedus::fs::DirectIoFile::write().
Referenced by foedus::savepoint::SavepointManagerPimpl::initialize_once(), foedus::savepoint::SavepointManagerPimpl::savepoint_main(), and foedus::snapshot::SnapshotManagerPimpl::snapshot_metadata().
void foedus::externalize::Externalizable::save_to_stream | ( | std::ostream * | ptr | ) | const |
Invokes save() and directs the resulting XML text to the given stream.
[in] | ptr | ostream to write to. |
Definition at line 55 of file externalizable.cpp.
References get_tag_name(), foedus::ErrorStack::is_error(), and save().
Referenced by foedus::soc::SharedMemoryRepo::allocate_shared_memories().