diff options
author | Chad Austin <chad@chadaustin.me> | 2012-09-25 23:25:30 -0700 |
---|---|---|
committer | Chad Austin <chad@chadaustin.me> | 2012-09-25 23:25:30 -0700 |
commit | 5208548e7f1db587491e91309ea883917545ba67 (patch) | |
tree | f19ac48344eb9153ce3d1c63b32a401ce97e9481 /system | |
parent | ec45caf434e7e3050a73b42ab9a9a05fba3d723f (diff) |
Break embind's dependency on boost::optional
Diffstat (limited to 'system')
-rw-r--r-- | system/include/emscripten/bind.h | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/system/include/emscripten/bind.h b/system/include/emscripten/bind.h index 0f1997bb..8f56ff87 100644 --- a/system/include/emscripten/bind.h +++ b/system/include/emscripten/bind.h @@ -2,9 +2,9 @@ #include <stddef.h> #include <string> +#include <type_traits> #include <emscripten/val.h> #include <emscripten/wire.h> -#include <boost/optional.hpp> namespace emscripten { namespace internal { @@ -525,6 +525,49 @@ namespace emscripten { } }; + namespace internal { + template<typename T> + class optional { + public: + optional() + : initialized(false) + {} + + ~optional() { + if (initialized) { + get()->~T(); + } + } + + optional(const optional&) = delete; + + T& operator*() { + assert(initialized); + return *get(); + } + + explicit operator bool() const { + return initialized; + } + + optional& operator=(const T& v) { + if (initialized) { + get()->~T(); + } + new(get()) T(v); + initialized = true; + } + + private: + T* get() { + return reinterpret_cast<T*>(&data); + } + + bool initialized; + typename std::aligned_storage<sizeof(T)>::type data; + }; + } + template<typename InterfaceType> class wrapper : public InterfaceType { public: @@ -572,7 +615,7 @@ namespace emscripten { } } - boost::optional<val> jsobj; + internal::optional<val> jsobj; }; namespace internal { |