Blob.h
Go to the documentation of this file.
1 
20 #ifndef BLOB_H_E1B6D2C3
21 #define BLOB_H_E1B6D2C3
22 
23 #include <string>
24 #include <memory>
25 
26 #include "uscxml/Common.h"
27 
28 namespace uscxml {
29 
30 class USCXML_API BlobImpl {
31 public:
32  BlobImpl(size_t size);
33  BlobImpl(const char* data, size_t size, const std::string& mimeType, bool adopt = false);
34  virtual ~BlobImpl();
35 
36  std::string base64() const;
37  std::string md5() const;
38  static BlobImpl* fromBase64(const std::string base64, const std::string& mimeType);
39 
40  char* getData() const {
41  return data;
42  }
43 
44  size_t getSize() const {
45  return size;
46  }
47 
48  std::string getMimeType() const {
49  return mimeType;
50  }
51 
52  void setMimeType(const std::string& mimeType) {
53  this->mimeType = mimeType;
54  }
55 
56 #ifdef SWIGIMPORTED
57 protected:
58 #endif
59 
60  char* data;
61  size_t size;
62  std::string mimeType;
63 };
64 
65 class USCXML_API Blob {
66 public:
67 
69 
70  Blob(size_t size) : _impl(std::shared_ptr<BlobImpl>(new BlobImpl(size))) {}
71  Blob(const char* data,
72  size_t size,
73  const std::string& mimeType = "application/octet-stream",
74  bool adopt = false) :
75  _impl(std::shared_ptr<BlobImpl>(new BlobImpl(data, size, mimeType, adopt))) {}
76 
77  static Blob fromBase64(const std::string base64, const std::string& mimeType = "application/octet-stream") {
78  return Blob(std::shared_ptr<BlobImpl>(BlobImpl::fromBase64(base64, mimeType)));
79  }
80 
81  std::string base64() const {
82  return _impl->base64();
83  }
84 
85  std::string md5() const {
86  return _impl->md5();
87  }
88 
89  char* getData() const {
90  return _impl->getData();
91  }
92 
93  size_t getSize() const {
94  return _impl->getSize();
95  }
96 
97  std::string getMimeType() const {
98  return _impl->getMimeType();
99  }
100 
101  void setMimeType(const std::string& mimeType) {
102  _impl->setMimeType(mimeType);
103  }
104 
105 #ifdef SWIGIMPORTED
106 protected:
107 #endif
108  std::shared_ptr<BlobImpl> _impl;
109 
110 };
111 
112 }
113 
114 #endif /* end of include guard: BLOB_H_E1B6D2C3 */
Definition: Breakpoint.cpp:26
#define PIMPL_OPERATORS(type)
The usual operators as required for the PIMPL pattern.
Definition: Common.h:68
Definition: Blob.h:30
Definition: Blob.h:65