www/api/Magick++/Blob_8cpp_source.html
| 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
39 {
40try
41 {
42if (_blobRef->decrease() == 0)
43delete _blobRef;
44 }
45catch(Magick::Exception&)
46 {
47 }
48
49 _blobRef=(Magick::BlobRef *) NULL;
50 }
51
52 Magick::Blob& Magick::Blob::operator=(const Magick::Blob& blob_)
53 {
54if (this != &blob_)
55 {
56 blob_._blobRef->increase();
57if (_blobRef->decrease() == 0)
58delete _blobRef;
59
60 _blobRef=blob_._blobRef;
61 }
62return(*this);
63 }
64
65 void Magick::Blob::base64(const std::string base64_)
66 {
67size_t
68 length;
69
70unsigned char
71 *decoded;
72
73 decoded=Base64Decode(base64_.c_str(),&length);
74
75if(decoded)
76 updateNoCopy(static_cast<void*>(decoded),length,
77Magick::Blob::MallocAllocator);
78 }
79
80 std::string Magick::Blob::base64(void) const
81 {
82size_t
83 encoded_length;
84
85char
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
95if(encoded)
96 {
97 result=std::string(encoded,encoded_length);
98 encoded=(char *) RelinquishMagickMemory(encoded);
99return result;
100 }
101
102return(std::string());
103 }
104
105 const void* Magick::Blob::data(void) const
106 {
107return(_blobRef->data);
108 }
109
110 size_t Magick::Blob::length(void) const
111 {
112return(_blobRef->length);
113 }
114
115 void Magick::Blob::update(const void* data_,size_t length_)
116 {
117if (_blobRef->decrease() == 0)
118delete _blobRef;
119
120 _blobRef=new Magick::BlobRef(data_,length_);
121 }
122
123 void Magick::Blob::updateNoCopy(void* data_,size_t length_,
124Magick::Blob::Allocator allocator_)
125 {
126if (_blobRef->decrease() == 0)
127delete _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
Definition: Blob.h:28
Blob & operator=(const Blob &blob_)
Definition: Blob.cpp:52
Blob(void)
Definition: Blob.cpp:21
void updateNoCopy(void *data_, const size_t length_, const Allocator allocator_=NewAllocator)
Definition: Blob.cpp:123
virtual ~Blob()
Definition: Blob.cpp:38
Definition: Blob.h:22
Definition: Exception.h:24
void increase()
Definition: BlobRef.cpp:64
std::string base64(void) const
Definition: Blob.cpp:80
Definition: BlobRef.h:23
const void * data(void) const
Definition: Blob.cpp:105
void update(const void *data_, const size_t length_)
Definition: Blob.cpp:115
Allocator
Definition: Blob.h:26
Definition: Blob.h:17
size_t length(void) const
Definition: Blob.cpp:110