VISH  0.2
Public Member Functions
MemCore::SaveInterfaceCreator Class Reference

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 </home/werner/origo/vish/memcore/Persistencer.hpp>

List of all members.

Public Member Functions


Detailed Description

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>
{
	override bool addSaveInterface(X*x)
	{
		x->addInterface( new XMLSaver_for_X() );
		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("-");

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