ref-counted-statement.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_REF_COUNTED_STATEMENT_H_INCLUDED
9 #define SOCI_REF_COUNTED_STATEMENT_H_INCLUDED
10 
11 #include "statement.h"
12 #include "into-type.h"
13 #include "use-type.h"
14 // std
15 #include <sstream>
16 
17 namespace soci
18 {
19 
20 namespace details
21 {
22 
23 // this class is a base for both "once" and "prepare" statements
25 {
26 public:
28 
30 
31  virtual void final_action() = 0;
32 
33  void inc_ref() { ++refCount_; }
34  void dec_ref()
35  {
36  if (--refCount_ == 0)
37  {
38  try
39  {
40  final_action();
41  }
42  catch (...)
43  {
44  delete this;
45  throw;
46  }
47 
48  delete this;
49  }
50  }
51 
52  template <typename T>
53  void accumulate(T const & t) { get_query_stream() << t; }
54 
55 protected:
56  // this function allows to break the circular dependenc
57  // between session and this class
58  std::ostringstream & get_query_stream();
59 
60  int refCount_;
61 
63 
64 private:
65  // noncopyable
68 };
69 
70 // this class is supposed to be a vehicle for the "once" statements
71 // it executes the whole statement in its destructor
73 {
74 public:
76  : ref_counted_statement_base(s), st_(s) {}
77 
78  virtual void final_action();
79 
80  template <typename T>
81  void exchange(T &t) { st_.exchange(t); }
82 
83 private:
85 };
86 
87 } // namespace details
88 
89 } // namespace soci
90 
91 #endif
#define SOCI_DECL
Definition: soci-config.h:31


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:40