libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
crn::Savable Class Reference

complex base abstract class More...

#include <CRNSavable.h>

+ Inheritance diagram for crn::Savable:
+ Collaboration diagram for crn::Savable:

Public Member Functions

 Savable (const String &s=U"")
 Default constructor. More...
 
virtual ~Savable ()
 Destructor. More...
 
 Savable (const Savable &)=delete
 No copy construction allowed. More...
 
Savableoperator= (const Savable &)=delete
 No assignment allowed. More...
 
 Savable (Savable &&) noexcept
 
Savableoperator= (Savable &&c)
 
const StringGetName () const
 Returns the name of the object. More...
 
void SetName (const String &s)
 Sets the name of the object. More...
 
void SetName (String &&s) noexcept
 Sets the name of the object. More...
 
void SetUserData (const String &key, SObject value)
 Adds or replaces a user data. More...
 
bool IsUserData (const String &key) const
 Tests if a user data key exists. More...
 
SObject GetUserData (const String &key)
 Gets a user data by key. More...
 
String GetUserDataKey (const SObject &value) const
 Gets a user data key by value. More...
 
const SObject GetUserData (const String &key) const
 Gets a user data by key. More...
 
void DeleteUserData (const String &key)
 Deletes a user data entry and frees the value. More...
 
void ClearUserData ()
 Deletes all user data entries. More...
 
 Savable (const String &s, const Path &fname)
 Constructor from file name. More...
 
void Load (const Path &fname)
 Loads the object from an XML file (Safe) More...
 
void Save (const Path &fname)
 Saves the object to an XML file (Safe) More...
 
void Save ()
 Saves the object to an already set XML file. More...
 
const PathGetFilename () const noexcept
 Returns the file name of the object. More...
 
void deserialize_internal_data (xml::Element &el)
 Initializes some internal data from an XML element. More...
 
void serialize_internal_data (xml::Element &el) const
 Dumps some internal data to an XML element. More...
 
- Public Member Functions inherited from crn::Object
virtual ~Object ()=default
 

Protected Member Functions

void setFilename (const Path &fname)
 Overwrites the filename. More...
 
void setFilename (Path &&fname) noexcept
 Overwrites the filename. More...
 

Protected Attributes

std::unique_ptr< std::mutex > filelock
 

Detailed Description

complex base abstract class

A more complex base abstract class.

This class offers several informal protocols. If an informal protocal's method is called without having been implemented, an exception will be thrown. The overloadable methods are the following (in parenthesis, the flag to activate in CRNProtocols.h):

Author
Yann LEYDIER
Date
August 2007
Version
0.2

Definition at line 58 of file CRNSavable.h.

Constructor & Destructor Documentation

Savable::Savable ( const String s = U"")

Default constructor.

Default constructor

Parameters
[in]sthe name of the object

Definition at line 36 of file CRNSavable.cpp.

Savable::~Savable ( )
virtual

Destructor.

Destructor. Frees the user data.

Definition at line 47 of file CRNSavable.cpp.

crn::Savable::Savable ( const Savable )
delete

No copy construction allowed.

Savable::Savable ( Savable &&  )
defaultnoexcept
Savable::Savable ( const String s,
const Path fname 
)

Constructor from file name.

Constructor from file name. Does not load the file!

Parameters
[in]sthe name of the object
[in]fnamethe file name

Definition at line 170 of file CRNSavable.cpp.

Member Function Documentation

void Savable::ClearUserData ( )

Deletes all user data entries.

Deletes all user data entries

Definition at line 155 of file CRNSavable.cpp.

void Savable::DeleteUserData ( const String key)

Deletes a user data entry and frees the value.

Deletes a user data entry and frees the value

Exceptions
ExceptionNotFoundkey not found
Parameters
[in]keyThe data key

Definition at line 132 of file CRNSavable.cpp.

void Savable::deserialize_internal_data ( xml::Element el)

Initializes some internal data from an XML element.

Internal. Initializes some internal data from an XML element.

Parameters
[in]elthe element that contains the serialized object

Definition at line 282 of file CRNSavable.cpp.

const Path& crn::Savable::GetFilename ( ) const
inlinenoexcept

Returns the file name of the object.

Definition at line 116 of file CRNSavable.h.

const String& crn::Savable::GetName ( ) const
inline

Returns the name of the object.

Definition at line 78 of file CRNSavable.h.

SObject Savable::GetUserData ( const String key)

Gets a user data by key.

Gets a user data by key

Parameters
[in]keyThe data key
Returns
the value or nullptr if key does not exist

Definition at line 78 of file CRNSavable.cpp.

const SObject Savable::GetUserData ( const String key) const

Gets a user data by key.

Gets a user data by key

Parameters
[in]keyThe data key
Returns
the value or nullptr if key does not exist

Definition at line 114 of file CRNSavable.cpp.

String Savable::GetUserDataKey ( const SObject &  value) const

Gets a user data key by value.

Gets a user data key by value

Parameters
[in]valueThe value to search
Returns
The key corresponding to the value, or "" if not found

Definition at line 95 of file CRNSavable.cpp.

bool Savable::IsUserData ( const String key) const

Tests if a user data key exists.

Tests if a user data key exists

Parameters
[in]keyThe data key
Returns
true if the key exists, false else

Definition at line 61 of file CRNSavable.cpp.

void Savable::Load ( const Path fname)

Loads the object from an XML file (Safe)

Loads the object from an XML file. Safe.

Exceptions
ExceptionIOcannot read file
ExceptionUninitializedempty file
ExceptionNotFoundinvalid file
ExceptionProtocolload unimplemented
Parameters
[in]fnamethe file name

Definition at line 188 of file CRNSavable.cpp.

Savable& crn::Savable::operator= ( const Savable )
delete

No assignment allowed.

Savable & Savable::operator= ( Savable &&  c)
default
void Savable::Save ( const Path fname)

Saves the object to an XML file (Safe)

Saves the object to an XML file. Safe.

Exceptions
ExceptionIOcannot write file
ExceptionProtocolsave unimplemented
Parameters
[in]fnamethe file name

Definition at line 208 of file CRNSavable.cpp.

void Savable::Save ( )

Saves the object to an already set XML file.

Saves the object to an already set XML file.

Exceptions
ExceptionUninitializedno filename
ExceptionIOcannot write file
ExceptionProtocolsave unimplemented

Definition at line 227 of file CRNSavable.cpp.

void Savable::serialize_internal_data ( xml::Element el) const

Dumps some internal data to an XML element.

Internal. Dumps some internal data to an XML element.

Parameters
[in]elthe element that contains the serialized object

Definition at line 316 of file CRNSavable.cpp.

void crn::Savable::setFilename ( const Path fname)
inlineprotected

Overwrites the filename.

Definition at line 119 of file CRNSavable.h.

void crn::Savable::setFilename ( Path &&  fname)
inlineprotectednoexcept

Overwrites the filename.

Definition at line 121 of file CRNSavable.h.

void crn::Savable::SetName ( const String s)
inline

Sets the name of the object.

Definition at line 80 of file CRNSavable.h.

void crn::Savable::SetName ( String &&  s)
inlinenoexcept

Sets the name of the object.

Definition at line 82 of file CRNSavable.h.

void Savable::SetUserData ( const String key,
SObject  value 
)

Adds or replaces a user data.

Adds an object to the user data

Parameters
[in]keythe (unique) key of the data
[in]valuethe data to add

Definition at line 145 of file CRNSavable.cpp.

Member Data Documentation

std::unique_ptr<std::mutex> crn::Savable::filelock
protected

Protection to avoid multiple access to the file at the same time

Definition at line 122 of file CRNSavable.h.


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