-
Jan Trávníček authoredJan Trávníček authored
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
XmlComposerRegistry.hpp 2.25 KiB
/*
* XmlComposerRegistry.hpp
*
* Created on: 28. 8. 2017
* Author: Jan Travnicek
*/
#ifndef _XML_COMPOSER_REGISTRY_HPP_
#define _XML_COMPOSER_REGISTRY_HPP_
#include <alib/memory>
#include <alib/string>
#include <alib/set>
#include <alib/map>
#include <alib/typeinfo>
#include <exception/CommonException.h>
#include <abstraction/OperationAbstraction.hpp>
namespace abstraction {
class XmlComposerRegistry {
class Entry {
public:
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0;
virtual ~Entry ( ) {
}
};
template < class Param >
class EntryImpl : public Entry {
public:
EntryImpl ( ) {
}
virtual ~EntryImpl ( ) {
}
virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
};
static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( );
public:
static void unregisterXmlComposer ( std::string param ) {
getEntries ( ).erase ( param );
}
template < class ParamType >
static void unregisterXmlComposer ( ) {
std::string param = ext::to_string < ParamType > ( );
unregisterXmlComposer ( std::move ( param ) );
}
template < class ParamType >
static void registerXmlComposer ( std::string param ) {
if ( ! getEntries ( ).insert ( std::make_pair ( param, std::unique_ptr < Entry > ( new EntryImpl < ParamType > ( ) ) ) ).second )
throw std::invalid_argument ( "Entry " + param + " already registered." );
}
template < class ParamType >
static void registerXmlComposer ( ) {
std::string param = ext::to_string < ParamType > ( );
registerXmlComposer < ParamType > ( std::move ( param ) );
}
static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & param );
static ext::set < std::string > listGroup ( const std::string & group );
static ext::set < std::string > list ( );
};
} /* namespace abstraction */
#include <abstraction/XmlComposerAbstraction.hpp>
namespace abstraction {
template < class Param >
std::shared_ptr < abstraction::OperationAbstraction > XmlComposerRegistry::EntryImpl < Param >::getAbstraction ( ) const {
return std::make_shared < abstraction::XmlComposerAbstraction < const Param & > > ( );
}
} /* namespace abstraction */
#endif /* _XML_COMPOSER_REGISTRY_HPP_ */