SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
SpecsValues.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_cells_SpecsValues_h
8 #define swcdb_db_cells_SpecsValues_h
9 
10 
12 
13 
14 namespace SWC { namespace DB { namespace Specs {
15 
16 
17 class Values : public Core::Vector<Value> {
18  public:
19 
21 
22  using Vec::insert;
23  using Vec::emplace_back;
24 
25 
27 
30  : col_type(a_col_type) {
31  }
32 
34  Values(const uint8_t** bufp, size_t* remainp, bool owner)
35  : col_type() {
36  decode(bufp, remainp, owner);
37  }
38 
40  Values(Values&& other) noexcept
41  : Vec(std::move(other)), col_type(other.col_type) {
42  }
43 
44  ~Values() noexcept { }
45 
47  Values& operator=(const Values& other) {
48  copy(other);
49  return *this;
50  }
51 
53  Values& operator=(Values&& other) noexcept {
54  move(other);
55  return *this;
56  }
57 
59  void move(Values& other) noexcept {
60  Vec::operator=(std::move(other));
61  col_type = other.col_type;
62  }
63 
64  Values(const Values& other);
65 
66  void copy(const Values& other);
67 
69 
70  Value& add(Value&& other);
71 
72  size_t size_of_internal() const noexcept;
73 
74  bool SWC_PURE_FUNC equal(const Values& other) const noexcept;
75 
76  bool is_matching(const Cells::Cell& cell) const;
77 
79  size_t encoded_length() const noexcept {
80  size_t sz = 0;
81  size_t c = 0;
82  for(const auto& value : *this) {
83  if(value.comp != Condition::NONE) {
84  ++c;
85  sz += value.encoded_length();
86  }
87  }
89  }
90 
92  void encode(uint8_t** bufp) const {
93  size_t c = 0;
94  for(const auto& value : *this) {
95  if(value.comp != Condition::NONE)
96  ++c;
97  }
99  for(const auto& value : *this) {
100  if(value.comp != Condition::NONE)
101  value.encode(bufp);
102  }
103  }
104 
106  void decode(const uint8_t** bufp, size_t* remainp, bool owner) {
107  clear();
108  size_t sz = Serialization::decode_vi64(bufp, remainp);
109  if(sz) {
110  reserve(sz);
111  for(; sz; --sz) emplace_back(bufp, remainp, owner);
112  }
113  }
114 
115  void print(std::ostream& out) const;
116 
117  void display(std::ostream& out, bool pretty,
118  const std::string& offset) const;
119 
120 };
121 
122 
123 
125 size_t Values::size_of_internal() const noexcept {
126  size_t sz = sizeof(*this);
127  for(const auto& value : *this)
128  sz += sizeof(value) + value.size;
129  return sz;
130 }
131 
133 bool Values::is_matching(const Cells::Cell& cell) const {
134  if(empty())
135  return true;
136 
137  switch(col_type) {
138  case Types::Column::PLAIN: {
139  for(const auto& value : *this) {
140  if(!value.is_matching_plain(cell))
141  return false;
142  }
143  return true;
144  }
145  case Types::Column::SERIAL: {
146  for(const auto& value : *this) {
147  if(!value.is_matching_serial(cell))
148  return false;
149  }
150  return true;
151  }
152  case Types::Column::COUNTER_I64:
153  case Types::Column::COUNTER_I32:
154  case Types::Column::COUNTER_I16:
155  case Types::Column::COUNTER_I8: {
156  for(const auto& value : *this) {
157  if(!value.is_matching_counter(cell))
158  return false;
159  }
160  return true;
161  }
162  default:
163  return false;
164  }
165 }
166 
167 
168 
169 }}}
170 
171 
172 
173 #ifdef SWC_IMPL_SOURCE
175 #endif
176 
177 
178 #endif // swcdb_db_cells_SpecsValues_h
SWC::Core::Vector< Value >::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
SWC::DB::Specs::Values::is_matching
bool is_matching(const Cells::Cell &cell) const
Definition: SpecsValues.h:133
SWC::DB::Specs::Values::size_of_internal
size_t size_of_internal() const noexcept
Definition: SpecsValues.h:125
SWC::Core::Vector< Value >::operator=
SWC_CAN_INLINE Vector & operator=(Vector &&other) noexcept
Definition: Vector.h:141
SWC::DB::Specs::Values::print
void print(std::ostream &out) const
Definition: SpecsValues.cc:42
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::DB::Specs::Values::display
void display(std::ostream &out, bool pretty, const std::string &offset) const
Definition: SpecsValues.cc:55
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::DB::Specs::Values::operator=
SWC_CAN_INLINE Values & operator=(Values &&other) noexcept
Definition: SpecsValues.h:53
SWC::DB::Specs::Values::equal
bool SWC_PURE_FUNC equal(const Values &other) const noexcept
Definition: SpecsValues.cc:32
SWC::DB::Specs::Values::~Values
~Values() noexcept
Definition: SpecsValues.h:44
SWC::DB::Specs::Values::copy
void copy(const Values &other)
Definition: SpecsValues.cc:19
SWC::Condition::Comp
Comp
Definition: Comparators.h:27
SWC::Core::Vector< Value >::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: Vector.h:168
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::DB::Cell::Serial::Value::UNKNOWN
@ UNKNOWN
Definition: CellValueSerialField.h:34
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC_PURE_FUNC
#define SWC_PURE_FUNC
Definition: Compat.h:108
SWC::Condition::EQ
@ EQ
Definition: Comparators.h:32
SWC::DB::Specs::Values::move
SWC_CAN_INLINE void move(Values &other) noexcept
Definition: SpecsValues.h:59
SWC::DB::Specs::Values::operator=
SWC_CAN_INLINE Values & operator=(const Values &other)
Definition: SpecsValues.h:47
SWC::Serialization::encoded_length_vi64
constexpr SWC_CAN_INLINE uint8_t encoded_length_vi64(uint64_t val) noexcept
Definition: Serialization.h:272
SWC::Condition::NONE
@ NONE
Definition: Comparators.h:28
SWC::DB::Specs::Value
Definition: SpecsValue.h:17
SpecsValues.cc
SWC::Core::Vector
Definition: Vector.h:14
SWC::DB::Specs::Values::Values
SWC_CAN_INLINE Values(Values &&other) noexcept
Definition: SpecsValues.h:40
SWC::Core::Vector< Value >::reserve
SWC_CAN_INLINE void reserve()
Definition: Vector.h:294
SWC::DB::Specs::Values::add
Value & add(Condition::Comp comp=Condition::EQ)
Definition: SpecsValues.cc:24
SWC::Serialization::decode_vi64
constexpr SWC_CAN_INLINE uint64_t decode_vi64(const uint8_t **bufp, size_t *remainp)
Definition: Serialization.h:302
SWC::DB::Specs::Values::encoded_length
SWC_CAN_INLINE size_t encoded_length() const noexcept
Definition: SpecsValues.h:79
SpecsValue.h
SWC::DB::Specs::Values::encode
SWC_CAN_INLINE void encode(uint8_t **bufp) const
Definition: SpecsValues.h:92
SWC::DB::Specs::Values::Values
SWC_CAN_INLINE Values(const uint8_t **bufp, size_t *remainp, bool owner)
Definition: SpecsValues.h:34
SWC::Serialization::encode_vi64
constexpr SWC_CAN_INLINE void encode_vi64(uint8_t **bufp, uint64_t val)
Definition: Serialization.h:286
SWC::DB::Types::Column::SERIAL
@ SERIAL
SWC::DB::Specs::Values::col_type
Types::Column col_type
Definition: SpecsValues.h:26
SWC::DB::Specs::Values::decode
SWC_CAN_INLINE void decode(const uint8_t **bufp, size_t *remainp, bool owner)
Definition: SpecsValues.h:106
SWC::DB::Specs::Values
Definition: SpecsValues.h:17
SWC::Core::Vector< Value >::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::Core::Vector< Value >::insert
SWC_CAN_INLINE iterator insert(size_type offset, ArgsT &&... args)
Definition: Vector.h:367
SWC::DB::Specs::Values::Vec
Core::Vector< Value > Vec
Definition: SpecsValues.h:20
SWC::DB::Specs::Values::Values
SWC_CAN_INLINE Values(Types::Column a_col_type=Types::Column::UNKNOWN) noexcept
Definition: SpecsValues.h:29