type-holder.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2008 Maciej Sobczak, Stephen Hutton
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_TYPE_HOLDER_H_INCLUDED
9 #define SOCI_TYPE_HOLDER_H_INCLUDED
10 // std
11 #include <typeinfo>
12 
13 namespace soci
14 {
15 
16 namespace details
17 {
18 
19 // Base class holder + derived class type_holder for storing type data
20 // instances in a container of holder objects
21 template <typename T>
23 
24 class holder
25 {
26 public:
27  holder() {}
28  virtual ~holder() {}
29 
30  template<typename T>
31  T get()
32  {
33  type_holder<T>* p = dynamic_cast<type_holder<T> *>(this);
34  if (p)
35  {
36  return p->template value<T>();
37  }
38  else
39  {
40  throw std::bad_cast();
41  }
42  }
43 
44 private:
45 
46  template<typename T>
47  T value();
48 };
49 
50 template <typename T>
51 class type_holder : public holder
52 {
53 public:
54  type_holder(T * t) : t_(t) {}
55  ~type_holder() { delete t_; }
56 
57  template<typename TypeValue>
58  TypeValue value() const { return *t_; }
59 
60 private:
61  T * t_;
62 };
63 
64 } // namespace details
65 
66 } // namespace soci
67 
68 #endif // SOCI_TYPE_HOLDER_H_INCLUDED
TypeValue value() const
Definition: type-holder.h:58


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41