db_value.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2013 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Animehunter
28 */
29 
30 
31 #pragma once
32 
33 namespace clan
34 {
35 
36 class DBValue
37 {
38 public:
39  DBValue();
40  DBValue(const DBReader &db_reader, int column_index);
41  DBValue(const DBReader &db_reader, const std::string &column_name);
42 
43  int to_integer() const;
44  std::string to_string() const;
45  bool to_boolean() const;
46  double to_double() const;
47  DataBuffer to_binary() const;
48  DateTime to_datetime() const;
49 
50  inline operator int() const { return to_integer(); }
51  inline operator std::string() const { return to_string(); }
52  inline operator bool() const { return to_boolean(); }
53  inline operator double() const { return to_double(); }
54  inline operator DataBuffer() const { return to_binary(); }
55  inline operator DateTime() const { return to_datetime(); }
56 
57 private:
58 
59  enum ParamType
60  {
61  cl_index, cl_name
62  };
63 
64  ParamType param_type;
65 
66  int column_index;
67  std::string column_name;
68 
69  DBReader db_reader;
70 };
71 
72 }
double to_double() const
Database reader.
Definition: db_reader.h:47
int to_integer() const
Date/Time class.
Definition: datetime.h:44
std::string to_string() const
Definition: db_value.h:36
DataBuffer to_binary() const
DateTime to_datetime() const
bool to_boolean() const
General purpose data buffer.
Definition: databuffer.h:43