tudocomp
– The TU Dortmund Compression Framework
pre_header/Registry.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <unordered_set>
5 #include <array>
6 
7 namespace tdc {
8 
9 class Env;
10 
12 struct AlreadySeenPair {
13  std::array<std::string, 2> pair;
14 };
15 
16 inline bool operator==(const AlreadySeenPair& lhs, const AlreadySeenPair& rhs) {
17  return lhs.pair[0] == rhs.pair[0] && lhs.pair[1] == rhs.pair[1];
18 }
20 
28 template<typename algorithm_t>
29 class Registry {
30  typedef std::function<std::unique_ptr<algorithm_t>(Env&&)> constructor_t;
31 
32  struct RegistryData {
33  eval::AlgorithmTypes m_algorithms;
34  std::map<pattern::Algorithm, constructor_t> m_registered;
35  };
36 
37  std::shared_ptr<RegistryData> m_data;
38  std::string m_root_type;
39 
41  friend class AlgorithmTypeBuilder;
42  friend class GlobalRegistry;
44 
45 public:
46  inline Registry(const std::string& root_type = "any"):
47  m_data(std::make_shared<RegistryData>()), m_root_type(root_type) {}
48 
57  template<typename T>
58  void register_algorithm();
59 
60  inline eval::AlgorithmTypes& algorithm_map();
61  inline const eval::AlgorithmTypes& algorithm_map() const;
62 
64  // Create the list of all possible static-argument-type combinations
65  inline std::vector<pattern::Algorithm> all_algorithms_with_static(View type) const;
66  inline std::vector<pattern::Algorithm> all_algorithms_with_static_internal(std::vector<AlreadySeenPair>& already_seen, View type) const;
67  inline std::vector<pattern::Algorithm> check_for_undefined_algorithms();
68  inline std::unique_ptr<algorithm_t> select_algorithm(const AlgorithmValue& algo) const;
69  inline AlgorithmValue parse_algorithm_id(string_ref text) const;
70  inline std::unique_ptr<algorithm_t> select(const std::string& text) const;
71  inline static Registry<algorithm_t> with_all_from(std::function<void(Registry<algorithm_t>&)> f, const std::string& root_type);
72  inline std::string generate_doc_string(const std::string& title) const;
74 };
75 
76 }
77 namespace std {
78  template<>
79  struct hash<typename tdc::AlreadySeenPair>
80  {
81  size_t operator()(const tdc::AlreadySeenPair& x) const {
82  return std::hash<tdc::ConstGenericView<std::string>>()(
84  x.pair.data(),
85  x.pair.size()
86  });
87  }
88  };
89 }
90 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
A const view into a slice of memory.
bool operator==(const ConstGenericView< uliteral_t > &lhs, const ConstGenericView< uliteral_t > &rhs)
size_t operator()(const tdc::AlreadySeenPair &x) const
A registry for algorithms to be made available in the driver application.
uint64_t m_data
Definition: uint_t.hpp:30
const value_type * data() const noexcept
The backing memory location.
Automatically select compress mode, internal use in TextDS only.
Local environment for a compression/encoding/decompression call.
Registry(const std::string &root_type="any")