ClanLib  2.3.7
db_value.h
Go to the documentation of this file.
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2011 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 class CL_DBValue
34 {
35 
36 public:
37 
38  CL_DBValue();
39  CL_DBValue(const CL_DBReader &db_reader, int column_index);
40  CL_DBValue(const CL_DBReader &db_reader, const CL_StringRef &column_name);
41 
42  int to_integer() const;
43  CL_String to_string() const;
44  bool to_boolean() const;
45  double to_double() const;
46  CL_DataBuffer to_binary() const;
47  CL_DateTime to_datetime() const;
48 
49  inline operator int() const { return to_integer(); }
50  inline operator CL_String() const { return to_string(); }
51  inline operator bool() const { return to_boolean(); }
52  inline operator double() const { return to_double(); }
53  inline operator CL_DataBuffer() const { return to_binary(); }
54  inline operator CL_DateTime() const { return to_datetime(); }
55 
56 private:
57 
58  enum ParamType
59  {
60  cl_index, cl_name
61  };
62 
63  ParamType param_type;
64 
65  int column_index;
66  CL_String column_name;
67 
68  CL_DBReader db_reader;
69 };
70