OpenCMISS-Zinc C++ API Documentation
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Pages
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 "zinc/timenotifier.h"
13 #include "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 
233  double getNextCallbackTime(enum Timekeeper::PlayDirection playDirection)
234  {
235  return cmzn_timenotifier_get_next_callback_time(
236  id, static_cast<cmzn_timekeeper_play_direction>(playDirection));
237  }
238 
246  inline TimenotifierRegular castRegular();
247 };
248 
255 {
256 public:
257 
259  { }
260 
261  // takes ownership of C handle, responsibility for destroying it
262  explicit TimenotifierRegular(cmzn_timenotifier_regular_id timenotifier_regular_id) :
263  Timenotifier(reinterpret_cast<cmzn_timenotifier_id>(timenotifier_regular_id))
264  { }
265 
271  cmzn_timenotifier_regular_id getDerivedId()
272  {
273  return reinterpret_cast<cmzn_timenotifier_regular_id>(id);
274  }
275 
290  int setFrequency(double frequency)
291  {
292  return cmzn_timenotifier_regular_set_frequency(getDerivedId(), frequency);
293  }
294 
303  int setOffset(double timeOffset)
304  {
305  return cmzn_timenotifier_regular_set_offset(getDerivedId(), timeOffset);
306  }
307 
308 };
309 
311 {
312  return TimenotifierRegular(cmzn_timenotifier_cast_regular(id));
313 }
314 
315 inline TimenotifierRegular Timekeeper::createTimenotifierRegular(double updateFrequency, double timeOffset)
316 {
317  return TimenotifierRegular(reinterpret_cast<cmzn_timenotifier_regular_id>(
318  cmzn_timekeeper_create_timenotifier_regular(id, updateFrequency, timeOffset)));
319 }
320 
321 } // namespace Zinc
322 }
323 
324 #endif
int clearCallback()
Definition: timenotifier.hpp:228
double getTime()
Definition: timenotifier.hpp:201
TimenotifierRegular createTimenotifierRegular(double updateFrequency, double timeOffset)
Definition: timenotifier.hpp:315
int setOffset(double timeOffset)
Definition: timenotifier.hpp:303
cmzn_timenotifier_regular_id getDerivedId()
Definition: timenotifier.hpp:271
Information about changes to the timekeeper/time.
Definition: timenotifier.hpp:26
A derived timenotifier type which requests notifications at regular intervals.
Definition: timenotifier.hpp:254
TimenotifierRegular castRegular()
Definition: timenotifier.hpp:310
int setCallback(Timenotifiercallback &callback)
Definition: timenotifier.hpp:216
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:290
bool isValid() const
Definition: timenotifier.hpp:69
Description of timing requirements and for setting up time callbacks.
Definition: timenotifier.hpp:138