VISH
0.2
|
Database for routines that may create objects of type X. More...
#include </home/werner/origo/vish/memcore/Loader.hpp>
Database for routines that may create objects of type X.
The LoaderRegistry class allows to actually create objects of type X from a certain input source. The input source is specified through the LoaderParameters class, which may carry arbitrary additional interfaces.
bool success; RefPtr<LoaderParameters> LP = new LoaderParameters("FileName.txt"); LP->addInterface( new ProgressDisplay() ); RefPtr<X> object = LoaderRegistry<X>::load(success, LP);
Implementation of a new Loader: Consider a type Bundle to be created from some input source. We introduce an artificial type, here called HDF5
struct HDF5 {};
with no other purpose as to provide a unique typeid in C++. We implement a loader by deriving from the Loader<Bundle> base class:
struct myHDF5Loader : Loader<Bundle> { override RefPtr<Bundle> load(const RefPtr<LoaderParameters>&, const RefPtr<Bundle>&Xptr = NullPtr() ) {} };
The name of this class is not of relevance. We now add an instance of this loader to the LoaderRegistry for the Bundle type:
MemCore::LoaderRegistry<Bundle>::append( typeid(HDF5), new myHDF5Loader() );
Now we have the means to iterate over all loaders which have been registered for the type Bundle. This iteration is implemented in function LoaderRegistryBase::domain_load() as a static function, or easier as LoaderRegistry<Bundle>::load();