Main Page
Namespaces
Classes
Files
File List
File Members
libism
ISM
soci
src
core
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
24
class
SOCI_DECL
ref_counted_statement_base
25
{
26
public
:
27
ref_counted_statement_base
(
session
& s);
28
29
virtual
~ref_counted_statement_base
() {}
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
62
session
&
session_
;
63
64
private
:
65
// noncopyable
66
ref_counted_statement_base
(
ref_counted_statement_base
const
&);
67
ref_counted_statement_base
& operator=(
ref_counted_statement_base
const
&);
68
};
69
70
// this class is supposed to be a vehicle for the "once" statements
71
// it executes the whole statement in its destructor
72
class
ref_counted_statement
:
public
ref_counted_statement_base
73
{
74
public
:
75
ref_counted_statement
(
session
& s)
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
:
84
statement
st_
;
85
};
86
87
}
// namespace details
88
89
}
// namespace soci
90
91
#endif
statement.h
into-type.h
soci::details::ref_counted_statement_base
Definition:
ref-counted-statement.h:24
soci::statement
Definition:
statement.h:167
soci::details::ref_counted_statement_base::~ref_counted_statement_base
virtual ~ref_counted_statement_base()
Definition:
ref-counted-statement.h:29
soci::details::ref_counted_statement_base::refCount_
int refCount_
Definition:
ref-counted-statement.h:60
soci::details::ref_counted_statement::ref_counted_statement
ref_counted_statement(session &s)
Definition:
ref-counted-statement.h:75
SOCI_DECL
#define SOCI_DECL
Definition:
soci-config.h:31
soci::details::ref_counted_statement_base::inc_ref
void inc_ref()
Definition:
ref-counted-statement.h:33
soci::details::ref_counted_statement
Definition:
ref-counted-statement.h:72
soci::details::ref_counted_statement::st_
statement st_
Definition:
ref-counted-statement.h:84
use-type.h
soci::session
Definition:
session.h:40
soci::details::ref_counted_statement_base::session_
session & session_
Definition:
ref-counted-statement.h:62
soci::details::ref_counted_statement_base::dec_ref
void dec_ref()
Definition:
ref-counted-statement.h:34
soci::details::ref_counted_statement::exchange
void exchange(T &t)
Definition:
ref-counted-statement.h:81
soci::details::ref_counted_statement_base::accumulate
void accumulate(T const &t)
Definition:
ref-counted-statement.h:53
soci
Definition:
db2/common.h:15
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