BlobRef.cpp
Go to the documentation of this file.
// This may look like C code, but it is really -*- C++ -*-
//
// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002, 2004
//
// Copyright @ 2014 ImageMagick Studio LLC, a non-profit organization
// dedicated to making software imaging solutions freely available.
//
// Implementation of Blob
//
#define MAGICKCORE_IMPLEMENTATION 1
#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
#include "Magick++/Include.h"
#include "Magick++/BlobRef.h"
#include "Magick++/Exception.h"
#include "Magick++/Thread.h"
#include <string.h>
Magick::BlobRef::BlobRef(const void* data_,const size_t length_)
: allocator(Magick::Blob::NewAllocator),
length(length_),
data((void*) NULL),
_mutexLock(),
_refCount(1)
{
if (data_ != (const void*) NULL)
{
data=new unsigned char[length_];
memcpy(data,data_,length_);
}
}
Magick::BlobRef::~BlobRef(void)
{
if (allocator == Magick::Blob::NewAllocator)
{
delete[] static_cast<unsigned char*>(data);
data=(void *) NULL;
}
else if (allocator == Magick::Blob::MallocAllocator)
data=(void *) RelinquishMagickMemory(data);
}
size_t Magick::BlobRef::decrease()
{
size_t
count;
_mutexLock.lock();
if (_refCount == 0)
{
_mutexLock.unlock();
throwExceptionExplicit(MagickCore::OptionError,
"Invalid call to decrease");
return(0);
}
count=--_refCount;
_mutexLock.unlock();
return(count);
}
void Magick::BlobRef::increase()
{
_mutexLock.lock();
_refCount++;
_mutexLock.unlock();
}
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