vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
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
// *** WARNING: This file must only be included in a .cpp or .C file, not
20
// in a .h file, because it includes <vector>, and we can't have any standard
21
// library files in the VRPN headers because that will make VRPN incompatible
22
// with libraries that use the other flavor of <vector.h>.
23
24
#pragma once
25
26
// Internal Includes
27
#include "
vrpn_MainloopObject.h
"
28
29
// Library/third-party includes
30
// - none
31
32
// Standard includes
33
#include <vector>
34
36
class
vrpn_MainloopContainer
{
37
public
:
39
vrpn_MainloopContainer
() {}
41
~vrpn_MainloopContainer
();
42
45
void
clear
();
46
50
vrpn_MainloopObject
*
add
(
vrpn_MainloopObject
*o);
51
55
template
<
class
T> T
add
(T o)
56
{
57
if
(!
add
(
vrpn_MainloopObject::wrap
(o))) {
58
return
NULL;
59
}
60
return
o;
61
}
62
65
void
mainloop
();
66
67
private
:
68
std::vector<vrpn_MainloopObject *> _vrpn;
69
};
70
71
/* -- inline implementations -- */
72
73
inline
vrpn_MainloopContainer::~vrpn_MainloopContainer
() {
clear
(); }
74
75
inline
vrpn_MainloopObject
*
vrpn_MainloopContainer::add
(
vrpn_MainloopObject
*o)
76
{
77
// If the object is NULL, we have a problem and don't add it.
78
if
(!o) {
79
return
o;
80
}
81
82
// If the object is broken(), this indicates a problem
83
// with the device. We also do not add it and we return NULL to show.
84
// that there is a problem.
85
if
(o->
broken
()) {
86
fprintf(
87
stderr,
88
"vrpn_MainloopContainer::add() Device is broken, not adding.\n"
);
89
return
NULL;
90
}
91
92
_vrpn.push_back(o);
93
return
o;
94
}
95
96
inline
void
vrpn_MainloopContainer::clear
()
97
{
98
if
(_vrpn.empty()) {
99
return
;
100
}
102
for
(
int
i =
int
(_vrpn.size()) - 1; i >= 0; --i) {
103
try
{
104
delete
_vrpn[i];
105
}
catch
(...) {
106
fprintf(stderr,
"vrpn_MainloopContainer::clear: delete failed\n"
);
107
return
;
108
}
109
_vrpn[i] = NULL;
110
}
111
_vrpn.clear();
112
}
113
114
inline
void
vrpn_MainloopContainer::mainloop
()
115
{
116
const
size_t
n = _vrpn.size();
117
for
(
size_t
i = 0; i < n; ++i) {
118
_vrpn[i]->mainloop();
119
}
120
}
vrpn_MainloopContainer::vrpn_MainloopContainer
vrpn_MainloopContainer()
Constructor.
Definition
vrpn_MainloopContainer.h:39
vrpn_MainloopContainer::add
vrpn_MainloopObject * add(vrpn_MainloopObject *o)
Add an object wrapped by vrpn_MainloopObject. Return NULL if the object has a problem (indicated by b...
Definition
vrpn_MainloopContainer.h:75
vrpn_MainloopContainer::add
T add(T o)
Template method to automatically wrap objects with vrpn_MainloopObject before adding them....
Definition
vrpn_MainloopContainer.h:55
vrpn_MainloopContainer::mainloop
void mainloop()
Runs mainloop on all contained objects, in the order that they were added.
Definition
vrpn_MainloopContainer.h:114
vrpn_MainloopContainer::clear
void clear()
Clear internal structure holding objects, deleting them in reverse order of their addition.
Definition
vrpn_MainloopContainer.h:96
vrpn_MainloopContainer::~vrpn_MainloopContainer
~vrpn_MainloopContainer()
Destructor: invokes clear().
Definition
vrpn_MainloopContainer.h:73
vrpn_MainloopObject
An interface for all VRPN objects that have a "mainloop" method. Not instantiated directly: use vrpn_...
Definition
vrpn_MainloopObject.h:43
vrpn_MainloopObject::broken
virtual bool broken()=0
Checks the connectionPtr() for the VRPN object to make sure it is not NULL.
vrpn_MainloopObject::wrap
static vrpn_MainloopObject * wrap(T o)
Templated wrapping function.
Definition
vrpn_MainloopObject.h:176
vrpn_MainloopObject.h
Header.
vrpn_MainloopContainer.h
Generated by
1.17.0