summaryrefslogtreecommitdiffstats
path: root/src/uscxml/messages
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-06 16:04:18 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2014-07-06 16:04:18 (GMT)
commit9cc762d85afffea42de3e1d156a6b8838d88a00c (patch)
treebff170c0493759c7f1bffca2648960b6f43ca139 /src/uscxml/messages
parentbe98a8297b4e10e169290f497e649e803e43d791 (diff)
downloaduscxml-9cc762d85afffea42de3e1d156a6b8838d88a00c.zip
uscxml-9cc762d85afffea42de3e1d156a6b8838d88a00c.tar.gz
uscxml-9cc762d85afffea42de3e1d156a6b8838d88a00c.tar.bz2
Made Blob into Pimpl to better support language bindings
Diffstat (limited to 'src/uscxml/messages')
-rw-r--r--src/uscxml/messages/Blob.cpp16
-rw-r--r--src/uscxml/messages/Blob.h93
-rw-r--r--src/uscxml/messages/Data.cpp4
-rw-r--r--src/uscxml/messages/Data.h13
4 files changed, 99 insertions, 27 deletions
diff --git a/src/uscxml/messages/Blob.cpp b/src/uscxml/messages/Blob.cpp
index 2e68e98..b8a263e 100644
--- a/src/uscxml/messages/Blob.cpp
+++ b/src/uscxml/messages/Blob.cpp
@@ -24,27 +24,27 @@
namespace uscxml {
-Blob::~Blob() {
+BlobImpl::~BlobImpl() {
free(data);
}
-std::string Blob::md5() {
+std::string BlobImpl::md5() const {
return uscxml::md5(data, size);
}
-Blob* Blob::fromBase64(const std::string base64) {
+BlobImpl* BlobImpl::fromBase64(const std::string base64, const std::string& mimeType) {
std::string decoded = base64Decode(base64);
- return new Blob(decoded.c_str(), decoded.length(), mimeType);
+ return new BlobImpl(decoded.c_str(), decoded.length(), mimeType);
}
-Blob::Blob(size_t _size) {
+BlobImpl::BlobImpl(size_t _size) {
data = (char*)malloc(_size);
memset(data, 0, _size);
size = _size;
mimeType = "application/octet-stream";
}
-Blob::Blob(const char* _data, size_t _size, const std::string& _mimeType, bool adopt) {
+BlobImpl::BlobImpl(const char* _data, size_t _size, const std::string& _mimeType, bool adopt) {
if (adopt) {
data = (char*)_data;
} else {
@@ -54,8 +54,8 @@ Blob::Blob(const char* _data, size_t _size, const std::string& _mimeType, bool a
mimeType = _mimeType;
size = _size;
}
-
-std::string Blob::base64() {
+
+std::string BlobImpl::base64() const {
return base64Encode((char* const)data, size);
}
diff --git a/src/uscxml/messages/Blob.h b/src/uscxml/messages/Blob.h
index b805da1..0c20f95 100644
--- a/src/uscxml/messages/Blob.h
+++ b/src/uscxml/messages/Blob.h
@@ -21,33 +21,38 @@
#define BLOB_H_E1B6D2C3
#include <string>
+#include <boost/shared_ptr.hpp>
#include "uscxml/Common.h"
namespace uscxml {
-class USCXML_API Blob {
+class USCXML_API BlobImpl {
public:
- ~Blob();
- Blob(size_t size);
- Blob(const char* data, size_t size, const std::string& mimeType, bool adopt = false);
-
- std::string base64();
- std::string md5();
- Blob* fromBase64(const std::string base64);
-
+ BlobImpl(size_t size);
+ BlobImpl(const char* data, size_t size, const std::string& mimeType, bool adopt = false);
+ virtual ~BlobImpl();
+
+ std::string base64() const;
+ std::string md5() const;
+ static BlobImpl* fromBase64(const std::string base64, const std::string& mimeType);
+
char* getData() const {
return data;
}
-
+
size_t getSize() const {
return size;
}
-
+
std::string getMimeType() const {
return mimeType;
}
-
+
+ void setMimeType(const std::string& mimeType) {
+ this->mimeType = mimeType;
+ }
+
#ifdef SWIGIMPORTED
protected:
#endif
@@ -55,7 +60,71 @@ protected:
char* data;
size_t size;
std::string mimeType;
+};
+
+class USCXML_API Blob {
+public:
+
+ Blob() : _impl() {}
+ Blob(const boost::shared_ptr<BlobImpl> impl) : _impl(impl) { }
+ Blob(const Blob& other) : _impl(other._impl) { }
+ Blob(size_t size) : _impl(boost::shared_ptr<BlobImpl>(new BlobImpl(size))) {}
+ Blob(const char* data,
+ size_t size,
+ const std::string& mimeType = "application/octet-stream",
+ bool adopt = false) :
+ _impl(boost::shared_ptr<BlobImpl>(new BlobImpl(data, size, mimeType, adopt))) {}
+ virtual ~Blob() {};
+
+ operator bool() const {
+ return _impl;
+ }
+ bool operator< (const Blob& other) const {
+ return _impl < other._impl;
+ }
+ bool operator==(const Blob& other) const {
+ return _impl == other._impl;
+ }
+ bool operator!=(const Blob& other) const {
+ return _impl != other._impl;
+ }
+ Blob& operator= (const Blob& other) {
+ _impl = other._impl;
+ return *this;
+ }
+ static Blob fromBase64(const std::string base64, const std::string& mimeType = "application/octet-stream") {
+ return Blob(boost::shared_ptr<BlobImpl>(BlobImpl::fromBase64(base64, mimeType)));
+ }
+
+ std::string base64() const {
+ return _impl->base64();
+ }
+
+ std::string md5() const {
+ return _impl->md5();
+ }
+
+ char* getData() const {
+ return _impl->getData();
+ }
+
+ size_t getSize() const {
+ return _impl->getSize();
+ }
+
+ std::string getMimeType() const {
+ return _impl->getMimeType();
+ }
+
+ void setMimeType(const std::string& mimeType) {
+ _impl->setMimeType(mimeType);
+ }
+
+#ifdef SWIGIMPORTED
+protected:
+#endif
+ boost::shared_ptr<BlobImpl> _impl;
};
diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp
index 1ee946a..911730a 100644
--- a/src/uscxml/messages/Data.cpp
+++ b/src/uscxml/messages/Data.cpp
@@ -35,9 +35,7 @@ extern "C" {
namespace uscxml {
-Data::Data(const char* data, size_t size, const std::string& mimeType, bool adopt) {
- binary = boost::shared_ptr<Blob>(new Blob(data, size, mimeType, adopt));
-}
+Data::Data(const char* data, size_t size, const std::string& mimeType, bool adopt) : binary(data, size, mimeType, adopt) {}
void Data::merge(const Data& other) {
if (other.compound.size() > 0) {
diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h
index 44ce1d7..11b46fb 100644
--- a/src/uscxml/messages/Data.h
+++ b/src/uscxml/messages/Data.h
@@ -27,12 +27,11 @@
#include "uscxml/Common.h"
#include "uscxml/Convenience.h"
+#include "uscxml/messages/Blob.h"
#include <DOM/Document.hpp>
namespace uscxml {
-class Blob;
-
static int _dataIndentation = 1;
class USCXML_API Data {
@@ -220,6 +219,13 @@ public:
this->atom = atom;
}
+ Blob getBinary() {
+ return this->binary;
+ }
+ void setBinary(const Blob& binary) {
+ this->binary = binary;
+ }
+
Type getType() {
return type;
}
@@ -227,7 +233,6 @@ public:
this->type = type;
}
-
#ifdef SWIGIMPORTED
protected:
#endif
@@ -236,7 +241,7 @@ protected:
std::map<std::string, Data> compound;
std::list<Data> array;
std::string atom;
- boost::shared_ptr<Blob> binary;
+ Blob binary;
Type type;
protected: