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 //
21 namespace gbxiceutilacfr {
22 
29 template<class Type>
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 
79 
80 private:
81 
82  bool hasNotifyHandler_;
83 };
84 
85 template<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 
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
bool hasNotifyHandler()
Returns TRUE is the notify handler has been set and FALSE otherwise.
Definition: notify.h:66
void set(const Type &obj)
Definition: notify.h:98
A data pipe with callback semantics.
Definition: notify.h:52
void setNotifyHandler(NotifyHandler< Type > *handler)
Definition: notify.h:86
The object which implements the callback function.
Definition: notify.h:30
Base class for all GbxUtilAcfr exceptions.
Definition: gbxutilacfr/exceptions.h:65
virtual void handleData(const Type &obj)=0
virtual void internalSet(const Type &obj)
Reimplement this function for non-standard types.
Definition: notify.h:108
Utility namespace (part of SICK-ACFR driver)
Definition: buffer.h:21
NotifyHandler< Type > * handler_
Interface to the object which is notified of incoming data.
Definition: notify.h:78
 

Generated for GearBox by  doxygen 1.4.5