Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
StringReaderRegistry.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <ext/memory>
9#include <ext/algorithm>
10#include <ext/typeinfo>
11
12#include <alib/string>
13#include <alib/map>
14#include <alib/list>
15
17
18#include <core/stringApi.hpp>
19
20namespace abstraction {
21
23public:
24 class Entry {
25 public:
26 virtual std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const = 0;
27
28 virtual ~Entry ( ) = default;
29 };
30
31private:
32 template < class Return >
33 class EntryImpl : public Entry {
34 public:
35 EntryImpl ( ) = default;
36
37 std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( ) const override;
38 };
39
40 static ext::map < std::string, ext::list < std::pair < std::function < bool ( ext::istream & ) >, std::unique_ptr < Entry > > > > & getEntries ( );
41
42public:
43 static void unregisterStringReader ( const std::string & group, ext::list < std::pair < std::function < bool ( ext::istream & ) >, std::unique_ptr < Entry > > >::const_iterator iter );
44
45 template < class Group >
46 static void unregisterStringReader ( ext::list < std::pair < std::function < bool ( ext::istream & ) >, std::unique_ptr < Entry > > >::const_iterator iter ) {
47 std::string group = ext::to_string < Group > ( );
48 unregisterStringReader ( group, iter );
49 }
50
51 static ext::list < std::pair < std::function < bool ( ext::istream & ) >, std::unique_ptr < Entry > > >::const_iterator registerStringReader ( std::string group, std::function < bool ( ext::istream & ) > first, std::unique_ptr < Entry > entry );
52
53 template < class Group, class ReturnType >
54 static ext::list < std::pair < std::function < bool ( ext::istream & ) >, std::unique_ptr < Entry > > >::const_iterator registerStringReader ( ) {
55 return registerStringReader ( ext::to_string < Group > ( ), core::stringApi < ReturnType >::first, std::unique_ptr < Entry > ( new EntryImpl < ReturnType > ( ) ) );
56 }
57
58 static std::shared_ptr < abstraction::OperationAbstraction > getAbstraction ( const std::string & group, const std::string & str );
59};
60
61} /* namespace abstraction */
62
64
65namespace abstraction {
66
67template < class Return >
68std::shared_ptr < abstraction::OperationAbstraction > StringReaderRegistry::EntryImpl < Return >::getAbstraction ( ) const {
69 return std::make_shared < abstraction::StringReaderAbstraction < Return > > ( );
70}
71
72} /* namespace abstraction */
73
Definition: StringReaderRegistry.hpp:24
virtual std::shared_ptr< abstraction::OperationAbstraction > getAbstraction() const =0
Definition: StringReaderRegistry.hpp:22
static void unregisterStringReader(const std::string &group, ext::list< std::pair< std::function< bool(ext::istream &) >, std::unique_ptr< Entry > > >::const_iterator iter)
static std::shared_ptr< abstraction::OperationAbstraction > getAbstraction(const std::string &group, const std::string &str)
Definition: StringReaderRegistry.cpp:31
static void unregisterStringReader(ext::list< std::pair< std::function< bool(ext::istream &) >, std::unique_ptr< Entry > > >::const_iterator iter)
Definition: StringReaderRegistry.hpp:46
static ext::list< std::pair< std::function< bool(ext::istream &)>, std::unique_ptr< Entry > > >::const_iterator registerStringReader()
Definition: StringReaderRegistry.hpp:54
Definition: istream.h:32
Class extending the list class from the standard library. Original reason is to allow printing of the...
Definition: list.hpp:44
Class extending the map class from the standard library. Original reason is to allow printing of the ...
Definition: map.hpp:48
Definition: AlgorithmAbstraction.hpp:11
Definition: stringApi.hpp:26