mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
TableFactory.hpp
Go to the documentation of this file.
1#pragma once
2
4
5
6namespace m {
7
8
11{
12 virtual ~TableFactory() = default;
13
15 virtual std::unique_ptr<Table> make(ThreadSafePooledString name) const = 0;
16};
17
18
21{
23 std::unique_ptr<Table> make(ThreadSafePooledString name) const override {
24 return std::make_unique<ConcreteTable>(std::move(name));
25 }
26};
27
28
31{
32 protected:
33 std::unique_ptr<TableFactory> table_factory_;
34
35 public:
36 TableFactoryDecorator(std::unique_ptr<TableFactory> table_factory) : table_factory_(std::move(table_factory)) { }
37
40 std::unique_ptr<Table> make(ThreadSafePooledString name) const override {
41 auto table = table_factory_->make(std::move(name));
42 return decorate(std::move(table));
43 }
44
45 protected:
46 virtual std::unique_ptr<Table> decorate(std::unique_ptr<Table> table) const = 0;
47};
48
49
50template<typename T>
51requires std::derived_from<T, Table>
53{
54 public:
55 ConcreteTableFactoryDecorator(std::unique_ptr<TableFactory> table_factory) : TableFactoryDecorator(std::move(table_factory)) { }
56
57 protected:
58 std::unique_ptr<Table> decorate(std::unique_ptr<Table> table) const override {
59 return std::make_unique<T>(std::move(table));
60 }
61};
62
63
64}
‍mutable namespace
Definition: Backend.hpp:10
ThreadSafeStringPool::proxy_type ThreadSafePooledString
Definition: Pool.hpp:464
STL namespace.
ConcreteTableFactoryDecorator(std::unique_ptr< TableFactory > table_factory)
std::unique_ptr< Table > decorate(std::unique_ptr< Table > table) const override
Basic implementation of TableFactory.
std::unique_ptr< Table > make(ThreadSafePooledString name) const override
Returns a Table with the given name.
Abstract Decorator class that concrete TableFactoryDecorator inherit from.
std::unique_ptr< Table > make(ThreadSafePooledString name) const override
Returns a Table with the given name.
TableFactoryDecorator(std::unique_ptr< TableFactory > table_factory)
std::unique_ptr< TableFactory > table_factory_
virtual std::unique_ptr< Table > decorate(std::unique_ptr< Table > table) const =0
The table factory creates Tables with all enabled decorators.
virtual std::unique_ptr< Table > make(ThreadSafePooledString name) const =0
Returns a Table with the given name.
virtual ~TableFactory()=default