SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
SpecsValue.cc
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 
10 
11 
12 namespace SWC { namespace DB { namespace Specs {
13 
14 
15 
18  MatcherPlainRE(const uint8_t* data, uint32_t size)
19  : re(re2::StringPiece(reinterpret_cast<const char*>(data), size)) {
20  }
22  ~MatcherPlainRE() noexcept { }
23  re2::RE2 re;
24 };
25 
26 bool Value::is_matching_plain(const Cells::Cell& cell) const {
27  if(empty())
28  return true;
29 
30  StaticBuffer v;
31  cell.get_value(v, false);
32  switch(comp) {
33  case Condition::RE: {
34  if(!data || !size)
35  return !v.base || !v.size;
36  if(!matcher)
38  return Condition::re(
39  static_cast<MatcherPlainRE*>(matcher)->re,
40  reinterpret_cast<char*>(v.base), v.size);
41  }
42  default:
44  }
45 }
46 
47 
50  MatcherSerial(const uint8_t* data, uint32_t size)
51  : fields(data, size, false) {
52  }
54  ~MatcherSerial() noexcept { }
56 };
57 
58 bool Value::is_matching_serial(const Cells::Cell& cell) const {
59  if(empty())
60  return true;
61  if(!matcher)
63  return static_cast<MatcherSerial*>(matcher)->fields.is_matching(cell)
64  ? comp == Condition::EQ
65  : comp == Condition::NE;
66 }
67 
68 
71  MatcherCounter(const uint8_t* data, uint32_t size) noexcept : value() {
72  errno = 0;
73  char *last = reinterpret_cast<char*>(const_cast<uint8_t*>(data)) + size;
74  value = strtoll(reinterpret_cast<const char*>(data), &last, 0);
75  }
76  int64_t value;
77 };
78 
79 bool Value::is_matching_counter(const Cells::Cell& cell) const {
80  if(empty())
81  return true;
82  if(!matcher)
85  comp, static_cast<MatcherCounter*>(matcher)->value, cell.get_counter());
86 }
87 
88 
89 void Value::print(Types::Column col_type, std::ostream& out) const {
90  out << "Value(";
91  if(size)
92  display(col_type, out);
93  out << ')';
94 }
95 
96 void Value::display(Types::Column col_type, std::ostream& out,
97  bool pretty) const {
98  out << "size=" << size << ' ' << Condition::to_string(comp);
99  if(size) {
100  if(col_type == Types::Column::SERIAL) {
101  Serial::Value::Fields(data, size, false).print(out);
102  } else {
103  out << '"';
104  char hex[5];
105  hex[4] = '\0';
106  const uint8_t* end = data + size;
107  for(const uint8_t* ptr = data; ptr < end; ++ptr) {
108  if(*ptr == '"')
109  out << '\\';
110  if(!pretty || (31 < *ptr && *ptr < 127)) {
111  out << *ptr;
112  } else {
113  sprintf(hex, "0x%X", *ptr);
114  out << hex;
115  }
116  }
117  out << '"';
118  }
119  }
120 }
121 
122 
123 
124 }}}
SWC::DB::Specs::MatcherPlainRE::re
re2::RE2 re
Definition: SpecsValue.cc:23
SWC::Condition::is_matching_extended
SWC_CAN_INLINE bool is_matching_extended(uint8_t comp, const uint8_t *p1, uint32_t p1_len, const uint8_t *p2, uint32_t p2_len)
Definition: Comparators.h:459
SWC::DB::Specs::Serial::Value::Fields::print
void print(std::ostream &out) const
Definition: SpecsValueSerialFields.cc:842
data
T data
Definition: BitFieldInt.h:1
SpecsValueSerialFields.h
SWC::DB::Specs::Serial::Value::Fields
Definition: SpecsValueSerialFields.h:335
SWC::DB::Specs::Value::size
uint32_t size
Definition: SpecsValue.h:251
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::DB::Specs::Value::print
void print(Types::Column col_type, std::ostream &out) const
Definition: SpecsValue.cc:89
SWC::DB::Specs::MatcherSerial::MatcherSerial
SWC_CAN_INLINE MatcherSerial(const uint8_t *data, uint32_t size)
Definition: SpecsValue.cc:50
SWC::DB::Cells::Cell
Definition: Cell.h:92
SWC::Condition::RE
@ RE
Definition: Comparators.h:36
SWC::DB::Specs::MatcherSerial
Definition: SpecsValue.cc:48
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::DB::Specs::Value::data
uint8_t * data
Definition: SpecsValue.h:252
SWC::Core::Buffer
Definition: Buffer.h:18
size
uint32_t size
Buffer size.
Definition: HeaderBufferInfo.h:47
SWC::Core::Buffer::size
size_t size
Definition: Buffer.h:130
SWC::Condition::EQ
@ EQ
Definition: Comparators.h:32
SWC::DB::Cells::Cell::get_value
Types::Encoder get_value(StaticBuffer &v, bool owner) const
Definition: Cell.cc:77
SWC::Condition::NE
@ NE
Definition: Comparators.h:35
Serialization.h
SWC::DB::Specs::MatcherPlainRE
Definition: SpecsValue.cc:16
SWC::Condition::is_matching
SWC_CAN_INLINE bool is_matching(bool volumetric, uint8_t comp, const uint8_t *p1, uint32_t p1_len, const uint8_t *p2, uint32_t p2_len)
Definition: Comparators.h:439
SWC::Condition::re
bool re(const re2::RE2 &regex, const re2::StringPiece &value)
Definition: Comparators.cc:225
SWC::DB::Specs::Value::TypeMatcher
Definition: SpecsValue.h:254
SWC::DB::Specs::MatcherSerial::~MatcherSerial
SWC_CAN_INLINE ~MatcherSerial() noexcept
Definition: SpecsValue.cc:54
SWC::DB::Specs::Value::is_matching_counter
bool is_matching_counter(const Cells::Cell &cell) const
Definition: SpecsValue.cc:79
SWC::DB::Cells::Cell::get_counter
constexpr SWC_CAN_INLINE int64_t get_counter() const
Definition: Cell.h:260
SWC::DB::Specs::MatcherCounter::MatcherCounter
SWC_CAN_INLINE MatcherCounter(const uint8_t *data, uint32_t size) noexcept
Definition: SpecsValue.cc:71
SWC::Condition::to_string
const char *SWC_CONST_FUNC to_string(Comp comp) noexcept
Definition: Comparators.cc:174
SWC::DB::Specs::MatcherSerial::fields
Serial::Value::Fields fields
Definition: SpecsValue.cc:55
SpecsValue.h
SWC::DB::Specs::Value::is_matching_serial
bool is_matching_serial(const Cells::Cell &cell) const
Definition: SpecsValue.cc:58
SWC::DB::Specs::MatcherPlainRE::MatcherPlainRE
SWC_CAN_INLINE MatcherPlainRE(const uint8_t *data, uint32_t size)
Definition: SpecsValue.cc:18
SWC::DB::Specs::Value::empty
constexpr SWC_CAN_INLINE bool empty() const noexcept
Definition: SpecsValue.h:166
SWC::DB::Types::Column::SERIAL
@ SERIAL
SWC::DB::Specs::Value::is_matching_plain
bool is_matching_plain(const Cells::Cell &cell) const
Definition: SpecsValue.cc:26
SWC::DB::Specs::Value::matcher
TypeMatcher * matcher
Definition: SpecsValue.h:258
SWC::DB::Specs::Value::display
void display(Types::Column col_type, std::ostream &out, bool pretty=true) const
Definition: SpecsValue.cc:96
SWC::DB::Specs::MatcherPlainRE::~MatcherPlainRE
SWC_CAN_INLINE ~MatcherPlainRE() noexcept
Definition: SpecsValue.cc:22
SWC::DB::Specs::Value::comp
Condition::Comp comp
Definition: SpecsValue.h:250
SWC::DB::Specs::MatcherCounter::value
int64_t value
Definition: SpecsValue.cc:76
SWC::DB::Specs::MatcherCounter
Definition: SpecsValue.cc:69