MeVisLabToolboxReference
MeVis/Foundation/Sources/OSXSupport/macByteData.h
Go to the documentation of this file.
00001 // **InsertLicense** code author="Felix Ritter" version="1.0"
00002 
00006 
00007 #ifndef __macByteData_H
00008 #define __macByteData_H
00009 #if defined(__APPLE__)
00010 
00011 #include "macSmartPtr.h"
00012 #include <sys/types.h>
00013 
00014 namespace macx {
00015   
00017   class ByteData
00018   {
00019   public:
00020     
00022     ByteData() : _retainCount(0), _data(NULL), _size(0) {}
00023     
00025     ByteData(size_t size) : _retainCount(0), _size(size) {
00026       _data = new char[_size];
00027     }
00028     
00030     inline char *data() {
00031       return _data;
00032     }
00033     
00035     inline const char *data() const {
00036       return _data;
00037     }
00038     
00040     inline size_t size() const {
00041       return _size;
00042     }
00043     
00045     inline void retain() {
00046       if (_retainCount <= 0) {
00047         // instance has reference count <= 0 already
00048       }
00049       _retainCount++;
00050     }
00051     
00053     inline void release() {
00054       if (--_retainCount == 0) {
00055         destroy();
00056       }
00057     }
00058     
00059   private:
00060     
00062     ~ByteData() {
00063     }
00064     
00065     inline void destroy() {
00066       delete [] _data;
00067       delete this;
00068     }
00069     
00070     int _retainCount;
00071     
00072     char   *_data;
00073     size_t  _size;
00074     
00075   };
00076   
00078   typedef SmartPtr<ByteData> ByteDataPtr;
00079 
00080 }
00081 
00082 #endif  // __APPLE__
00083 #endif  // __macByteData_H