Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F64606122
BackendFactory.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 28, 02:56
Size
2 KB
Mime Type
text/x-c
Expires
Thu, May 30, 02:56 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17931749
Attached To
R6622 liboncilla
BackendFactory.h
View Options
/**
* \file BackendFactory.h
*
* \date Jun 21, 2012
* \author Alexandre Tuleu
*/
#ifndef LIBONCILLA_BACKENDFACTORY_H_
#define LIBONCILLA_BACKENDFACTORY_H_
#include <map>
#include <tr1/memory>
#include <iostream>
#include <string>
#include <set>
extern "C" {
typedef void (*liboncilla_backend_entry_fct)();
}
namespace rci{
namespace oncilla{
class OncillaSynchronizer;
typedef std::tr1::shared_ptr<OncillaSynchronizer> OncillaSynchronizerPtr;
class BackendFactory {
public :
/**
* define the priority of the backend
*/
enum Priority{
HARDWARE = 0,
SIMULATION = 1,
USER_DEFINED_PRIORITY = 2
};
/**
* Pointer to a function that will be the entry of the Backend.
*/
typedef OncillaSynchronizerPtr (*EntryPtr)();
static BackendFactory & Instance();
void AddAdditionalBackend(const std::string & name);
/**
* Register a new backend.
* \param p the Priority of the backend
* \param entry the EntryPtr of the backend
* \warning : if a backend with the same priority is already here, the call
* will be silently discarded.
*/
void RegisterBackend(Priority p, EntryPtr entry);
/**
* \return the EntryPtr of the highest priority backend or 0 if none was
* registered with RegisterBackend().
*/
EntryPtr HighestPriorityBackend();
private:
typedef std::map<Priority,EntryPtr> EntryByPriority;
typedef std::set<std::string> SetOfBackendName;
typedef std::map<std::string,void*> ListOfLoadedBackend;
void LoadExternalBackend();
BackendFactory();
virtual ~BackendFactory();
EntryByPriority d_entries;
SetOfBackendName d_unloaded;
ListOfLoadedBackend d_loaded;
};
template <typename OncillaSynchronizerSubClass , BackendFactory::Priority P>
class BackendRegistrator {
public :
BackendRegistrator();
void PrintAlive();
};
template <class OncillaSynchronizerSubClass , BackendFactory::Priority P>
inline
BackendRegistrator<OncillaSynchronizerSubClass , P>::BackendRegistrator(){
BackendFactory::Instance().RegisterBackend(P,
&(OncillaSynchronizerSubClass::Create));
}
template <class OncillaSynchronizerSubClass, BackendFactory::Priority P>
inline void BackendRegistrator<OncillaSynchronizerSubClass,P>::PrintAlive(){
std::cout << "I am alive!" << std::endl;
}
}
}
#endif // LIBONCILLA_BACKENDFACTORY_H_
Event Timeline
Log In to Comment