OpenCMISS-Zinc C++ API Documentation
timekeeper.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_TIMEKEEPER_HPP__
10 #define CMZN_TIMEKEEPER_HPP__
11 
12 #include "opencmiss/zinc/timekeeper.h"
13 #include "opencmiss/zinc/context.hpp"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
20 class Timenotifier;
21 class TimenotifierRegular;
22 
42 {
43 protected:
44  cmzn_timekeeper_id id;
45 
46 public:
47 
48  Timekeeper() : id(0)
49  { }
50 
51  // takes ownership of C handle, responsibility for destroying it
52  explicit Timekeeper(cmzn_timekeeper_id in_timekeeper_id) :
53  id(in_timekeeper_id)
54  { }
55 
56  Timekeeper(const Timekeeper& timeKeeper) :
57  id(cmzn_timekeeper_access(timeKeeper.id))
58  { }
59 
60  Timekeeper& operator=(const Timekeeper& timeKeeper)
61  {
62  cmzn_timekeeper_id temp_id = cmzn_timekeeper_access(timeKeeper.id);
63  if (0 != id)
64  {
65  cmzn_timekeeper_destroy(&id);
66  }
67  id = temp_id;
68  return *this;
69  }
70 
71  ~Timekeeper()
72  {
73  if (0 != id)
74  {
75  cmzn_timekeeper_destroy(&id);
76  }
77  }
78 
85  {
86  PLAY_DIRECTION_INVALID = CMZN_TIMEKEEPER_PLAY_DIRECTION_INVALID,
88  PLAY_DIRECTION_FORWARD = CMZN_TIMEKEEPER_PLAY_DIRECTION_FORWARD,
90  PLAY_DIRECTION_REVERSE = CMZN_TIMEKEEPER_PLAY_DIRECTION_REVERSE
92  };
93 
99  bool isValid() const
100  {
101  return (0 != id);
102  }
103 
109  cmzn_timekeeper_id getId() const
110  {
111  return id;
112  }
113 
126  inline TimenotifierRegular createTimenotifierRegular(double updateFrequency, double timeOffset);
127 
133  double getMaximumTime()
134  {
135  return cmzn_timekeeper_get_maximum_time(id);
136  }
137 
145  int setMaximumTime(double maximumTime)
146  {
147  return cmzn_timekeeper_set_maximum_time(id, maximumTime);
148  }
149 
155  double getMinimumTime()
156  {
157  return cmzn_timekeeper_get_minimum_time(id);
158  }
159 
167  int setMinimumTime(double minimumTime)
168  {
169  return cmzn_timekeeper_set_minimum_time(id, minimumTime);
170  }
171 
177  double getTime()
178  {
179  return cmzn_timekeeper_get_time(id);
180  }
181 
189  int setTime(double time)
190  {
191  return cmzn_timekeeper_set_time(id, time);
192  }
193 
209  double getNextCallbackTime(enum PlayDirection playDirection)
210  {
211  return cmzn_timekeeper_get_next_callback_time(id,
212  static_cast<cmzn_timekeeper_play_direction>(playDirection));
213  }
214 
215 };
216 
223 {
224 protected:
225  cmzn_timekeepermodule_id id;
226 
227 public:
228 
229  Timekeepermodule() : id(0)
230  { }
231 
232  // takes ownership of C handle, responsibility for destroying it
233  explicit Timekeepermodule(cmzn_timekeepermodule_id in_timekeepermodule_id) :
234  id(in_timekeepermodule_id)
235  { }
236 
237  Timekeepermodule(const Timekeepermodule& timekeeperModule) :
238  id(cmzn_timekeepermodule_access(timekeeperModule.id))
239  { }
240 
241  Timekeepermodule& operator=(const Timekeepermodule& timekeeperModule)
242  {
243  cmzn_timekeepermodule_id temp_id = cmzn_timekeepermodule_access(
244  timekeeperModule.id);
245  if (0 != id)
246  cmzn_timekeepermodule_destroy(&id);
247  id = temp_id;
248  return *this;
249  }
250 
252  {
253  if (0 != id)
254  cmzn_timekeepermodule_destroy(&id);
255  }
256 
262  bool isValid() const
263  {
264  return (0 != id);
265  }
266 
272  cmzn_timekeepermodule_id getId() const
273  {
274  return id;
275  }
276 
283  {
284  return Timekeeper(cmzn_timekeepermodule_get_default_timekeeper(id));
285  }
286 
294  int readDescription(const char *description)
295  {
296  return cmzn_timekeepermodule_read_description(this->id, description);
297  }
298 
307  {
308  return cmzn_timekeepermodule_write_description(this->id);
309  }
310 
311 };
312 
314 {
315  return Timekeepermodule(cmzn_context_get_timekeepermodule(id));
316 }
317 
318 } // namespace Zinc
319 }
320 
321 #endif
TimenotifierRegular createTimenotifierRegular(double updateFrequency, double timeOffset)
Definition: timenotifier.hpp:325
double getMaximumTime()
Definition: timekeeper.hpp:133
int setMaximumTime(double maximumTime)
Definition: timekeeper.hpp:145
cmzn_timekeeper_id getId() const
Definition: timekeeper.hpp:109
A derived timenotifier type which requests notifications at regular intervals.
Definition: timenotifier.hpp:264
double getTime()
Definition: timekeeper.hpp:177
The timekeeper synchronises a current time across Zinc objects.
Definition: timekeeper.hpp:41
PlayDirection
Definition: timekeeper.hpp:84
bool isValid() const
Definition: timekeeper.hpp:262
double getNextCallbackTime(enum PlayDirection playDirection)
Definition: timekeeper.hpp:209
int setMinimumTime(double minimumTime)
Definition: timekeeper.hpp:167
Timekeepermodule getTimekeepermodule()
Definition: timekeeper.hpp:313
char * writeDescription()
Definition: timekeeper.hpp:306
int readDescription(const char *description)
Definition: timekeeper.hpp:294
int setTime(double time)
Definition: timekeeper.hpp:189
Module for finding and managing timekeepers.
Definition: timekeeper.hpp:222
The OpenCMISS namespace.
Definition: context.hpp:20
double getMinimumTime()
Definition: timekeeper.hpp:155
cmzn_timekeepermodule_id getId() const
Definition: timekeeper.hpp:272
Timekeeper getDefaultTimekeeper()
Definition: timekeeper.hpp:282
bool isValid() const
Definition: timekeeper.hpp:99