MeVisLab Toolbox Reference
macByteData.h
Go to the documentation of this file.
1 /*************************************************************************************
2 **
3 ** Copyright 2008, MeVis Medical Solutions AG
4 **
5 ** The user may use this file in accordance with the license agreement provided with
6 ** the Software or, alternatively, in accordance with the terms contained in a
7 ** written agreement between the user and MeVis Medical Solutions AG.
8 **
9 ** For further information use the contact form at https://www.mevislab.de/contact
10 **
11 **************************************************************************************/
12 
13 #ifndef MAC_BYTE_DATA_H
14 #define MAC_BYTE_DATA_H
15 
17 
18 #if defined(__APPLE__)
19 
21 #include <macSmartPtr.h>
22 #include <sys/types.h>
23 
24 namespace macos {
25 
28  {
29  public:
30 
32  ByteData() : _retainCount(0), _data(nullptr), _size(0) {}
33 
35  ByteData(size_t size) : _retainCount(0), _size(size) {
36  _data = new char[_size];
37  }
38 
40  inline char *data() {
41  return _data;
42  }
43 
45  inline const char *data() const {
46  return _data;
47  }
48 
50  inline size_t size() const {
51  return _size;
52  }
53 
55  inline void retain() {
56  if (_retainCount <= 0) {
57  // instance has reference count <= 0 already
58  }
59  _retainCount++;
60  }
61 
63  inline void release() {
64  if (--_retainCount == 0) {
65  destroy();
66  }
67  }
68 
69  private:
70 
73  }
74 
75  OSXSUPPORT_PRIVATE_API inline void destroy() {
76  delete [] _data;
77  delete this;
78  }
79 
80  OSXSUPPORT_PRIVATE_API int _retainCount;
81 
82  OSXSUPPORT_PRIVATE_API char *_data;
83  OSXSUPPORT_PRIVATE_API size_t _size;
84 
85  };
86 
89 
90 }
91 
92 #endif // __APPLE__
93 #endif // __macByteData_H
Byte data container with reference counting (Helper class)
Definition: macByteData.h:28
const char * data() const
get const pointer to data
Definition: macByteData.h:45
size_t size() const
get size of data
Definition: macByteData.h:50
void retain()
increase reference count
Definition: macByteData.h:55
void release()
decrease reference count, if reference count goes to 0, ByteData is released
Definition: macByteData.h:63
ByteData(size_t size)
C-tor.
Definition: macByteData.h:35
char * data()
get pointer to data
Definition: macByteData.h:40
ByteData()
C-tor.
Definition: macByteData.h:32
Smart pointer to reference counted object (Helper class)
Definition: macSmartPtr.h:28
#define OSXSUPPORT_PUBLIC_API
Symbol visibility macros.
#define OSXSUPPORT_PRIVATE_API
AppleScript support.
SmartPtr< ByteData > ByteDataPtr
Reference counted pointer to ByteData container.
Definition: macByteData.h:88
void destroy()
Delete dynamic data structures allocated by init().