cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | // This may look like C code, but it is really -*- C++ -*- |
| 2 | // |
| 3 | // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004 |
| 4 | // |
| 5 | // Implementation of Blob |
| 6 | // |
| 7 | |
| 8 | #define MAGICKCORE_IMPLEMENTATION 1 |
| 9 | #define MAGICK_PLUSPLUS_IMPLEMENTATION 1 |
| 10 | |
| 11 | #include "Magick++/Include.h" |
| 12 | #include "Magick++/Thread.h" |
| 13 | #include "Magick++/BlobRef.h" |
| 14 | |
| 15 | #include <string.h> |
| 16 | |
| 17 | // |
| 18 | // Implementation of Magick::BlobRef |
| 19 | // |
| 20 | |
| 21 | // Construct with data, making private copy of data |
| 22 | Magick::BlobRef::BlobRef ( const void* data_, |
| 23 | size_t length_ ) |
| 24 | : _data(0), |
| 25 | _length(length_), |
| 26 | _allocator(Magick::Blob::NewAllocator), |
| 27 | _refCount(1), |
| 28 | _mutexLock() |
| 29 | { |
| 30 | if( data_ ) |
| 31 | { |
| 32 | _data = new unsigned char[length_]; |
| 33 | memcpy( _data, data_, length_ ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // Destructor (actually destroys data) |
| 38 | Magick::BlobRef::~BlobRef ( void ) |
| 39 | { |
| 40 | if ( _allocator == Magick::Blob::NewAllocator ) |
| 41 | { |
| 42 | delete [] static_cast<unsigned char*>(_data); |
| 43 | _data=0; |
| 44 | } |
| 45 | else if ( _allocator == Magick::Blob::MallocAllocator ) |
| 46 | { |
| 47 | _data=(void *) RelinquishMagickMemory(_data); |
| 48 | } |
| 49 | } |