DatabaseConnectionPool.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/****************************************************************************
4** Copyright (c) 2001-2014
5**
6** This file is part of the QuickFIX FIX Engine
7**
8** This file may be distributed under the terms of the quickfixengine.org
9** license as defined by quickfixengine.org and appearing in the file
10** LICENSE included in the packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15** See http://www.quickfixengine.org/LICENSE for licensing information.
16**
17** Contact ask@quickfixengine.org if any conditions of this licensing are
18** not clear to you.
19**
20****************************************************************************/
21
22#ifndef FIX_DATABASECONNECTIONPOOL_H
23#define FIX_DATABASECONNECTIONPOOL_H
24
25#ifdef _MSC_VER
26#pragma warning( disable : 4503 4355 4786 4290 )
27#endif
28
30#include <string>
31#include <map>
32
33namespace FIX
34{
35template< typename T > class DatabaseConnectionPool
36{
37public:
38 DatabaseConnectionPool( bool poolConnections )
39 : m_poolConnections( poolConnections ) {}
40
42 {
44 return new T( id );
45
46 if( m_connections.find( id ) == m_connections.end() )
47 {
49 ( new T(id), 0 );
50 }
51 m_connections[id].second++;
52 return m_connections[id].first;
53 }
54
55 bool destroy( T* pConnection )
56 {
58 {
59 delete pConnection;
60 return true;
61 }
62
63 const DatabaseConnectionID& id = pConnection->connectionID();
64 if( m_connections.find( id ) == m_connections.end() )
65 return false;
66
67 Connection& connection = m_connections[id];
68 if( connection.first != pConnection )
69 return false;
70
71 connection.second--;
72 if( connection.second == 0 )
73 {
74 m_connections.erase( id );
75 delete pConnection;
76 }
77 return true;
78 }
79
80private:
81 typedef std::pair<T*, int>
83 typedef std::map<DatabaseConnectionID, Connection>
85
88};
89}
90
91#endif
std::map< DatabaseConnectionID, Connection > Connections
T * create(const DatabaseConnectionID &id)
DatabaseConnectionPool(bool poolConnections)

Generated on Sun Mar 31 2024 07:07:24 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001