diff --git a/alib2cli/src/registration/InputFileTypeRegistration.cpp b/alib2cli/src/registration/InputFileTypeRegistration.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6088d0df02a5759658ad65ff33816dfcd5772596 --- /dev/null +++ b/alib2cli/src/registration/InputFileTypeRegistration.cpp @@ -0,0 +1,11 @@ +#include "InputFileTypeRegistration.hpp" + +namespace { + + std::shared_ptr < abstraction::OperationAbstraction > dummy ( const std::string & /* type */, const ext::vector < std::string > & /* templateParams */ ) { + return nullptr; + } + +auto xmlInputFileHandler = registration::InputFileRegister ( "xml", dummy ); + +} diff --git a/alib2cli/src/registration/InputFileTypeRegistration.hpp b/alib2cli/src/registration/InputFileTypeRegistration.hpp new file mode 100644 index 0000000000000000000000000000000000000000..28cb35ef38523538813aa8fc66ae08eb2ca06ce6 --- /dev/null +++ b/alib2cli/src/registration/InputFileTypeRegistration.hpp @@ -0,0 +1,17 @@ +#ifndef _INPUT_FILE_REGISTER_HPP_ +#define _INPUT_FILE_REGISTER_HPP_ + +#include <registry/InputFileRegistry.hpp> + +namespace registration { + +class InputFileRegister { +public: + InputFileRegister ( const std::string & fileType, std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( const std::string & type, const ext::vector < std::string > & templateParams ) ) { + abstraction::InputFileRegistry::registerInputFileHandler ( fileType, callback ); + } +}; + +} /* namespace registration */ + +#endif // _INPUT_FILE_REGISTER_HPP_ diff --git a/alib2cli/src/registration/OutputFileTypeRegistration.cpp b/alib2cli/src/registration/OutputFileTypeRegistration.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2f1cbca7020b5d15dd44031fc40db9f3d8f5b9b3 --- /dev/null +++ b/alib2cli/src/registration/OutputFileTypeRegistration.cpp @@ -0,0 +1,11 @@ +#include "OutputFileTypeRegistration.hpp" + +namespace { + + std::shared_ptr < abstraction::OperationAbstraction > dummy ( ) { + return nullptr; + } + +auto xmlOutputFileHandler = registration::OutputFileRegister ( "xml", dummy ); + +} diff --git a/alib2cli/src/registration/OutputFileTypeRegistration.hpp b/alib2cli/src/registration/OutputFileTypeRegistration.hpp new file mode 100644 index 0000000000000000000000000000000000000000..223310fbd90e4b37ea871359033512b7c3b947f7 --- /dev/null +++ b/alib2cli/src/registration/OutputFileTypeRegistration.hpp @@ -0,0 +1,17 @@ +#ifndef _INPUT_FILE_REGISTER_HPP_ +#define _INPUT_FILE_REGISTER_HPP_ + +#include <registry/OutputFileRegistry.hpp> + +namespace registration { + +class OutputFileRegister { +public: + OutputFileRegister ( const std::string & fileType, std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( ) ) { + abstraction::OutputFileRegistry::registerOutputFileHandler ( fileType, callback ); + } +}; + +} /* namespace registration */ + +#endif // _INPUT_FILE_REGISTER_HPP_ diff --git a/alib2cli/src/registry/InputFileRegistry.cpp b/alib2cli/src/registry/InputFileRegistry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e06f0be975050bd8488d9f4818d7977174c5b672 --- /dev/null +++ b/alib2cli/src/registry/InputFileRegistry.cpp @@ -0,0 +1,25 @@ +/* + * InputFileRegistry.cpp + * + * Created on: 28. 8. 2017 + * Author: Jan Travnicek + */ + +#include <registry/InputFileRegistry.hpp> +#include <abstraction/XmlComposerAbstraction.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > InputFileRegistry::getAbstraction ( const std::string & fileType, const std::string & type, const ext::vector < std::string > & templateParams ) { + auto res = getEntries ( ).find ( fileType ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + fileType + " not available." ); + + return res->second->getAbstraction ( type, templateParams ); +} + +std::shared_ptr < abstraction::OperationAbstraction > InputFileRegistry::EntryImpl::getAbstraction ( const std::string & type, const ext::vector < std::string > & templateParams ) const { + return m_callback ( type, templateParams ); +} + +} /* namespace abstraction */ diff --git a/alib2cli/src/registry/InputFileRegistry.hpp b/alib2cli/src/registry/InputFileRegistry.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6ecf007becb6c2ff3a33c00c8b4f819a8f6d5203 --- /dev/null +++ b/alib2cli/src/registry/InputFileRegistry.hpp @@ -0,0 +1,57 @@ +/* + * InputFileRegistry.hpp + * + * Created on: 25. 5. 2018 + * Author: Jan Travnicek + */ + +#ifndef _INPUT_FILE_REGISTRY_HPP_ +#define _INPUT_FILE_REGISTRY_HPP_ + +#include <alib/memory> +#include <alib/string> +#include <alib/map> +#include <alib/functional> + +#include <exception/CommonException.h> +#include <abstraction/OperationAbstraction.hpp> + +namespace abstraction { + +class InputFileRegistry { + class Entry { + public: + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & type, const ext::vector < std::string > & templateParams ) const = 0; + + virtual ~Entry ( ) { + } + }; + + class EntryImpl : public Entry { + std::function < std::shared_ptr < abstraction::OperationAbstraction > ( const std::string & type, const ext::vector < std::string > & templateParams ) > m_callback; + public: + EntryImpl ( std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( const std::string & type, const ext::vector < std::string > & templateParams ) ) : m_callback ( callback ) { + } + + virtual ~EntryImpl ( ) { + } + + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & type, const ext::vector < std::string > & templateParams ) const override; + }; + + static ext::map < std::string, std::unique_ptr < Entry > > & getEntries ( ) { + static ext::map < std::string, std::unique_ptr < Entry > > inputFileHandlers; + return inputFileHandlers; + } + +public: + static void registerInputFileHandler ( const std::string & fileType, std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( const std::string & type, const ext::vector < std::string > & templateParams ) ) { + getEntries ( ).insert ( std::make_pair ( fileType, std::unique_ptr < Entry > ( new EntryImpl ( callback ) ) ) ); + } + + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & fileType, const std::string & type, const ext::vector < std::string > & templateParams ); +}; + +} /* namespace abstraction */ + +#endif /* _INPUT_FILE_REGISTRY_HPP_ */ diff --git a/alib2cli/src/registry/OutputFileRegistry.cpp b/alib2cli/src/registry/OutputFileRegistry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3aa32f1ddb994947fc09546d7a1a8851a8acb465 --- /dev/null +++ b/alib2cli/src/registry/OutputFileRegistry.cpp @@ -0,0 +1,25 @@ +/* + * OutputFileRegistry.cpp + * + * Created on: 28. 8. 2017 + * Author: Jan Travnicek + */ + +#include <registry/OutputFileRegistry.hpp> +#include <abstraction/XmlComposerAbstraction.hpp> + +namespace abstraction { + +std::shared_ptr < abstraction::OperationAbstraction > OutputFileRegistry::getAbstraction ( const std::string & fileType ) { + auto res = getEntries ( ).find ( fileType ); + if ( res == getEntries ( ).end ( ) ) + throw exception::CommonException ( "Entry " + fileType + " not available." ); + + return res->second->getAbstraction ( ); +} + +std::shared_ptr < abstraction::OperationAbstraction > OutputFileRegistry::EntryImpl::getAbstraction ( ) const { + return m_callback ( ); +} + +} /* namespace abstraction */ diff --git a/alib2cli/src/registry/OutputFileRegistry.hpp b/alib2cli/src/registry/OutputFileRegistry.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4d9dd73b52d801f33c9447bc170faca49ca48715 --- /dev/null +++ b/alib2cli/src/registry/OutputFileRegistry.hpp @@ -0,0 +1,57 @@ +/* + * OutputFileRegistry.hpp + * + * Created on: 25. 5. 2018 + * Author: Jan Travnicek + */ + +#ifndef _OUTPUT_FILE_REGISTRY_HPP_ +#define _OUTPUT_FILE_REGISTRY_HPP_ + +#include <alib/memory> +#include <alib/string> +#include <alib/map> +#include <alib/functional> + +#include <exception/CommonException.h> +#include <abstraction/OperationAbstraction.hpp> + +namespace abstraction { + +class OutputFileRegistry { + class Entry { + public: + virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0; + + virtual ~Entry ( ) { + } + }; + + class EntryImpl : public Entry { + std::function < std::shared_ptr < abstraction::OperationAbstraction > ( ) > m_callback; + public: + EntryImpl ( std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( ) ) : m_callback ( callback ) { + } + + virtual ~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 > > inputFileHandlers; + return inputFileHandlers; + } + +public: + static void registerOutputFileHandler ( const std::string & fileType, std::shared_ptr < abstraction::OperationAbstraction > ( * callback ) ( ) ) { + getEntries ( ).insert ( std::make_pair ( fileType, std::unique_ptr < Entry > ( new EntryImpl ( callback ) ) ) ); + } + + static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & fileType ); +}; + +} /* namespace abstraction */ + +#endif /* _OUTPUT_FILE_REGISTRY_HPP_ */