The Vish Visualization Shell 0.3
Vish
Public Member Functions | List of all members
MemCore::SaveInterfaceCreator< X > Class Template Referenceabstract

Abstract base class for objects that may equip a certain class object X with an interface to write this structure into a file. More...

#include <elementary/memcore/Persistencer.hpp>

Inheritance diagram for MemCore::SaveInterfaceCreator< X >:
MemCore::SaveInterfaceCreatorBase MemCore::ReferenceBase< SaveInterfaceCreatorBase >

Public Member Functions

 SaveInterfaceCreator (const string &Extension, const string &Description)
 Construct from preferred file name extension and a human-readable description of this file format.
 
- Public Member Functions inherited from MemCore::SaveInterfaceCreatorBase
 SaveInterfaceCreatorBase (const string &Extension, const string &Description)
 Constructor.
 
 ~SaveInterfaceCreatorBase ()
 Destructor.
 
- Public Member Functions inherited from MemCore::ReferenceBase< SaveInterfaceCreatorBase >
auto getObjectCountID () const noexcept
 Get a unique ID for this object in the given domain.
 
bool isIdentical (const WeakPtr< SaveInterfaceCreatorBase, SaveInterfaceCreatorBase > &PossibleSelf) const noexcept
 Check if this object is identical to the one used by the given pointer.
 
void mkAutoDestructive ()
 Marks this object as being automatically destructed, e.g.
 
refcount_t refcount () const noexcept
 The strong reference count.
 
 ReferenceBase (SaveInterfaceCreatorBase *that) noexcept
 Constructor, initializes reference counter to zero.
 
const auto & self () const
 Return weak pointer to the object self.
 
refcount_t wrefcount () const noexcept
 The weak reference count.
 

Additional Inherited Members

- Public Types inherited from MemCore::ReferenceBase< SaveInterfaceCreatorBase >
using reference_domain_t = SaveInterfaceCreatorBase
 The type of the base class.
 
using SelfPtr_t = WeakPtr< SaveInterfaceCreatorBase, SaveInterfaceCreatorBase >
 Type for a pointer to this object itself.
 
- Public Attributes inherited from MemCore::SaveInterfaceCreatorBase
string description
 Optional verbose description.
 
string extension
 Preferred file name extension (maybe an array in the future?)
 
- Protected Member Functions inherited from MemCore::ReferenceBase< SaveInterfaceCreatorBase >
virtual void extremeUnction ()
 A virtual function that will be called just before the object is destroyed.
 
ReferenceBaseoperator= (const ReferenceBase &R)
 Protected assignment operator (should not be called).
 
void suicide ()
 Delete this.
 
virtual ~ReferenceBase ()
 Virtual destructor.
 

Detailed Description

template<class X>
class MemCore::SaveInterfaceCreator< X >

Abstract base class for objects that may equip a certain class object X with an interface to write this structure into a file.

The details how to do this are completely left open and deferred to the respective implementation.

A common practice is to add an Interface to the object X for a certain file format type. This requires the class X to be derived from an Intercube. Such a file saving interface can be defined like that:

struct  XML {};

class   XMLSaver_for_X : public Interface<XML>
{
public:
        void save(const char*filename);
};

This class will become part of all created objects. In addition we require an object that will be part of the saveregistry database. This one is in charge to add new interface objects to newly created objects of type X:

class   XMLSaver_for_X_Creator : public SaveInterfaceCreator<Bundle>
{
        bool addSaveInterface(X*x)
        {
                x->addInterface( new XMLSaver_for_X() ) override;
                return false;
        }
};

At last, the database object needs to be added to the save registry:

SaveRegistry<X>::getCreator( typeid(XML) ) = new XMLSaver_for_X_Creator ();

Now, when saving objects of type X one can just ask for a specific interface:

  X myObject;
  InterfacePtr<XMLSaver_for_X> XSaver = *myObject;
        if (XSaver)
                XSaver->save("-");