-
Notifications
You must be signed in to change notification settings - Fork 164
/
Copy pathProviderManager.h
81 lines (59 loc) · 3.08 KB
/
ProviderManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/************************************************************************
* Copyright(c) 2009, One Unified. All rights reserved. *
* *
* This file is provided as is WITHOUT ANY WARRANTY *
* without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
* This software may not be used nor distributed without proper license *
* agreement. *
* *
* See the file LICENSE.txt for redistribution information. *
************************************************************************/
// when a provider is created, it should be registered with the provider manager
#pragma once
#include <map>
#include <string>
#include <OUCommon/ManagerBase.h>
#include "KeyTypes.h"
#include "ProviderInterface.h"
// key might be account or other similar globally known identifier
// map could be converted over to boost::fusion for storing full types and values for the
// various providers, and then have specialized algorithms for processing the tuples of providers.
namespace ou { // One Unified
namespace tf { // TradeFrame
class ProviderManager: public ou::db::ManagerBase<ProviderManager> {
public:
typedef keytypes::idProvider_t idProvider_t;
typedef ProviderInterfaceBase::pProvider_t pProvider_t;
ProviderManager() {};
virtual ~ProviderManager() {};
// when to use Construct and when to use Get?
pProvider_t Construct( const idProvider_t& key, keytypes::eidProvider_t type ); // construct given an enum
template<class P> pProvider_t Construct( const idProvider_t& key ); // construct given a provider 'P' type
void Register( const idProvider_t& key, pProvider_t pProvider );
void Release( const idProvider_t& key ); // should we check for close or anything? need to keep a lock count.
pProvider_t Get( const idProvider_t& key );
template<class P> pProvider_t Construct();
void Register( pProvider_t pProvider );
protected:
private:
typedef std::map<idProvider_t, pProvider_t> mapProviders_t;
typedef std::pair<idProvider_t, pProvider_t> mapProviders_pair_t;
typedef mapProviders_t::iterator iterProviders_t;
mapProviders_t m_mapProviders;
};
template<class P> ProviderManager::pProvider_t ProviderManager::Construct() {
// need to perform some construction asssertions to ensure P is of a valid type
pProvider_t pProvider = std::make_shared<P>();
Register( pProvider );
return pProvider;
}
template<class P> ProviderManager::pProvider_t ProviderManager::Construct( const idProvider_t& key ) {
// need to perform some construction asssertions to ensure P is of a valid type
pProvider_t pProvider = std::make_shared<P>();
Register( key, pProvider );
return pProvider;
}
} // namespace tf
} // namespace ou