libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
DatabaseTypes.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef DATABASETYPES_H
32 #define DATABASETYPES_H
33 
34 #include <string>
35 #include <vector>
36 #include <deque>
37 #include <map>
38 #include <memory>
39 
40 namespace BaseLib
41 {
42 namespace Database
43 {
44 
49 {
50  public:
54  struct DataType
55  {
56  enum Enum { NODATA, INTEGER, FLOAT, TEXT, BLOB };
57  };
58 
62  DataType::Enum dataType = DataType::Enum::NODATA;
63 
67  int32_t index = 0;
68 
72  int64_t intValue = 0;
73 
77  double floatValue = 0;
78 
82  std::string textValue;
83 
87  std::shared_ptr<std::vector<char>> binaryValue;
88 
92  DataColumn() { binaryValue.reset(new std::vector<char>()); }
93 
99  DataColumn(int64_t value) : DataColumn() { dataType = DataType::Enum::INTEGER; intValue = value; }
100 
106  DataColumn(uint64_t value) : DataColumn() { dataType = DataType::Enum::INTEGER; intValue = value; }
107 
113  DataColumn(int32_t value) : DataColumn() { dataType = DataType::Enum::INTEGER; intValue = value; }
114 
120  DataColumn(uint32_t value) : DataColumn() { dataType = DataType::Enum::INTEGER; intValue = value; }
121 
127  DataColumn(std::string value) : DataColumn() { dataType = DataType::Enum::TEXT; textValue = value; }
128 
134  DataColumn(double value) : DataColumn() { dataType = DataType::Enum::FLOAT; floatValue = value; }
135 
141  DataColumn(std::shared_ptr<std::vector<char>> value) : DataColumn() { dataType = DataType::Enum::BLOB; if(value) binaryValue = value; }
142 
148  DataColumn(const std::vector<char>& value) : DataColumn()
149  {
150  dataType = DataType::Enum::BLOB;
151  binaryValue.reset(new std::vector<char>());
152  binaryValue->insert(binaryValue->begin(), value.begin(), value.end());
153  }
154 
160  DataColumn(const std::vector<uint8_t>& value) : DataColumn()
161  {
162  dataType = DataType::Enum::BLOB;
163  binaryValue.reset(new std::vector<char>());
164  binaryValue->insert(binaryValue->begin(), value.begin(), value.end());
165  }
166 
170  virtual ~DataColumn() {}
171 };
172 
176 typedef std::map<uint32_t, std::map<uint32_t, std::shared_ptr<DataColumn>>> DataTable;
177 
181 typedef std::deque<std::shared_ptr<DataColumn>> DataRow;
182 
183 }
184 }
185 #endif
std::map< uint32_t, std::map< uint32_t, std::shared_ptr< DataColumn > > > DataTable
Type definition to easily create a DataTable.
Definition: DatabaseTypes.h:176
DataColumn()
Default constructor.
Definition: DatabaseTypes.h:92
Enumeration of the data types which can be stored in this class.
Definition: DatabaseTypes.h:54
std::shared_ptr< std::vector< char > > binaryValue
The binary value.
Definition: DatabaseTypes.h:87
Definition: BaseLib.cpp:34
DataColumn(std::string value)
Constructor to create a data column of type TEXT.
Definition: DatabaseTypes.h:127
DataType::Enum dataType
The data type of the column.
Definition: DatabaseTypes.h:62
DataColumn(int64_t value)
Constructor to create a data column of type INTEGER.
Definition: DatabaseTypes.h:99
DataColumn(uint32_t value)
Constructor to create a data column of type INTEGER.
Definition: DatabaseTypes.h:120
DataColumn(const std::vector< uint8_t > &value)
Constructor to create a data column of type BLOB.
Definition: DatabaseTypes.h:160
int64_t intValue
The integer value.
Definition: DatabaseTypes.h:72
PVariable value
Definition: UiElements.h:217
DataColumn(double value)
Constructor to create a data column of type FLOAT.
Definition: DatabaseTypes.h:134
std::string textValue
The text value.
Definition: DatabaseTypes.h:82
DataColumn(std::shared_ptr< std::vector< char >> value)
Constructor to create a data column of type BLOB.
Definition: DatabaseTypes.h:141
Enum
Definition: DatabaseTypes.h:56
DataColumn(int32_t value)
Constructor to create a data column of type INTEGER.
Definition: DatabaseTypes.h:113
DataColumn(uint64_t value)
Constructor to create a data column of type INTEGER.
Definition: DatabaseTypes.h:106
Class to store data of a database column in.
Definition: DatabaseTypes.h:48
virtual ~DataColumn()
Destructor.
Definition: DatabaseTypes.h:170
Definition: DatabaseTypes.h:56
double floatValue
The float value.
Definition: DatabaseTypes.h:77
Definition: DatabaseTypes.h:56
int32_t index
The column index.
Definition: DatabaseTypes.h:67
DataColumn(const std::vector< char > &value)
Constructor to create a data column of type BLOB.
Definition: DatabaseTypes.h:148
std::deque< std::shared_ptr< DataColumn > > DataRow
Type definition to easily create a DataRow.
Definition: DatabaseTypes.h:181