INTRODUCTION
Overview
Download and Install
Documentation
Publications
REPOSITORY
Libraries
DEVELOPER
Dev Guide
Dashboard
PEOPLE
Contributors
Users
Project
Download
Mailing lists
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
src
gbxsickacfr
gbxiceutilacfr
notify.h
1
/*
2
* GearBox Project: Peer-Reviewed Open-Source Libraries for Robotics
3
* http://gearbox.sf.net/
4
* Copyright (c) 2004-2010 Alex Brooks, Alexei Makarenko, Tobias Kaupp
5
*
6
* This distribution is licensed to you under the terms described in
7
* the LICENSE file included in this distribution.
8
*
9
*/
10
11
#ifndef GBXICEUTILACFR_NOTIFY_H
12
#define GBXICEUTILACFR_NOTIFY_H
13
14
#include <gbxutilacfr/exceptions.h>
15
#include <iostream>
16
17
//
18
// note: this class can be libGbxUtilAcfr but we keep it with the other "data pattern"
19
// classes: Store and Buffer.
20
//
21
namespace
gbxiceutilacfr {
22
29
template
<
class
Type>
30
class
NotifyHandler
31
{
32
public
:
33
virtual
~
NotifyHandler
() {};
37
virtual
void
handleData
(
const
Type & obj )=0;
38
};
39
51
template
<
class
Type>
52
class
Notify
53
{
54
public
:
55
Notify
()
56
: hasNotifyHandler_(
false
)
57
{};
58
59
virtual
~
Notify
() {};
60
63
void
setNotifyHandler
(
NotifyHandler<Type>
* handler );
64
66
bool
hasNotifyHandler
() {
return
hasNotifyHandler_; };
67
71
void
set
(
const
Type & obj );
72
73
protected
:
75
virtual
void
internalSet
(
const
Type & obj );
76
78
NotifyHandler<Type>
*
handler_
;
79
80
private
:
81
82
bool
hasNotifyHandler_;
83
};
84
85
template
<
class
Type>
86
void
Notify<Type>::setNotifyHandler
(
NotifyHandler<Type>
* handler )
87
{
88
if
( handler == 0 ) {
89
std::cout<<
"TRACE(notify.h): no handler set. Ignoring data."
<< std::endl;
90
return
;
91
}
92
93
handler_ = handler;
94
hasNotifyHandler_ =
true
;
95
}
96
97
template
<
class
Type>
98
void
Notify<Type>::set
(
const
Type & obj )
99
{
100
if
( !hasNotifyHandler_ ) {
101
throw
gbxutilacfr::Exception
( ERROR_INFO,
"setting data when data handler has not been set"
);
102
}
103
104
internalSet( obj );
105
}
106
107
template
<
class
Type>
108
void
Notify<Type>::internalSet
(
const
Type & obj )
109
{
110
handler_->handleData( obj );
111
}
112
113
}
// end namespace
114
115
#endif
Generated for GearBox by
1.4.5