SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Column.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 
7 
9 
10 
11 namespace SWC { namespace DB { namespace Types {
12 
13 
14 namespace {
15  const char Column_PLAIN[] = "PLAIN";
16  const char Column_COUNTER_I64[] = "COUNTER_I64";
17  const char Column_COUNTER_I32[] = "COUNTER_I32";
18  const char Column_COUNTER_I16[] = "COUNTER_I16";
19  const char Column_COUNTER_I8[] = "COUNTER_I8";
20  const char Column_SERIAL[] = "SERIAL";
21  const char Column_CELL_DEFINED[] = "CELL_DEFINED";
22  const char Column_UNKNOWN[] = "UNKNOWN";
23 }
24 
25 
26 bool is_counter(const Column typ) noexcept {
27  switch(typ) {
28  case Column::COUNTER_I64:
29  case Column::COUNTER_I32:
30  case Column::COUNTER_I16:
31  case Column::COUNTER_I8:
32  return true;
33  default:
34  return false;
35  }
36 }
37 
38 const char* to_string(Column typ) noexcept {
39  switch(typ) {
40  case Column::PLAIN:
41  return Column_PLAIN;
42  case Column::COUNTER_I64:
43  return Column_COUNTER_I64;
44  case Column::COUNTER_I32:
45  return Column_COUNTER_I32;
46  case Column::COUNTER_I16:
47  return Column_COUNTER_I16;
48  case Column::COUNTER_I8:
49  return Column_COUNTER_I8;
50  case Column::SERIAL:
51  return Column_SERIAL;
53  return Column_CELL_DEFINED;
54  default:
55  return Column_UNKNOWN;
56  }
57 }
58 
59 Column column_type_from(const std::string& typ) noexcept {
60  switch(typ.length()) {
61  case 1: {
62  switch(*typ.data()) {
63  case '1':
64  return Column::PLAIN;
65  case '2':
66  return Column::COUNTER_I64;
67  case '3':
68  return Column::COUNTER_I32;
69  case '4':
70  return Column::COUNTER_I16;
71  case '5':
72  return Column::COUNTER_I8;
73  case '6':
74  return Column::SERIAL;
75  default:
76  break;
77  }
78  break;
79  }
80  case 5: {
81  if(Condition::str_case_eq(typ.data(), Column_PLAIN, 5))
82  return Column::PLAIN;
83  break;
84  }
85  case 6: {
86  if(Condition::str_case_eq(typ.data(), Column_SERIAL, 6))
87  return Column::SERIAL;
88  break;
89  }
90  case 7: {
91  if(Condition::str_case_eq(typ.data(), Column_COUNTER_I64, 7))
92  return Column::COUNTER_I64;
93  break;
94  }
95  case 10: {
96  if(Condition::str_case_eq(typ.data(), Column_COUNTER_I8, 10))
97  return Column::COUNTER_I8;
98  break;
99  }
100  case 11: {
101  if(Condition::str_case_eq(typ.data(), Column_COUNTER_I64, 11))
102  return Column::COUNTER_I64;
103  if(Condition::str_case_eq(typ.data(), Column_COUNTER_I32, 11))
104  return Column::COUNTER_I32;
105  if(Condition::str_case_eq(typ.data(), Column_COUNTER_I16, 11))
106  return Column::COUNTER_I16;
107  break;
108  }
109  default:
110  break;
111  }
112  return Column::UNKNOWN;
113 }
114 
115 
116 }}}
SWC::DB::Types::column_type_from
Column SWC_PURE_FUNC column_type_from(const std::string &typ) noexcept
Definition: Column.cc:59
SWC::DB::Types::to_string
const char *SWC_CONST_FUNC to_string(Column typ) noexcept
Definition: Column.cc:38
SWC::DB::Types::Column
Column
Definition: Column.h:18
SWC::DB::Types::Column::UNKNOWN
@ UNKNOWN
SWC::DB::Cell::Serial::Value::UNKNOWN
@ UNKNOWN
Definition: CellValueSerialField.h:34
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
Column.h
SWC::DB::Types::is_counter
bool SWC_CONST_FUNC is_counter(const Column typ) noexcept
Definition: Column.cc:26
SWC::DB::Types::Column::SERIAL
@ SERIAL
SWC::Condition::str_case_eq
bool str_case_eq(const char *s1, const char *s2, size_t count) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
Definition: Comparators_basic.h:257