| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Core/Types.h> |
| 4 | #include <Disks/IDisk.h> |
| 5 | |
| 6 | #include <functional> |
| 7 | #include <unordered_map> |
| 8 | #include <boost/noncopyable.hpp> |
| 9 | #include <Poco/Util/AbstractConfiguration.h> |
| 10 | |
| 11 | |
| 12 | namespace DB |
| 13 | { |
| 14 | class Context; |
| 15 | |
| 16 | /** |
| 17 | * Disk factory. Responsible for creating new disk objects. |
| 18 | */ |
| 19 | class DiskFactory final : private boost::noncopyable |
| 20 | { |
| 21 | public: |
| 22 | using Creator = std::function<DiskPtr( |
| 23 | const String & name, |
| 24 | const Poco::Util::AbstractConfiguration & config, |
| 25 | const String & config_prefix, |
| 26 | const Context & context)>; |
| 27 | |
| 28 | static DiskFactory & instance(); |
| 29 | |
| 30 | void registerDiskType(const String & disk_type, Creator creator); |
| 31 | |
| 32 | DiskPtr create( |
| 33 | const String & name, |
| 34 | const Poco::Util::AbstractConfiguration & config, |
| 35 | const String & config_prefix, |
| 36 | const Context & context) const; |
| 37 | |
| 38 | private: |
| 39 | using DiskTypeRegistry = std::unordered_map<String, Creator>; |
| 40 | DiskTypeRegistry registry; |
| 41 | }; |
| 42 | |
| 43 | } |
| 44 |