VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
publisherList.h
Go to the documentation of this file.
1 /*********************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************************/
5 
6 #pragma once
7 
11 
13 
14 #include <map>
15 
17 template <typename Publisher>
19 {
20 public:
23 
26  {
27 
28  }
29 
32  {
33  clear();
34  }
35 
37  void tick()
38  {
39  typename std::map<std::string, Publisher*>::iterator iter=myPublishers.begin();
40  for(iter; iter!=myPublishers.end(); ++iter)
41  {
42  iter->second->tick();
43  }
44  }
45 
47  void add(Publisher* pub)
48  {
49  myPublishers[pub->globalId().string()] = pub;
50  typename std::list<DtPublisherListDelegate*>::iterator iter=myAddedDelegates.begin();
51  for(iter; iter!=myAddedDelegates.end(); ++iter)
52  {
53  (*(*iter))(pub);
54  }
55  }
57  void add(Publisher* pub, const std::string& id)
58  {
59  myPublishers[id] = pub;
60  typename std::list<DtPublisherListDelegate*>::iterator iter = myAddedDelegates.begin();
61  for (iter; iter != myAddedDelegates.end(); ++iter)
62  {
63  (*(*iter))(pub);
64  }
65  }
66 
68  void remove(Publisher* pub)
69  {
70  myPublishers.erase(pub->globalId().string());
71  typename std::list<DtPublisherListDelegate*>::iterator iter=myRemovedDelegates.begin();
72  for(iter; iter!=myRemovedDelegates.end(); ++iter)
73  {
74  DtPublisherListDelegate* del=(*iter);
75  (*del)(pub);
76  }
77  }
78 
80  void remove(const std::string& id)
81  {
82  Publisher* pub = myPublishers[id];
83  myPublishers.erase(id);
84  typename std::list<DtPublisherListDelegate*>::iterator iter = myRemovedDelegates.begin();
85  for (iter; iter != myRemovedDelegates.end(); ++iter)
86  {
87  DtPublisherListDelegate* del = (*iter);
88  (*del)(pub);
89  }
90  }
91 
93  Publisher* find(std::string id)
94  {
95  Publisher* result = NULL;
96  typename std::map<std::string, Publisher*>::iterator pubIter;
97  pubIter = myPublishers.find(id);
98  if (pubIter != myPublishers.end())
99  {
100  result = myPublishers[id];
101  }
102  return result;
103  }
104 
107  {
108  myAddedDelegates.push_back(del);
109  }
110 
113  {
114  myAddedDelegates.remove(del);
115  }
116 
119  {
120  myRemovedDelegates.push_back(del);
121  }
122 
125  {
126  myRemovedDelegates.remove(del);
127  }
128 
130  typename std::map< std::string, Publisher* >::iterator begin()
131  {
132  return myPublishers.begin();
133  }
134 
136  typename std::map< std::string, Publisher*>::iterator end()
137  {
138  return myPublishers.end();
139  }
140 
142  void clear()
143  {
144  typename std::map<std::string, Publisher*>::iterator iter=myPublishers.begin();
145  for(iter; iter!=myPublishers.end(); ++iter)
146  {
147  delete (iter->second);
148  }
149  myPublishers.clear();
150 
151  typename std::list<DtPublisherListDelegate*>::iterator iter2=myAddedDelegates.begin();
152  for(iter2; iter2!=myAddedDelegates.end(); ++iter2)
153  {
154  delete (*iter2);
155  }
156  myAddedDelegates.clear();
157 
158  typename std::list<DtPublisherListDelegate*>::iterator iter3=myRemovedDelegates.begin();
159  for(iter3; iter3!=myRemovedDelegates.end(); ++iter3)
160  {
161  delete (*iter3);
162  }
163  myRemovedDelegates.clear();
164  }
165 
166 protected:
167  typename std::map< std::string, Publisher*> myPublishers;
168  std::list<DtPublisherListDelegate*> myAddedDelegates;
169  std::list<DtPublisherListDelegate*> myRemovedDelegates;
170 };
std::map< std::string, Publisher * >::iterator end()
Get the end of the list for iteration.
Definition: publisherList.h:136
std::list< DtPublisherListDelegate * > myAddedDelegates
Definition: publisherList.h:168
std::map< std::string, Publisher * >::iterator begin()
Get the beginning of the list for iteration.
Definition: publisherList.h:130
Defines a single parameter delegate to make binding member function pointers easier.
void removePublisherRemovedDelegate(DtPublisherListDelegate *del)
remove a callback for when a publisher is removed from the list
Definition: publisherList.h:124
void removePublisherAddedDelegate(DtPublisherListDelegate *del)
remove a callback for when a publisher is added to the list
Definition: publisherList.h:112
void tick()
Ticks all of the publishers.
Definition: publisherList.h:37
void add(Publisher *pub)
add a publisher to the list
Definition: publisherList.h:47
std::map< std::string, Publisher * > myPublishers
Definition: publisherList.h:167
~DtPublisherList()
destructor
Definition: publisherList.h:31
DtPublisherList()
constructor
Definition: publisherList.h:25
DtDelegate< void, Publisher * > DtPublisherListDelegate
Defines a delegate that has a Publisher object pointer as a parameter and returns a void type...
Definition: publisherList.h:22
Publisher * find(std::string id)
find a particular object publisher in the list
Definition: publisherList.h:93
Defines the DtPublisherList template. The parameter is the VR-Link Publisher object class type...
Definition: publisherList.h:18
void addPublisherRemovedDelegate(DtPublisherListDelegate *del)
add a callback for when a publisher is removed from the list
Definition: publisherList.h:118
void addPublisherAddedDelegate(DtPublisherListDelegate *del)
add a callback for when a publisher is added to the list
Definition: publisherList.h:106
void add(Publisher *pub, const std::string &id)
add a publisher to the list with a specific identifier
Definition: publisherList.h:57
Delegate template for binding static or member functions for callback at later time The return type a...
Definition: delegate.h:69
void clear()
Clears the list and all delegates. This will release the memory used by the delegates or object publi...
Definition: publisherList.h:142
std::list< DtPublisherListDelegate * > myRemovedDelegates
Definition: publisherList.h:169

Document ID: Generated on Wed Mar 27 02:04:30 EDT 2024 from SVN revision 264570
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)