diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-05 22:53:49 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-07-05 22:53:49 (GMT) |
commit | f50dabccaae935457ea6f09a349d54855d60e7d5 (patch) | |
tree | 133f714be2b946b240d34c7cf3e6c1f5b5963f30 /src/uscxml | |
parent | dec6466d01757ab8e93d867e5a6d214bcafaf428 (diff) | |
download | uscxml-f50dabccaae935457ea6f09a349d54855d60e7d5.zip uscxml-f50dabccaae935457ea6f09a349d54855d60e7d5.tar.gz uscxml-f50dabccaae935457ea6f09a349d54855d60e7d5.tar.bz2 |
Binary data in bindings
Diffstat (limited to 'src/uscxml')
-rw-r--r-- | src/uscxml/messages/Blob.cpp | 7 | ||||
-rw-r--r-- | src/uscxml/messages/Blob.h | 27 | ||||
-rw-r--r-- | src/uscxml/messages/Data.cpp | 4 | ||||
-rw-r--r-- | src/uscxml/messages/Data.h | 22 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp | 2 |
5 files changed, 40 insertions, 22 deletions
diff --git a/src/uscxml/messages/Blob.cpp b/src/uscxml/messages/Blob.cpp index 1d07e6a..2e68e98 100644 --- a/src/uscxml/messages/Blob.cpp +++ b/src/uscxml/messages/Blob.cpp @@ -34,16 +34,17 @@ std::string Blob::md5() { Blob* Blob::fromBase64(const std::string base64) { std::string decoded = base64Decode(base64); - return new Blob((void*)decoded.c_str(), decoded.length(), mimeType); + return new Blob(decoded.c_str(), decoded.length(), mimeType); } Blob::Blob(size_t _size) { data = (char*)malloc(_size); memset(data, 0, _size); size = _size; + mimeType = "application/octet-stream"; } -Blob::Blob(void* _data, size_t _size, const std::string& _mimeType, bool adopt) { +Blob::Blob(const char* _data, size_t _size, const std::string& _mimeType, bool adopt) { if (adopt) { data = (char*)_data; } else { @@ -53,7 +54,7 @@ Blob::Blob(void* _data, size_t _size, const std::string& _mimeType, bool adopt) mimeType = _mimeType; size = _size; } - + std::string Blob::base64() { return base64Encode((char* const)data, size); } diff --git a/src/uscxml/messages/Blob.h b/src/uscxml/messages/Blob.h index b4fcd46..b805da1 100644 --- a/src/uscxml/messages/Blob.h +++ b/src/uscxml/messages/Blob.h @@ -30,15 +30,32 @@ class USCXML_API Blob { public: ~Blob(); Blob(size_t size); - Blob(void* data, size_t size, const std::string& mimeType, bool adopt = false); - char* data; - size_t size; - std::string mimeType; + 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); + + char* getData() const { + return data; + } + + size_t getSize() const { + return size; + } + + std::string getMimeType() const { + return mimeType; + } + +#ifdef SWIGIMPORTED +protected: +#endif + + char* data; + size_t size; + std::string mimeType; + }; diff --git a/src/uscxml/messages/Data.cpp b/src/uscxml/messages/Data.cpp index 6706253..1ee946a 100644 --- a/src/uscxml/messages/Data.cpp +++ b/src/uscxml/messages/Data.cpp @@ -35,8 +35,8 @@ 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((void*)_data, _size, mimeType, adopt)); +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)); } void Data::merge(const Data& other) { diff --git a/src/uscxml/messages/Data.h b/src/uscxml/messages/Data.h index 9b5bea7..44ce1d7 100644 --- a/src/uscxml/messages/Data.h +++ b/src/uscxml/messages/Data.h @@ -45,26 +45,26 @@ public: Data() : type(INTERPRETED) {} // TODO: default INTERPRETED is unfortunate - Data(const std::string& atom_, Type type_ = INTERPRETED) : atom(atom_), type(type_) {} + Data(const std::string& atom, Type type = INTERPRETED) : atom(atom), type(type) {} Data(const char* data, size_t size, const std::string& mimeType, bool adopt = false); // convenience constructors - Data(short atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(unsigned int atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(unsigned long atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(float atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(double atom_) : atom(toStr(atom_)), type(INTERPRETED) {} - Data(bool atom_) : type(INTERPRETED) { - if (atom_) { + Data(short atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(int atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(unsigned int atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(long atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(unsigned long atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(float atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(double atom) : atom(toStr(atom)), type(INTERPRETED) {} + Data(bool atom) : type(INTERPRETED) { + if (atom) { atom = "true"; } else { atom = "false"; } } - template <typename T> Data(T value, Type type_) : atom(toStr(value)), type(type_) {} + template <typename T> Data(T value, Type type) : atom(toStr(value)), type(type) {} #if 0 // constructor for arbitrary types, skip if type is subclass though (C++11) diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp index fd1f936..5b34181 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp @@ -42,7 +42,7 @@ ArrayBuffer::ArrayBuffer(boost::shared_ptr<Blob> buffer) : _buffer(buffer) { } ArrayBuffer::ArrayBuffer(void* data, unsigned int size) { - _buffer = boost::shared_ptr<Blob>(new Blob(data, size, "application/octet-stream")); + _buffer = boost::shared_ptr<Blob>(new Blob((const char*)data, size, "application/octet-stream")); } unsigned long ArrayBuffer::getByteLength() { |