INTRODUCTION
Overview
Download and Install
Documentation
Publications

REPOSITORY
Libraries

DEVELOPER
Dev Guide
Dashboard

PEOPLE
Contributors
Users

SourceForge.net Logo
Project
Download
Mailing lists

 

         
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//
21namespace gbxiceutilacfr {
22
29template<class Type>
31{
32public:
33 virtual ~NotifyHandler() {};
37 virtual void handleData( const Type & obj )=0;
38};
39
51template<class Type>
52class Notify
53{
54public:
55 Notify()
56 : hasNotifyHandler_(false)
57 {};
58
59 virtual ~Notify() {};
60
64
66 bool hasNotifyHandler() { return hasNotifyHandler_; };
67
71 void set( const Type & obj );
72
73protected:
75 virtual void internalSet( const Type & obj );
76
79
80private:
81
82 bool hasNotifyHandler_;
83};
84
85template<class Type>
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
97template<class Type>
98void 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
107template<class Type>
108void Notify<Type>::internalSet( const Type & obj )
109{
110 handler_->handleData( obj );
111}
112
113} // end namespace
114
115#endif
The object which implements the callback function.
Definition: notify.h:31
virtual void handleData(const Type &obj)=0
A data pipe with callback semantics.
Definition: notify.h:53
NotifyHandler< Type > * handler_
Interface to the object which is notified of incoming data.
Definition: notify.h:78
void set(const Type &obj)
Definition: notify.h:98
bool hasNotifyHandler()
Returns TRUE is the notify handler has been set and FALSE otherwise.
Definition: notify.h:66
virtual void internalSet(const Type &obj)
Reimplement this function for non-standard types.
Definition: notify.h:108
void setNotifyHandler(NotifyHandler< Type > *handler)
Definition: notify.h:86
Base class for all GbxUtilAcfr exceptions.
Definition: gbxutilacfr/exceptions.h:66
Utility namespace (part of SICK-ACFR driver)
Definition: buffer.h:21
 

Generated for GearBox by  doxygen 1.4.5