RSC
0.9.0
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
ObservableFactory.h
Go to the documentation of this file.
1
/* ============================================================
2
*
3
* This file is part of the RSC project
4
*
5
* Copyright (C) 2010, 2011 Jan Moringen
6
*
7
* This file may be licensed under the terms of the
8
* GNU Lesser General Public License Version 3 (the ``LGPL''),
9
* or (at your option) any later version.
10
*
11
* Software distributed under the License is distributed
12
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13
* express or implied. See the LGPL for the specific language
14
* governing rights and limitations.
15
*
16
* You should have received a copy of the LGPL along with this
17
* program. If not, go to http://www.gnu.org/licenses/lgpl.html
18
* or write to the Free Software Foundation, Inc.,
19
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
*
21
* The development of this software was supported by:
22
* CoR-Lab, Research Institute for Cognition and Robotics
23
* Bielefeld University
24
*
25
* ============================================================ */
26
27
#pragma once
28
29
#include <boost/signals.hpp>
30
31
#include "
Factory.h
"
32
33
namespace
rsc {
34
namespace
patterns {
35
42
template
<
typename
Key,
typename
Interface>
43
class
ObservableFactory
:
public
Factory
<Key, Interface> {
44
protected
:
45
typedef
Factory<Key, Interface>
base
;
46
public
:
47
typedef
typename
base::CreateFunction
CreateFunction
;
48
49
typedef
boost::signal2<void, const std::string&, const CreateFunction&>
50
ImplAddedSignal
;
51
52
typedef
boost::signal2<void, const std::string&, const CreateFunction&>
53
ImplRemovedSignal
;
54
58
ImplAddedSignal
&
59
signalImplAdded
() throw ();
60
64
ImplRemovedSignal
&
65
signalImplRemoved
() throw ();
66
protected:
67
typedef typename
base
::
ImplMap
ImplMap
;
68
69
ImplAddedSignal
signal_impl_added_
;
70
ImplRemovedSignal
signal_impl_removed_
;
71
75
void
register_
(const Key& key, const
CreateFunction
& create_function_);
76
80
void
unregister
(const Key& key);
81
};
82
86
template<typename Key, typename Interface>
87
class
ObservableSingletonFactory
: public
Singleton
<
ObservableSingletonFactory
<
88
Key, Interface> > , public
ObservableFactory
<Key, Interface> {
89
friend
class
Singleton
<
SingletonFactory
<Key, Interface> > ;
90
private
:
91
ObservableSingletonFactory
();
92
};
93
94
// ObservableFactory implementation
95
96
template
<
typename
Key,
typename
Interface>
97
typename
ObservableFactory<Key, Interface>::ImplAddedSignal
&
98
ObservableFactory<Key, Interface>::signalImplAdded
() throw () {
99
return
this->
signal_impl_added_
;
100
}
101
102
template
<
typename
Key,
typename
Interface>
103
typename
ObservableFactory<Key, Interface>::ImplRemovedSignal
&
104
ObservableFactory<Key, Interface>::signalImplRemoved
() throw () {
105
return
this->
signal_impl_removed_
;
106
}
107
108
template
<
typename
Key,
typename
Interface>
109
void
ObservableFactory<Key, Interface>::register_
(
const
Key& key,
110
const
CreateFunction
& create_function_) {
111
base::register_
(key, create_function_);
112
113
//
114
if
(!this->
signal_impl_added_
.empty()) {
115
this->
signal_impl_added_
(key, create_function_);
116
}
117
}
118
119
template
<
typename
Key,
typename
Interface>
120
void
ObservableFactory<Key, Interface>::unregister
(
const
Key& key) {
121
//
122
if
(!this->
signal_impl_removed_
.empty()) {
123
typename
ImplMap::iterator it;
124
if
((it = this->
impl_map_
.find(key)) != this->
impl_map_
.end()) {
125
this->
signal_impl_removed_
(it->first, it->second);
126
}
127
}
128
129
base::unregister
(key);
130
}
131
132
// ObservableSingletonFactory implementation
133
134
template
<
typename
Key,
typename
Interface>
135
ObservableSingletonFactory<Key, Interface>::ObservableSingletonFactory
() {
136
}
137
138
}
139
}
rsc
patterns
ObservableFactory.h
Generated on Tue Aug 6 2013 15:04:20 for RSC by
1.8.1.2