OpenCMISS-Zinc C++ API Documentation
timenotifier.hpp
Go to the documentation of this file.
1 
4 /* OpenCMISS-Zinc Library
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public
7 * License, v. 2.0. If a copy of the MPL was not distributed with this
8 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #ifndef CMZN_TIMENOTIFIER_HPP__
10 #define CMZN_TIMENOTIFIER_HPP__
11 
12 #include "opencmiss/zinc/timenotifier.h"
13 #include "opencmiss/zinc/timekeeper.hpp"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
27 {
28 protected:
29  cmzn_timenotifierevent_id id;
30 
31 public:
32 
33  Timenotifierevent() : id(0)
34  { }
35 
36  // takes ownership of C handle, responsibility for destroying it
37  explicit Timenotifierevent(cmzn_timenotifierevent_id in_timenotifier_event_id) :
38  id(in_timenotifier_event_id)
39  { }
40 
41  Timenotifierevent(const Timenotifierevent& timenotifierEvent) :
42  id(cmzn_timenotifierevent_access(timenotifierEvent.id))
43  { }
44 
45  Timenotifierevent& operator=(const Timenotifierevent& timenotifierEvent)
46  {
47  cmzn_timenotifierevent_id temp_id = cmzn_timenotifierevent_access(timenotifierEvent.id);
48  if (0 != id)
49  {
50  cmzn_timenotifierevent_destroy(&id);
51  }
52  id = temp_id;
53  return *this;
54  }
55 
57  {
58  if (0 != id)
59  {
60  cmzn_timenotifierevent_destroy(&id);
61  }
62  }
63 
69  bool isValid() const
70  {
71  return (0 != id);
72  }
73 
79  cmzn_timenotifierevent_id getId() const
80  {
81  return id;
82  }
83 
89  double getTime() const
90  {
91  return cmzn_timenotifierevent_get_time(id);
92  }
93 
94 };
95 
105 {
106 friend class Timenotifier;
107 private:
108  Timenotifiercallback(const Timenotifiercallback&); // not implemented
109  Timenotifiercallback& operator=(const Timenotifiercallback&); // not implemented
110 
111  static void C_callback(cmzn_timenotifierevent_id timenotifierevent_id, void *callbackVoid)
112  {
113  Timenotifierevent timenotifierevent(cmzn_timenotifierevent_access(timenotifierevent_id));
114  Timenotifiercallback *callback = reinterpret_cast<Timenotifiercallback *>(callbackVoid);
115  (*callback)(timenotifierevent);
116  }
117 
118  virtual void operator()(const Timenotifierevent &timenotifierevent) = 0;
119 
120 protected:
122  { }
123 
124 public:
125  virtual ~Timenotifiercallback()
126  { }
127 };
128 
129 class TimenotifierRegular;
130 
139 {
140 protected:
141  cmzn_timenotifier_id id;
142 
143 public:
144 
145  Timenotifier() : id(0)
146  { }
147 
148  // takes ownership of C handle, responsibility for destroying it
149  explicit Timenotifier(cmzn_timenotifier_id in_timenotifier_id) :
150  id(in_timenotifier_id)
151  { }
152 
153  Timenotifier(const Timenotifier& timenotifier) :
154  id(cmzn_timenotifier_access(timenotifier.id))
155  { }
156 
157  Timenotifier& operator=(const Timenotifier& timenotifier)
158  {
159  cmzn_timenotifier_id temp_id = cmzn_timenotifier_access(timenotifier.id);
160  if (0 != id)
161  {
162  cmzn_timenotifier_destroy(&id);
163  }
164  id = temp_id;
165  return *this;
166  }
167 
168  ~Timenotifier()
169  {
170  if (0 != id)
171  {
172  cmzn_timenotifier_destroy(&id);
173  }
174  }
175 
181  bool isValid() const
182  {
183  return (0 != id);
184  }
185 
191  cmzn_timenotifier_id getId() const
192  {
193  return id;
194  }
195 
201  double getTime()
202  {
203  return cmzn_timenotifier_get_time(id);
204  }
205 
217  {
218  return cmzn_timenotifier_set_callback(id, callback.C_callback, static_cast<void*>(&callback));
219  }
220 
229  {
230  return cmzn_timenotifier_clear_callback(id);
231  }
232 
244  {
245  return cmzn_timenotifier_get_next_callback_time(
246  id, static_cast<cmzn_timekeeper_play_direction>(playDirection));
247  }
248 
256  inline TimenotifierRegular castRegular();
257 };
258 
265 {
266 public:
267 
269  { }
270 
271  // takes ownership of C handle, responsibility for destroying it
272  explicit TimenotifierRegular(cmzn_timenotifier_regular_id timenotifier_regular_id) :
273  Timenotifier(reinterpret_cast<cmzn_timenotifier_id>(timenotifier_regular_id))
274  { }
275 
281  cmzn_timenotifier_regular_id getDerivedId()
282  {
283  return reinterpret_cast<cmzn_timenotifier_regular_id>(id);
284  }
285 
300  int setFrequency(double frequency)
301  {
302  return cmzn_timenotifier_regular_set_frequency(getDerivedId(), frequency);
303  }
304 
313  int setOffset(double timeOffset)
314  {
315  return cmzn_timenotifier_regular_set_offset(getDerivedId(), timeOffset);
316  }
317 
318 };
319 
321 {
322  return TimenotifierRegular(cmzn_timenotifier_cast_regular(id));
323 }
324 
325 inline TimenotifierRegular Timekeeper::createTimenotifierRegular(double updateFrequency, double timeOffset)
326 {
327  return TimenotifierRegular(reinterpret_cast<cmzn_timenotifier_regular_id>(
328  cmzn_timekeeper_create_timenotifier_regular(id, updateFrequency, timeOffset)));
329 }
330 
331 } // namespace Zinc
332 }
333 
334 #endif
int clearCallback()
Definition: timenotifier.hpp:228
double getTime()
Definition: timenotifier.hpp:201
TimenotifierRegular createTimenotifierRegular(double updateFrequency, double timeOffset)
Definition: timenotifier.hpp:325
int setOffset(double timeOffset)
Definition: timenotifier.hpp:313
cmzn_timenotifier_regular_id getDerivedId()
Definition: timenotifier.hpp:281
Information about changes to the timekeeper/time.
Definition: timenotifier.hpp:26
A derived timenotifier type which requests notifications at regular intervals.
Definition: timenotifier.hpp:264
TimenotifierRegular castRegular()
Definition: timenotifier.hpp:320
int setCallback(Timenotifiercallback &callback)
Definition: timenotifier.hpp:216
double getNextCallbackTime(enum Timekeeper::PlayDirection playDirection)
Definition: timenotifier.hpp:243
PlayDirection
Definition: timekeeper.hpp:84
double getTime() const
Definition: timenotifier.hpp:89
cmzn_timenotifierevent_id getId() const
Definition: timenotifier.hpp:79
cmzn_timenotifier_id getId() const
Definition: timenotifier.hpp:191
Base class functor for Timenotifier callbacks.
Definition: timenotifier.hpp:104
bool isValid() const
Definition: timenotifier.hpp:181
int setFrequency(double frequency)
Definition: timenotifier.hpp:300
The OpenCMISS namespace.
Definition: context.hpp:20
bool isValid() const
Definition: timenotifier.hpp:69
Description of timing requirements and for setting up time callbacks.
Definition: timenotifier.hpp:138