MAK Data Logger API Documentation for HLA
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
observe.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #ifndef observe_H_
11 #define observe_H_
12 
13 #include "observeConnection.h"
14 #include <lgrUtil/observeEvent.h>
15 
16 namespace MAKLogger
17 {
18 
21  template <typename SubjectType>
23  {
24  public:
25 
27  virtual ~DtObserver()
28  {
29  disconnectAll();
30  }
31 
34  {
35  DtObserveConnectionSP sharedCon = findEventObserverConnection(event,this);
36  if(sharedCon)
37  {
38  sharedCon->disconnect(sharedCon);
39  }
40  }
41 
43  virtual void observe(const SubjectType&) = 0;
44  };
45 
46 
50  template <typename SubjectType>
51  class DtObserverCallback : public DtObserver<SubjectType>
52  {
53  public:
54 
55  typedef void (*ObserverFunction)(const SubjectType&,void*);
56 
57  DtObserverCallback(ObserverFunction function,void* userData) :
58  myFunction(function),
59  myData(userData)
60  {
61  }
62 
63  virtual ~DtObserverCallback(){}
64 
65  void observe(const SubjectType& subject)
66  {
67  (*myFunction)(subject,myData);
68  }
69 
70  protected:
71 
76 
77 
79  void* myData;
80  };
81 
91  template <typename ClassType,typename SubjectType>
92  class DtObserverFunctor : public DtObserver<SubjectType>
93  {
94  public:
95 
96  typedef void (ClassType::*ObserverMemberFunction)(const SubjectType&);
97 
98  DtObserverFunctor(ClassType& object,ObserverMemberFunction function) :
99  myObject(object),
100  myFunction(function)
101  {
102  }
103 
104  virtual ~DtObserverFunctor(){}
105 
106  void observe(const SubjectType& subject)
107  {
108  (myObject.*myFunction)(subject);
109  }
110 
111  protected:
112 
117 
118  ClassType& myObject;
120  };
121 }
122 
123 #endif

Document ID: Generated on Thu Apr 7 20:50:59 EDT 2016 from SVN revision 163818
Copyright © 2005-2012 VT MÄK. All Rights Reserved (www.mak.com)