13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// This may look like C code, but it is really -*- C++ -*- 23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Copyright Bob Friesenhahn, 1999, 2000, 2001, 2002 4bed10b164d3d5f161ace78109adb5219446e9218dirk// Copyright Dirk Lemstra 2015 53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// Reference counted container class for Binary Large Objects (BLOBs) 73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy// 83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(Magick_BlobRef_header) 103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define Magick_BlobRef_header 113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include "Magick++/Include.h" 133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <string> 143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 153ed852eea50f9d4cd633efb8c2b054b8e33c253cristynamespace Magick 163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{ 173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Forward decl 183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy class BlobRef; 193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 20af1dd259230d63d51f441c28bc23265a79b19c55cristy class MagickPPExport Blob 213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy public: 233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy enum Allocator 253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy { 263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy MallocAllocator, 273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy NewAllocator 283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }; 293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Default constructor 3104a15bc961aeaded80e33141c68e2399f789f282dirk Blob(void); 323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Construct object with data, making a copy of the supplied data. 34e8fddf8b0ee09a9ff393449b169dd2e24e7608e4dirk Blob(const void* data_,const size_t length_); 353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Copy constructor (reference counted) 3704a15bc961aeaded80e33141c68e2399f789f282dirk Blob(const Blob& blob_); 383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Destructor (reference counted) 4004a15bc961aeaded80e33141c68e2399f789f282dirk virtual ~Blob(); 413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Assignment operator (reference counted) 4304a15bc961aeaded80e33141c68e2399f789f282dirk Blob& operator=(const Blob& blob_); 443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Update object contents from Base64-encoded string representation. 4604a15bc961aeaded80e33141c68e2399f789f282dirk void base64(const std::string base64_); 473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Return Base64-encoded string representation. 48be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk std::string base64(void) const; 49be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk 50be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // Obtain pointer to data. The user should never try to modify or 51be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // free this data since the Blob class manages its own data. The 52be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // user must be finished with the data before allowing the Blob to 53be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // be destroyed since the pointer is invalid once the Blob is 54be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // destroyed. 55be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk const void* data(void) const; 56be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk 57be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk // Obtain data length 58be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk size_t length(void) const; 593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Update object contents, making a copy of the supplied data. 613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Any existing data in the object is deallocated. 62be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk void update(const void* data_,const size_t length_); 633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Update object contents, using supplied pointer directly (no 653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // copy). Any existing data in the object is deallocated. The user 663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // must ensure that the pointer supplied is not deleted or 673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // otherwise modified after it has been supplied to this method. 683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // Specify allocator_ as "MallocAllocator" if memory is allocated 693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // via the C language malloc() function, or "NewAllocator" if 703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy // memory is allocated via C++ 'new'. 71be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk void updateNoCopy(void* data_,const size_t length_, 72be9f62c7943cfd2c3fc13892319933a9e7ae1322dirk const Allocator allocator_=NewAllocator); 733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy private: 7504a15bc961aeaded80e33141c68e2399f789f282dirk BlobRef *_blobRef; 763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy }; 773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} // namespace Magick 793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy 803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif // Magick_BlobRef_header 81