Magick++ 7.0.10

BlobRef.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
4 // Copyright Dirk Lemstra 2014-2015
5 //
6 // Implementation of Blob
7 //
8
9 #define MAGICKCORE_IMPLEMENTATION 1
10 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
11
12 #include "Magick++/Include.h"
13 #include "Magick++/BlobRef.h"
14 #include "Magick++/Exception.h"
15 #include "Magick++/Thread.h"
16
17 #include <string.h>
18
19 Magick::BlobRef::BlobRef(const void* data_,const size_t length_)
20 : allocator(Magick::Blob::NewAllocator),
21 length(length_),
22 data((void*) NULL),
23 _mutexLock(),
24 _refCount(1)
25 {
26 if (data_ != (const void*) NULL)
27 {
28 data=new unsigned char[length_];
29 memcpy(data,data_,length_);
30 }
31 }
32
33 Magick::BlobRef::~BlobRef(void)
34 {
35 if (allocator == Magick::Blob::NewAllocator)
36 {
37 delete[] static_cast<unsigned char*>(data);
38 data=(void *) NULL;
39 }
40 else if (allocator == Magick::Blob::MallocAllocator)
41 data=(void *) RelinquishMagickMemory(data);
42 }
43
44 size_t Magick::BlobRef::decrease()
45 {
46 size_t
47 count;
48
49 _mutexLock.lock();
50 if (_refCount == 0)
51 {
52 _mutexLock.unlock();
53 throwExceptionExplicit(MagickCore::OptionError,
54 "Invalid call to decrease");
55 return(0);
56 }
57 count=--_refCount;
58 _mutexLock.unlock();
59 return(count);
60 }
61
62 void Magick::BlobRef::increase()
63 {
64 _mutexLock.lock();
65 _refCount++;
66 _mutexLock.unlock();
67 }
BlobRef.h
Magick::Blob::MallocAllocator
Definition: Blob.h:26
Magick::BlobRef::BlobRef
BlobRef(const void *data_, const size_t length_)
Definition: BlobRef.cpp:19
Magick::BlobRef::data
void * data
Definition: BlobRef.h:39
Thread.h
Magick::Blob
Definition: Blob.h:20
Magick::BlobRef::increase
void increase()
Definition: BlobRef.cpp:62
Magick::throwExceptionExplicit
MagickPPExport void throwExceptionExplicit(const MagickCore::ExceptionType severity_, const char *reason_, const char *description_=(char *) NULL)
Definition: Exception.cpp:806
Magick::BlobRef::decrease
size_t decrease()
Definition: BlobRef.cpp:44
Include.h
Magick::Blob::NewAllocator
Definition: Blob.h:27
Magick
Definition: Blob.h:15
Exception.h
Magick::BlobRef::~BlobRef
~BlobRef(void)
Definition: BlobRef.cpp:33