Newer
Older
/*
* ContainerRegistry.hpp
*
* Created on: 11. 7. 2017
* Author: Jan Travnicek
*/
#ifndef _CONTAINER_REGISTRY_HPP_
#define _CONTAINER_REGISTRY_HPP_
#include <alib/functional>
#include <alib/memory>
#include <alib/vector>
#include <alib/string>
#include <alib/set>
#include <alib/map>
#include <abstraction/OperationAbstraction.hpp>
namespace abstraction {
class ContainerRegistry {
class Entry {
public:
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0;
};
template < class Params >
class SetEntryImpl : public Entry {
public:
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
};
static ext::map < std::string, ext::vector < ext::pair < std::string, std::shared_ptr < Entry > > > > & getEntries ( ) {
static ext::map < std::string, ext::vector < ext::pair < std::string, std::shared_ptr < Entry > > > > containerGroups;
return containerGroups;
};
public:
template < class ParamTypes >
static void registerSet ( std::string param ) {
std::string container = "Set";
auto & group = getEntries ( ) [ container ];
for ( const ext::pair < std::string, std::shared_ptr < Entry > > & entry : group )
if ( entry.first == param )
throw std::invalid_argument ( "Callback for " + container + " already registered." );
std::shared_ptr < Entry > entryValue = std::make_shared < SetEntryImpl < ParamTypes > > ( );
group.push_back ( ext::make_pair ( param, entryValue ) );
}
template < class ParamTypes >
static void registerSet ( ) {
std::string param = ext::to_string < typename std::decay < ParamTypes >::type > ( );
registerSet < ParamTypes > ( param );
static bool hasAbstraction ( const std::string & container );
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & container, const std::string & param );
static ext::set < std::string > listOverloads ( const std::string & algorithm );
static ext::set < std::string > list ( );
};
} /* namespace abstraction */
#include <abstraction/SetAbstraction.hpp>
namespace abstraction {
template < class Param >
std::shared_ptr < abstraction::OperationAbstraction > ContainerRegistry::SetEntryImpl < Param >::getAbstraction ( ) const {
return std::make_shared < abstraction::SetAbstraction < Param > > ( );
}
} /* namespace abstraction */
#endif /* _CONTAINER_REGISTRY_HPP_ */