OpenCMISS-Zinc C++ API Documentation
logger.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_LOGGER_HPP__
10 #define CMZN_LOGGER_HPP__
11 
12 #include "opencmiss/zinc/logger.h"
13 #include "opencmiss/zinc/context.hpp"
14 
15 namespace OpenCMISS
16 {
17 namespace Zinc
18 {
19 
20 class Loggernotifier;
21 
28 class Logger
29 {
30 protected:
31  cmzn_logger_id id;
32 
33 public:
34 
35  Logger() : id(0)
36  { }
37 
38  // takes ownership of C handle, responsibility for destroying it
39  explicit Logger(cmzn_logger_id in_logger_id) :
40  id(in_logger_id)
41  { }
42 
43  Logger(const Logger& logger) :
44  id(cmzn_logger_access(logger.id))
45  { }
46 
47  Logger& operator=(const Logger& logger)
48  {
49  cmzn_logger_id temp_id = cmzn_logger_access(logger.id);
50  if (0 != id)
51  {
52  cmzn_logger_destroy(&id);
53  }
54  id = temp_id;
55  return *this;
56  }
57 
58  ~Logger()
59  {
60  if (0 != id)
61  {
62  cmzn_logger_destroy(&id);
63  }
64  }
65 
67  {
68  CHANGE_FLAG_NONE = CMZN_LOGGER_CHANGE_FLAG_NONE,
70  CHANGE_FLAG_NEW_MESSAGE = CMZN_LOGGER_CHANGE_FLAG_NEW_MESSAGE,
72  CHANGE_FLAG_FINAL = CMZN_LOGGER_CHANGE_FLAG_FINAL
74  };
75 
80  {
81  MESSAGE_TYPE_INVALID = CMZN_LOGGER_MESSAGE_TYPE_INVALID,
83  MESSAGE_TYPE_ERROR = CMZN_LOGGER_MESSAGE_TYPE_ERROR,
85  MESSAGE_TYPE_WARNING = CMZN_LOGGER_MESSAGE_TYPE_WARNING,
87  MESSAGE_TYPE_INFORMATION = CMZN_LOGGER_MESSAGE_TYPE_INFORMATION
89  };
90 
95  typedef int ChangeFlags;
96 
102  bool isValid() const
103  {
104  return (0 != id);
105  }
106 
112  cmzn_logger_id getId() const
113  {
114  return id;
115  }
116 
123  {
124  return cmzn_logger_get_number_of_messages(id);
125  }
126 
137  {
138  return static_cast<MessageType>(cmzn_logger_get_message_type_at_index(
139  id, index));
140  }
141 
149  char *getMessageTextAtIndex(int index)
150  {
151  return cmzn_logger_get_message_text_at_index(id, index);
152  }
153 
162  {
163  return cmzn_logger_set_maximum_number_of_messages(id, number);
164  }
165 
172  {
173  return cmzn_logger_remove_all_messages(id);
174  }
175 
183 
184 };
185 
186 inline bool operator==(const Logger& a, const Logger& b)
187 {
188  return a.getId() == b.getId();
189 }
190 
198 {
199 protected:
200  cmzn_loggerevent_id id;
201 
202 public:
203 
204  Loggerevent() : id(0)
205  { }
206 
207  // takes ownership of C handle, responsibility for destroying it
208  explicit Loggerevent(cmzn_loggerevent_id in_logger_event_id) :
209  id(in_logger_event_id)
210  { }
211 
212  Loggerevent(const Loggerevent& loggerEvent) :
213  id(cmzn_loggerevent_access(loggerEvent.id))
214  { }
215 
216  Loggerevent& operator=(const Loggerevent& loggerEvent)
217  {
218  cmzn_loggerevent_id temp_id = cmzn_loggerevent_access(loggerEvent.id);
219  if (0 != id)
220  cmzn_loggerevent_destroy(&id);
221  id = temp_id;
222  return *this;
223  }
224 
225  ~Loggerevent()
226  {
227  if (0 != id)
228  {
229  cmzn_loggerevent_destroy(&id);
230  }
231  }
232 
238  bool isValid() const
239  {
240  return (0 != id);
241  }
242 
248  cmzn_loggerevent_id getId() const
249  {
250  return id;
251  }
252 
263  {
264  return cmzn_loggerevent_get_change_flags(id);
265  }
266 
274  {
275  return static_cast<Logger::MessageType>(cmzn_loggerevent_get_message_type(id));
276  }
277 
284  char *getMessageText() const
285  {
286  return cmzn_loggerevent_get_message_text(id);
287  }
288 
295  {
296  return Logger(cmzn_loggerevent_get_logger(id));
297  }
298 
299 };
300 
310 {
311 friend class Loggernotifier;
312 private:
313  Loggercallback(const Loggercallback&); // not implemented
314  Loggercallback& operator=(const Loggercallback&); // not implemented
315 
316  static void C_callback(cmzn_loggerevent_id loggerevent_id, void *callbackVoid)
317  {
318  Loggerevent loggerevent(cmzn_loggerevent_access(loggerevent_id));
319  Loggercallback *callback = reinterpret_cast<Loggercallback *>(callbackVoid);
320  (*callback)(loggerevent);
321  }
322 
323  virtual void operator()(const Loggerevent &loggerevent) = 0;
324 
325 protected:
327  { }
328 
329 public:
330  virtual ~Loggercallback()
331  { }
332 };
333 
340 {
341 protected:
342  cmzn_loggernotifier_id id;
343 
344 public:
345 
346  Loggernotifier() : id(0)
347  { }
348 
349  // takes ownership of C handle, responsibility for destroying it
350  explicit Loggernotifier(cmzn_loggernotifier_id in_loggernotifier_id) :
351  id(in_loggernotifier_id)
352  { }
353 
354  Loggernotifier(const Loggernotifier& loggerNotifier) :
355  id(cmzn_loggernotifier_access(loggerNotifier.id))
356  { }
357 
358  Loggernotifier& operator=(const Loggernotifier& loggerNotifier)
359  {
360  cmzn_loggernotifier_id temp_id = cmzn_loggernotifier_access(loggerNotifier.id);
361  if (0 != id)
362  {
363  cmzn_loggernotifier_destroy(&id);
364  }
365  id = temp_id;
366  return *this;
367  }
368 
369  ~Loggernotifier()
370  {
371  if (0 != id)
372  {
373  cmzn_loggernotifier_destroy(&id);
374  }
375  }
376 
382  bool isValid() const
383  {
384  return (0 != id);
385  }
386 
392  cmzn_loggernotifier_id getId() const
393  {
394  return id;
395  }
396 
408  {
409  return cmzn_loggernotifier_set_callback(id, callback.C_callback, static_cast<void*>(&callback));
410  }
411 
419  {
420  return cmzn_loggernotifier_clear_callback(id);
421  }
422 };
423 
425 {
426  return Loggernotifier(cmzn_logger_create_loggernotifier(id));
427 }
428 
430 {
431  return Logger(cmzn_context_get_logger(id));
432 }
433 
434 } // namespace Zinc
435 }
436 
437 #endif
int removeAllMessages()
Definition: logger.hpp:171
int setMaximumNumberOfMessages(int number)
Definition: logger.hpp:161
bool isValid() const
Definition: logger.hpp:382
char * getMessageText() const
Definition: logger.hpp:284
bool isValid() const
Definition: logger.hpp:238
int setCallback(Loggercallback &callback)
Definition: logger.hpp:407
cmzn_logger_id getId() const
Definition: logger.hpp:112
int clearCallback()
Definition: logger.hpp:418
Logger::MessageType getMessageType() const
Definition: logger.hpp:273
ChangeFlag
Definition: logger.hpp:66
Font object controlling attributes of rendering text.
Definition: logger.hpp:28
char * getMessageTextAtIndex(int index)
Definition: logger.hpp:149
Base class functor for logger notifier callbacks.
Definition: logger.hpp:309
cmzn_loggerevent_id getId() const
Definition: logger.hpp:248
int ChangeFlags
Definition: logger.hpp:95
Logger::ChangeFlags getChangeFlags() const
Definition: logger.hpp:262
cmzn_loggernotifier_id getId() const
Definition: logger.hpp:392
MessageType
Definition: logger.hpp:79
Manages individual user notification of changes with a logger.
Definition: logger.hpp:339
Information about changes to messages in the logger.
Definition: logger.hpp:197
int getNumberOfMessages()
Definition: logger.hpp:122
Loggernotifier createLoggernotifier()
Definition: logger.hpp:424
The OpenCMISS namespace.
Definition: context.hpp:20
bool isValid() const
Definition: logger.hpp:102
MessageType getMessageTypeAtIndex(int index)
Definition: logger.hpp:136
Logger getLogger() const
Definition: logger.hpp:294
Logger getLogger()
Definition: logger.hpp:429