[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / dbwrappers / qry_dat.h
blob88d708b5c0fbacbefa300b80a7e7f24e229e0e6f
1 /*
2 * Copyright (C) 2004, Leo Seib, Hannover
4 * Project:Dataset C++ Dynamic Library
5 * Module: FieldValue class and result sets classes header file
6 * Author: Leo Seib E-Mail: leoseib@web.de
7 * Begin: 5/04/2002
9 * SPDX-License-Identifier: MIT
10 * See LICENSES/README.md for more information.
13 #pragma once
15 #include <iostream>
16 #include <stdint.h>
17 #include <string>
18 #include <vector>
20 namespace dbiplus
23 enum fType
25 ft_String,
26 ft_Boolean,
27 ft_Char,
28 ft_WChar,
29 ft_WideString,
30 ft_Short,
31 ft_UShort,
32 ft_Int,
33 ft_UInt,
34 ft_Float,
35 ft_Double,
36 ft_LongDouble,
37 ft_Int64,
38 ft_Object
41 #ifdef TARGET_WINDOWS_STORE
42 #pragma pack(push)
43 #pragma pack(8)
44 #endif
46 class field_value
48 private:
49 fType field_type;
50 std::string str_value;
51 union
53 bool bool_value;
54 char char_value;
55 short short_value;
56 unsigned short ushort_value;
57 int int_value;
58 unsigned int uint_value;
59 float float_value;
60 double double_value;
61 int64_t int64_value;
62 void* object_value;
65 bool is_null;
67 public:
68 field_value();
69 explicit field_value(const char* s);
70 explicit field_value(const bool b);
71 explicit field_value(const char c);
72 explicit field_value(const short s);
73 explicit field_value(const unsigned short us);
74 explicit field_value(const int l);
75 explicit field_value(const unsigned int ul);
76 explicit field_value(const float f);
77 explicit field_value(const double d);
78 explicit field_value(const int64_t i);
79 field_value(const char* s, std::size_t len);
80 field_value(const field_value& fv);
81 field_value(field_value&& fv) noexcept;
82 ~field_value();
84 fType get_fType() const { return field_type; }
85 bool get_isNull() const { return is_null; }
86 std::string get_asString() const&;
87 std::string get_asString() &&;
88 bool get_asBool() const;
89 char get_asChar() const;
90 short get_asShort() const;
91 unsigned short get_asUShort() const;
92 int get_asInt() const;
93 unsigned int get_asUInt() const;
94 float get_asFloat() const;
95 double get_asDouble() const;
96 int64_t get_asInt64() const;
98 field_value& operator=(const char* s)
100 set_asString(s);
101 return *this;
103 field_value& operator=(const std::string& s)
105 set_asString(s);
106 return *this;
108 field_value& operator=(std::string&& s)
110 set_asString(std::move(s));
111 return *this;
113 field_value& operator=(const bool b)
115 set_asBool(b);
116 return *this;
118 field_value& operator=(const short s)
120 set_asShort(s);
121 return *this;
123 field_value& operator=(const unsigned short us)
125 set_asUShort(us);
126 return *this;
128 field_value& operator=(const int l)
130 set_asInt(l);
131 return *this;
133 field_value& operator=(const unsigned int l)
135 set_asUInt(l);
136 return *this;
138 field_value& operator=(const float f)
140 set_asFloat(f);
141 return *this;
143 field_value& operator=(const double d)
145 set_asDouble(d);
146 return *this;
148 field_value& operator=(const int64_t i)
150 set_asInt64(i);
151 return *this;
153 field_value& operator=(const field_value& fv);
154 field_value& operator=(field_value&& fv) noexcept;
156 //class ostream;
157 friend std::ostream& operator<<(std::ostream& os, const field_value& fv)
159 switch (fv.get_fType())
161 case ft_String:
163 return os << fv.get_asString();
164 break;
166 case ft_Boolean:
168 return os << fv.get_asBool();
169 break;
171 case ft_Char:
173 return os << fv.get_asChar();
174 break;
176 case ft_Short:
178 return os << fv.get_asShort();
179 break;
181 case ft_UShort:
183 return os << fv.get_asUShort();
184 break;
186 case ft_Int:
188 return os << fv.get_asInt();
189 break;
191 case ft_UInt:
193 return os << fv.get_asUInt();
194 break;
196 case ft_Float:
198 return os << fv.get_asFloat();
199 break;
201 case ft_Double:
203 return os << fv.get_asDouble();
204 break;
206 case ft_Int64:
208 return os << fv.get_asInt64();
209 break;
211 default:
213 return os;
214 break;
219 void set_isNull() { is_null = true; }
220 void set_asString(const char* s);
221 void set_asString(const char* s, std::size_t len);
222 void set_asString(const std::string& s);
223 void set_asString(std::string&& s);
224 void set_asBool(const bool b);
225 void set_asChar(const char c);
226 void set_asShort(const short s);
227 void set_asUShort(const unsigned short us);
228 void set_asInt(const int l);
229 void set_asUInt(const unsigned int l);
230 void set_asFloat(const float f);
231 void set_asDouble(const double d);
232 void set_asInt64(const int64_t i);
234 fType get_field_type();
235 std::string gft();
238 struct field_prop
240 std::string name;
243 struct field
245 field_prop props;
246 field_value val;
249 typedef std::vector<field> Fields;
250 typedef std::vector<field_value> sql_record;
251 typedef std::vector<field_prop> record_prop;
252 typedef std::vector<sql_record*> query_data;
253 typedef field_value variant;
255 class result_set
257 public:
258 result_set() = default;
259 ~result_set() { clear(); };
260 void clear()
262 for (unsigned int i = 0; i < records.size(); i++)
263 if (records[i])
264 delete records[i];
265 records.clear();
266 record_header.clear();
269 record_prop record_header;
270 query_data records;
273 #ifdef TARGET_WINDOWS_STORE
274 #pragma pack(pop)
275 #endif
276 } // namespace dbiplus