vrpn 07.36
Virtual Reality Peripheral Network
Loading...
Searching...
No Matches
vrpn_MainloopContainer.h
Go to the documentation of this file.
1
13
14// Copyright Iowa State University 2011.
15// Distributed under the Boost Software License, Version 1.0.
16// (See accompanying file LICENSE_1_0.txt or copy at
17// http://www.boost.org/LICENSE_1_0.txt)
18
19#pragma once
20
21// Internal Includes
22#include "vrpn_MainloopObject.h"
23
24// Library/third-party includes
25// - none
26
29public:
34
37 void clear();
38
43
47 template <class T> T add(T o)
48 {
50 return NULL;
51 }
52 return o;
53 }
54
57 void mainloop();
58
59private:
61};
62
63/* -- inline implementations -- */
64
66
68{
69 // If the object is NULL, we have a problem and don't add it.
70 if (!o) {
71 return o;
72 }
73
74 // If the object is broken(), this indicates a problem
75 // with the device. We also do not add it and we return NULL to show.
76 // that there is a problem.
77 if (o->broken()) {
78 fprintf(
79 stderr,
80 "vrpn_MainloopContainer::add() Device is broken, not adding.\n");
81 return NULL;
82 }
83
84 _vrpn.push_back(o);
85 return o;
86}
87
89{
90 if (_vrpn.empty()) {
91 return;
92 }
94 for (int i = int(_vrpn.size()) - 1; i >= 0; --i) {
95 try {
96 delete _vrpn[i];
97 } catch (...) {
98 fprintf(stderr, "vrpn_MainloopContainer::clear: delete failed\n");
99 return;
100 }
101 _vrpn[i] = NULL;
102 }
103 _vrpn.clear();
104}
105
107{
108 const size_t n = _vrpn.size();
109 for (size_t i = 0; i < n; ++i) {
110 _vrpn[i]->mainloop();
111 }
112}
vrpn_MainloopObject * add(vrpn_MainloopObject *o)
Add an object wrapped by vrpn_MainloopObject. Return NULL if the object has a problem (indicated by b...
T add(T o)
Template method to automatically wrap objects with vrpn_MainloopObject before adding them....
void mainloop()
Runs mainloop on all contained objects, in the order that they were added.
void clear()
Clear internal structure holding objects, deleting them in reverse order of their addition.
~vrpn_MainloopContainer()
Destructor: invokes clear()
An interface for all VRPN objects that have a "mainloop" method. Not instantiated directly: use vrpn_...
virtual bool broken()=0
Checks the connectionPtr() for the VRPN object to make sure it is not NULL.
static vrpn_MainloopObject * wrap(T o)
Templated wrapping function.