Magick++: Blob.cpp Source File

Magick++ 7.1.0

Blob.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 @ 2013 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++/Blob.h"
16 #include "Magick++/BlobRef.h"
17 #include "Magick++/Exception.h"
18
19 #include <string.h>
20
21 Magick::Blob::Blob(void)
22 : _blobRef(new Magick::BlobRef(0,0))
23 {
24 }
25
26 Magick::Blob::Blob(const void* data_,const size_t length_)
27 : _blobRef(new Magick::BlobRef(data_, length_))
28 {
29 }
30
31 Magick::Blob::Blob(const Magick::Blob& blob_)
32 : _blobRef(blob_._blobRef)
33 {
34 // Increase reference count
35 _blobRef->increase();
36 }
37
38 Magick::Blob::~Blob()
39 {
40 try
41 {
42 if (_blobRef->decrease() == 0)
43 delete _blobRef;
44 }
45 catch(Magick::Exception&)
46 {
47 }
48
49 _blobRef=(Magick::BlobRef *) NULL;
50 }
51
52 Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_)
53 {
54 if (this != &blob_)
55 {
56 blob_._blobRef->increase();
57 if (_blobRef->decrease() == 0)
58 delete _blobRef;
59
60 _blobRef=blob_._blobRef;
61 }
62 return(*this);
63 }
64
65 void Magick::Blob::base64(const std::string base64_)
66 {
67 size_t
68 length;
69
70 unsigned char
71 *decoded;
72
73 decoded=Base64Decode(base64_.c_str(),&length);
74
75 if(decoded)
76 updateNoCopy(static_cast<void*>(decoded),length,
77 Magick::Blob::MallocAllocator);
78 }
79
80 std::string Magick::Blob::base64(void) const
81 {
82 size_t
83 encoded_length;
84
85 char
86 *encoded;
87
88 std::string
89 result;
90
91 encoded_length=0;
92 encoded=Base64Encode(static_cast<const unsigned char*>(data()),length(),
93 &encoded_length);
94
95 if(encoded)
96 {
97 result=std::string(encoded,encoded_length);
98 encoded=(char *) RelinquishMagickMemory(encoded);
99 return result;
100 }
101
102 return(std::string());
103 }
104
105 const void* Magick::Blob::data(void) const
106 {
107 return(_blobRef->data);
108 }
109
110 size_t Magick::Blob::length(void) const
111 {
112 return(_blobRef->length);
113 }
114
115 void Magick::Blob::update(const void* data_,size_t length_)
116 {
117 if (_blobRef->decrease() == 0)
118 delete _blobRef;
119
120 _blobRef=new Magick::BlobRef(data_,length_);
121 }
122
123 void Magick::Blob::updateNoCopy(void* data_,size_t length_,
124 Magick::Blob::Allocator allocator_)
125 {
126 if (_blobRef->decrease() == 0)
127 delete _blobRef;
128
129 _blobRef=new Magick::BlobRef((const void*) NULL,0);
130 _blobRef->data=data_;
131 _blobRef->length=length_;
132 _blobRef->allocator=allocator_;
133 }
134
BlobRef.h
Magick::Blob::MallocAllocator
Definition: Blob.h:28
Magick::Blob::operator=
Blob & operator=(const Blob &blob_)
Definition: Blob.cpp:52
Magick::Blob::Blob
Blob(void)
Definition: Blob.cpp:21
Magick::Blob::updateNoCopy
void updateNoCopy(void *data_, const size_t length_, const Allocator allocator_=NewAllocator)
Definition: Blob.cpp:123
Magick::Blob::~Blob
virtual ~Blob()
Definition: Blob.cpp:38
Magick::Blob
Definition: Blob.h:22
Magick::Exception
Definition: Exception.h:24
Magick::BlobRef::increase
void increase()
Definition: BlobRef.cpp:64
Magick::Blob::base64
std::string base64(void) const
Definition: Blob.cpp:80
Include.h
Magick::BlobRef
Definition: BlobRef.h:23
Magick::Blob::data
const void * data(void) const
Definition: Blob.cpp:105
Magick::Blob::update
void update(const void *data_, const size_t length_)
Definition: Blob.cpp:115
Magick::Blob::Allocator
Allocator
Definition: Blob.h:26
Magick
Definition: Blob.h:17
Magick::Blob::length
size_t length(void) const
Definition: Blob.cpp:110
Blob.h
Exception.h