Magick++ 7.1.0

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 //
5 // Copyright @ 2014 ImageMagick Studio LLC, a non-profit organization
6 // dedicated to making software imaging solutions freely available.
7 //
8 // Implementation of Blob
9 //
10
11 #define MAGICKCORE_IMPLEMENTATION 1
12 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
13
14 #include "Magick++/Include.h"
15 #include "Magick++/BlobRef.h"
16 #include "Magick++/Exception.h"
17 #include "Magick++/Thread.h"
18
19 #include <string.h>
20
21 Magick::BlobRef::BlobRef(const void* data_,const size_t length_)
22 : allocator(Magick::Blob::NewAllocator),
23 length(length_),
24 data((void*) NULL),
25 _mutexLock(),
26 _refCount(1)
27 {
28 if (data_ != (const void*) NULL)
29 {
30 data=new unsigned char[length_];
31 memcpy(data,data_,length_);
32 }
33 }
34
35 Magick::BlobRef::~BlobRef(void)
36 {
37 if (allocator == Magick::Blob::NewAllocator)
38 {
39 delete[] static_cast<unsigned char*>(data);
40 data=(void *) NULL;
41 }
42 else if (allocator == Magick::Blob::MallocAllocator)
43 data=(void *) RelinquishMagickMemory(data);
44 }
45
46 size_t Magick::BlobRef::decrease()
47 {
48 size_t
49 count;
50
51 _mutexLock.lock();
52 if (_refCount == 0)
53 {
54 _mutexLock.unlock();
55 throwExceptionExplicit(MagickCore::OptionError,
56 "Invalid call to decrease");
57 return(0);
58 }
59 count=--_refCount;
60 _mutexLock.unlock();
61 return(count);
62 }
63
64 void Magick::BlobRef::increase()
65 {
66 _mutexLock.lock();
67 _refCount++;
68 _mutexLock.unlock();
69 }
BlobRef.h
Magick::Blob::MallocAllocator
Definition: Blob.h:28
Magick::BlobRef::BlobRef
BlobRef(const void *data_, const size_t length_)
Definition: BlobRef.cpp:21
Magick::BlobRef::data
void * data
Definition: BlobRef.h:41
Thread.h
Magick::Blob
Definition: Blob.h:22
Magick::BlobRef::increase
void increase()
Definition: BlobRef.cpp:64
Magick::throwExceptionExplicit
MagickPPExport void throwExceptionExplicit(const MagickCore::ExceptionType severity_, const char *reason_, const char *description_=(char *) NULL)
Definition: Exception.cpp:808
Magick::BlobRef::decrease
size_t decrease()
Definition: BlobRef.cpp:46
Include.h
Magick::Blob::NewAllocator
Definition: Blob.h:29
Magick
Definition: Blob.h:17
Exception.h
Magick::BlobRef::~BlobRef
~BlobRef(void)
Definition: BlobRef.cpp:35