SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Schemas.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #ifndef swcdb_db_Columns_Schemas_h
8 #define swcdb_db_Columns_Schemas_h
9 
10 
11 #include "swcdb/core/MutexSptd.h"
12 #include "swcdb/core/Comparators.h"
14 
15 
16 namespace SWC { namespace DB {
17 
18 class Schemas : private std::unordered_map<cid_t, Schema::Ptr> {
19  using Map = std::unordered_map<cid_t, Schema::Ptr>;
20 
21  public:
22 
23 
24  struct Pattern : public std::string {
25 
27 
29  Pattern() noexcept : comp(Condition::NONE) { }
30 
32  Pattern(Condition::Comp a_comp, std::string&& value) noexcept
33  : std::string(std::move(value)), comp(a_comp) {
34  }
35 
37  Pattern(Condition::Comp a_comp, const std::string& value)
38  : std::string(value), comp(a_comp) {
39  }
40 
42  Pattern(Pattern&& other) noexcept
43  : std::string(std::move(other)), comp(other.comp) {
44  }
45 
47  Pattern(const Pattern& other)
48  : std::string(other), comp(other.comp) {
49  }
50 
51  ~Pattern() noexcept { }
52 
54  Pattern& operator=(Pattern&& other) noexcept {
55  std::string::operator=(std::move(other));
56  comp = other.comp;
57  return *this;
58  }
59 
61  Pattern& operator=(const Pattern& other) {
62  std::string::operator=(other);
63  comp = other.comp;
64  return *this;
65  }
66 
68  void set(Condition::Comp _comp, std::string&& value) {
69  std::string::operator=(std::move(value));
70  comp = _comp;
71  }
72 
74  void set(Condition::Comp _comp, const std::string& value) {
75  std::string::operator=(value);
76  comp = _comp;
77  }
78 
79  void print(std::ostream& out) const {
80  out << Condition::to_string(comp) << '"' << *this << '"';
81  }
82 
83  };
85 
86  struct TagsPattern : public NamePatterns {
88 
90  TagsPattern() noexcept : comp(Condition::NONE) { }
91 
92  TagsPattern(TagsPattern&&) noexcept = default;
93  TagsPattern(const TagsPattern&) = default;
94  TagsPattern& operator=(TagsPattern&&) noexcept = default;
95  TagsPattern& operator=(const TagsPattern&) = delete;
96 
97  ~TagsPattern() noexcept { }
98  };
99 
104  SelectorPatterns() noexcept : names(), tags() {}
105  SelectorPatterns(SelectorPatterns&&) noexcept = default;
107  SelectorPatterns& operator=(SelectorPatterns&&) noexcept = default;
108  SelectorPatterns& operator=(const SelectorPatterns&) = delete;
109  ~SelectorPatterns() noexcept { }
110  };
111 
112 
113 
115  Schemas() noexcept: m_mutex() { }
116 
118  ~Schemas() noexcept { }
119 
120  uint64_t size();
121 
122  void add(int& err, const Schema::Ptr& schema);
123 
124  void remove(cid_t cid);
125 
126  void replace(const Schema::Ptr& schema);
127 
128  Schema::Ptr get(cid_t cid) noexcept;
129 
130  Schema::Ptr get(const std::string& name) noexcept;
131 
132  void all(SchemasVec& entries);
133 
134  void matching(const SelectorPatterns& patterns, SchemasVec& entries,
135  bool no_sys=true);
136 
137  void reset();
138 
139  protected:
140 
141  void _add(int& err, const Schema::Ptr& schema);
142 
143  void _remove(cid_t cid);
144 
145  void _replace(const Schema::Ptr& schema);
146 
147  Schema::Ptr _get(cid_t cid) const noexcept;
148 
149  Schema::Ptr _get(const std::string& name) const noexcept;
150 
152 };
153 
154 
155 
156 }}
157 
158 
159 #ifdef SWC_IMPL_SOURCE
161 #endif
162 
163 #endif // swcdb_db_Columns_Schemas_h
SWC::DB::Schemas::add
void add(int &err, const Schema::Ptr &schema)
Definition: Schemas.cc:19
SWC::DB::Schemas::TagsPattern::comp
Condition::Comp comp
Definition: Schemas.h:87
Schema.h
SWC::DB::Schemas::Pattern::Pattern
SWC_CAN_INLINE Pattern(Condition::Comp a_comp, std::string &&value) noexcept
Definition: Schemas.h:32
SWC::DB::Schemas::Pattern::operator=
SWC_CAN_INLINE Pattern & operator=(Pattern &&other) noexcept
Definition: Schemas.h:54
SWC::DB::Schema::Ptr
std::shared_ptr< Schema > Ptr
Definition: Schema.h:185
Schemas.cc
SWC::DB::Schemas::Pattern::~Pattern
~Pattern() noexcept
Definition: Schemas.h:51
SWC::DB::Schemas::Pattern::Pattern
SWC_CAN_INLINE Pattern(const Pattern &other)
Definition: Schemas.h:47
SWC::DB::Schemas::TagsPattern::TagsPattern
TagsPattern(TagsPattern &&) noexcept=default
SWC::DB::Schemas::SelectorPatterns::SelectorPatterns
SWC_CAN_INLINE SelectorPatterns() noexcept
Definition: Schemas.h:104
SWC::DB::Schemas::NamePatterns
Core::Vector< Pattern > NamePatterns
Definition: Schemas.h:84
SWC::DB::Schemas::_add
void _add(int &err, const Schema::Ptr &schema)
Definition: Schemas.cc:24
SWC::DB::Schemas::~Schemas
SWC_CAN_INLINE ~Schemas() noexcept
Definition: Schemas.h:118
SWC::DB::Schemas::SelectorPatterns
Definition: Schemas.h:100
SWC::DB::Schemas::m_mutex
Core::MutexSptd m_mutex
Definition: Schemas.h:151
SWC::DB::Schemas::SelectorPatterns::names
NamePatterns names
Definition: Schemas.h:101
SWC::DB::Schemas::Pattern::Pattern
SWC_CAN_INLINE Pattern(Condition::Comp a_comp, const std::string &value)
Definition: Schemas.h:37
SWC::DB::Schemas::size
uint64_t size()
Definition: Schemas.cc:14
SWC::DB::Schemas::TagsPattern::TagsPattern
SWC_CAN_INLINE TagsPattern() noexcept
Definition: Schemas.h:90
SWC::Condition::Comp
Comp
Definition: Comparators.h:27
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::DB::Schemas::get
Schema::Ptr get(cid_t cid) noexcept
Definition: Schemas.cc:56
SWC::DB::Schemas::Pattern::print
void print(std::ostream &out) const
Definition: Schemas.h:79
SWC::DB::Schemas::all
void all(SchemasVec &entries)
Definition: Schemas.cc:79
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Schemas::remove
void remove(cid_t cid)
Definition: Schemas.cc:34
SWC::DB::Schemas::replace
void replace(const Schema::Ptr &schema)
Definition: Schemas.cc:45
SWC::DB::Schemas::TagsPattern
Definition: Schemas.h:86
SWC::DB::Schemas::_remove
void _remove(cid_t cid)
Definition: Schemas.cc:39
Comparators.h
SWC::DB::Schemas
Definition: Schemas.h:18
SWC::Condition::NONE
@ NONE
Definition: Comparators.h:28
SWC::DB::Schemas::reset
void reset()
Definition: Schemas.cc:305
SWC::cid_t
uint64_t cid_t
Definition: Identifiers.h:16
SWC::DB::Schemas::_replace
void _replace(const Schema::Ptr &schema)
Definition: Schemas.cc:50
SWC::Core::Vector< Pattern >
SWC::DB::Schemas::SelectorPatterns::tags
TagsPattern tags
Definition: Schemas.h:102
MutexSptd.h
SWC::DB::Schemas::Pattern::set
SWC_CAN_INLINE void set(Condition::Comp _comp, const std::string &value)
Definition: Schemas.h:74
SWC::DB::Schemas::SelectorPatterns::SelectorPatterns
SelectorPatterns(SelectorPatterns &&) noexcept=default
SWC::Condition::to_string
const char *SWC_CONST_FUNC to_string(Comp comp) noexcept
Definition: Comparators.cc:174
SWC::Core::MutexSptd
Definition: MutexSptd.h:16
SWC::DB::Schemas::_get
Schema::Ptr _get(cid_t cid) const noexcept
Definition: Schemas.cc:61
SWC::DB::Schemas::Pattern::Pattern
SWC_CAN_INLINE Pattern() noexcept
Definition: Schemas.h:29
SWC::DB::Schemas::Schemas
SWC_CAN_INLINE Schemas() noexcept
Definition: Schemas.h:115
SWC::DB::Schemas::Pattern::operator=
SWC_CAN_INLINE Pattern & operator=(const Pattern &other)
Definition: Schemas.h:61
SWC::DB::Schemas::matching
void matching(const SelectorPatterns &patterns, SchemasVec &entries, bool no_sys=true)
Definition: Schemas.cc:94
SWC::DB::Schemas::Map
std::unordered_map< cid_t, Schema::Ptr > Map
Definition: Schemas.h:19
SWC::DB::Schemas::Pattern::comp
Condition::Comp comp
Definition: Schemas.h:26
SWC::DB::Schemas::Pattern::set
SWC_CAN_INLINE void set(Condition::Comp _comp, std::string &&value)
Definition: Schemas.h:68
SWC::DB::Schemas::Pattern::Pattern
SWC_CAN_INLINE Pattern(Pattern &&other) noexcept
Definition: Schemas.h:42
SWC::DB::Schemas::Pattern
Definition: Schemas.h:24