~hitmuri/vjpirate/trunk

« back to all changes in this revision

Viewing changes to os/win/include/vrpn_MainloopContainer.h

  • Committer: Florent Berthaut
  • Date: 2014-07-26 18:53:16 UTC
  • mfrom: (5.1.12 mac)
  • Revision ID: flo@localhost.localdomain-20140726185316-c2ucnwmgm5kij4e2
Merged mac branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** @file
 
2
        @brief Header
 
3
 
 
4
        @date 2011
 
5
 
 
6
        @author
 
7
        Ryan Pavlik
 
8
        <rpavlik@iastate.edu> and <abiryan@ryand.net>
 
9
        http://academic.cleardefinition.com/
 
10
        Iowa State University Virtual Reality Applications Center
 
11
        Human-Computer Interaction Graduate Program
 
12
*/
 
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
#ifndef INCLUDED_vrpn_MainloopContainer_h_GUID_2146c66c_1925_4ac3_a192_354d10d7a39f
 
21
#define INCLUDED_vrpn_MainloopContainer_h_GUID_2146c66c_1925_4ac3_a192_354d10d7a39f
 
22
 
 
23
// Internal Includes
 
24
#include "vrpn_MainloopObject.h"
 
25
 
 
26
// Library/third-party includes
 
27
// - none
 
28
 
 
29
// Standard includes
 
30
#include <vector>
 
31
 
 
32
/// A container that holds and owns one or more VRPN objects,
 
33
class vrpn_MainloopContainer {
 
34
        public:
 
35
                /// Constructor
 
36
                vrpn_MainloopContainer() {}
 
37
                /// Destructor: invokes clear()
 
38
                ~vrpn_MainloopContainer();
 
39
 
 
40
                /// Clear internal structure holding objects, deleting them
 
41
                /// in reverse order of their addition.
 
42
                void clear();
 
43
 
 
44
                /// Add an object wrapped by vrpn_MainloopObject.
 
45
                void add(vrpn_MainloopObject * o);
 
46
 
 
47
                /// Template method to automatically wrap objects
 
48
                /// with vrpn_MainloopObject before adding them.
 
49
                template<class T>
 
50
                void add(T o) {
 
51
                        add(vrpn_MainloopObject::wrap(o));
 
52
                }
 
53
 
 
54
                /// Runs mainloop on all contained objects, in the order
 
55
                /// that they were added.
 
56
                void mainloop();
 
57
 
 
58
        private:
 
59
                std::vector<vrpn_MainloopObject *> _vrpn;
 
60
};
 
61
 
 
62
/* -- inline implementations -- */
 
63
 
 
64
inline vrpn_MainloopContainer::~vrpn_MainloopContainer() {
 
65
        clear();
 
66
}
 
67
 
 
68
inline void vrpn_MainloopContainer::add(vrpn_MainloopObject* o) {
 
69
        if (!o) {
 
70
                return;
 
71
        }
 
72
        _vrpn.push_back(o);
 
73
}
 
74
 
 
75
inline void vrpn_MainloopContainer::clear() {
 
76
        if (_vrpn.empty()) {
 
77
                return;
 
78
        }
 
79
        /// Delete in reverse order
 
80
        for (size_t i = _vrpn.size() - 1; i >= 0; --i) {
 
81
                delete _vrpn[i];
 
82
                _vrpn[i] = NULL;
 
83
        }
 
84
        _vrpn.clear();
 
85
}
 
86
 
 
87
inline void vrpn_MainloopContainer::mainloop() {
 
88
        const size_t n = _vrpn.size();
 
89
        for (size_t i = 0; i < n; ++i) {
 
90
                _vrpn[i]->mainloop();
 
91
        }
 
92
}
 
93
 
 
94
#endif // INCLUDED_vrpn_MainloopContainer_h_GUID_2146c66c_1925_4ac3_a192_354d10d7a39f