~ubuntu-branches/ubuntu/intrepid/graphicsmagick/intrepid

« back to all changes in this revision

Viewing changes to Magick++/lib/BlobRef.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2006-05-06 16:28:08 UTC
  • Revision ID: james.westby@ubuntu.com-20060506162808-vt2ni3r5nytcszms
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 MAGICK_IMPLEMENTATION
 
9
 
 
10
#include "Magick++/Include.h"
 
11
#include "Magick++/Thread.h"
 
12
#include "Magick++/BlobRef.h"
 
13
 
 
14
#include <string.h>
 
15
 
 
16
//
 
17
// Implementation of Magick::BlobRef
 
18
//
 
19
 
 
20
// Construct with data, making private copy of data
 
21
Magick::BlobRef::BlobRef ( const void* data_,
 
22
                           size_t length_ )
 
23
  : _data(0),
 
24
    _length(length_),
 
25
    _allocator(Magick::Blob::NewAllocator),
 
26
    _refCount(1),
 
27
    _mutexLock()
 
28
{
 
29
  if( data_ )
 
30
    {
 
31
      _data = new unsigned char[length_];
 
32
      memcpy( _data, data_, length_ );
 
33
    }
 
34
}
 
35
 
 
36
// Destructor (actually destroys data)
 
37
Magick::BlobRef::~BlobRef ( void )
 
38
{
 
39
  if ( _allocator == Magick::Blob::NewAllocator )
 
40
    {
 
41
      delete [] static_cast<unsigned char*>(_data);
 
42
      _data=0;
 
43
    }
 
44
  else if ( _allocator == Magick::Blob::MallocAllocator )
 
45
    {
 
46
      LiberateMemory(static_cast<void **>(&_data));
 
47
    }
 
48
}