-
Jan Trávníček authoredJan Trávníček authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
RawWriterRegistry.hpp 1.77 KiB
/*
* RawWriterRegistry.hpp
*
* Created on: 28. 8. 2017
* Author: Jan Travnicek
*/
#ifndef _RAW_WRITER_REGISTRY_HPP_
#define _RAW_WRITER_REGISTRY_HPP_
#include <alib/memory>
#include <alib/string>
#include <alib/set>
#include <alib/map>
#include <exception/CommonException.h>
#include <abstraction/OperationAbstraction.hpp>
namespace abstraction {
class RawWriterRegistry {
class Entry {
public:
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0;
};
template < class Param >
class EntryImpl : public Entry {
public:
EntryImpl ( ) {
}
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
};
static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ) {
static ext::map < std::string, std::unique_ptr < Entry > > writers;
return writers;
}
public:
template < class ParamType >
static void registerRawWriter ( std::string param ) {
getEntries ( ).insert ( std::make_pair ( std::move ( param ), std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) );
}
template < class ParamType >
static void registerRawWriter ( ) {
std::string param = ext::to_string < ParamType > ( );
registerRawWriter < ParamType > ( std::move ( param ) );
}
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param );
};
} /* namespace abstraction */
#include <abstraction/RawWriterAbstraction.hpp>
namespace abstraction {
template < class Param >
std::shared_ptr < abstraction::OperationAbstraction > RawWriterRegistry::EntryImpl < Param >::getAbstraction ( ) const {
return std::make_shared < abstraction::RawWriterAbstraction < const Param & > > ( );
}
} /* namespace abstraction */
#endif /* _RAW_WRITER_REGISTRY_HPP_ */