15 #ifndef SHAKA_EMBEDDED_MAPPING_STRUCT_H_ 16 #define SHAKA_EMBEDDED_MAPPING_STRUCT_H_ 20 #include <type_traits> 35 #define THIS_TYPE std::decay<decltype(*this)>::type 37 #define ADD_NAMED_DICT_FIELD(member, name, ...) \ 38 __VA_ARGS__ member = CreateFieldConverter(name, &THIS_TYPE::member) 39 #define ADD_DICT_FIELD(member, ...) \ 40 ADD_NAMED_DICT_FIELD(member, #member, __VA_ARGS__) 42 #define DECLARE_STRUCT_SPECIAL_METHODS_COPYABLE(Type) \ 43 static std::string name() { \ 50 Type& operator=(const Type&); \ 51 Type& operator=(Type&&) 52 #define DEFINE_STRUCT_SPECIAL_METHODS_COPYABLE(Type) \ 54 Type::Type(const Type&) = default; \ 55 Type::Type(Type&&) = default; \ 57 Type& Type::operator=(const Type&) = default; \ 58 Type& Type::operator=(Type&&) = default 59 #define DECLARE_STRUCT_SPECIAL_METHODS_MOVE_ONLY(Type) \ 60 static std::string name() { \ 64 Type(const Type&) = delete; \ 67 Type& operator=(const Type&) = delete; \ 68 Type& operator=(Type&&) 69 #define DEFINE_STRUCT_SPECIAL_METHODS_MOVE_ONLY(Type) \ 71 Type::Type(Type&&) = default; \ 73 Type& Type::operator=(Type&&) = default 99 Handle<JsObject>
object)
const = 0;
108 template <
typename Parent,
typename Field>
112 : name_(name), member_(member) {}
116 auto parent =
static_cast<Parent*
>(dict);
122 auto parent =
static_cast<const Parent*
>(dict);
123 LocalVar<JsValue> value(
ToJsValue(parent->*member_));
128 auto parent =
static_cast<const Parent*
>(dict);
129 tracer->
Trace(&(parent->*member_));
136 Field Parent::*member_;
178 bool TryConvert(Handle<JsValue> value)
override;
179 ReturnVal<JsValue>
ToJsValue()
const override;
183 template <
typename Parent,
typename Field>
185 static_assert(std::is_base_of<Struct, Parent>::value,
186 "Must be derived from Struct");
188 converters_.emplace_back(convert);
194 std::vector<std::shared_ptr<impl::FieldConverterBase>> converters_;
199 #endif // SHAKA_EMBEDDED_MAPPING_STRUCT_H_
bool FromJsValue(Handle< JsValue > source, T *dest)
virtual void AddToObject(const Struct *dict, Handle< JsObject > object) const =0
void AddToObject(const Struct *dict, Handle< JsObject > object) const override
ReturnVal< JsValue > ToJsValue(T &&source)
virtual void SearchAndStore(Struct *dict, Handle< JsObject > object)=0
Field CreateFieldConverter(const std::string &name, Field Parent::*field)
void Trace(const Traceable *ptr)
virtual ~FieldConverterBase()
void SetMemberRaw(Handle< JsObject > object, const std::string &name, Handle< JsValue > value)
virtual void Trace(const Struct *dict, memory::HeapTracer *tracer) const =0
void Trace(const Struct *dict, memory::HeapTracer *tracer) const override
ReturnVal< JsValue > GetMemberRaw(Handle< JsObject > object, const std::string &name, LocalVar< JsValue > *exception=nullptr)
void SearchAndStore(Struct *dict, Handle< JsObject > object) override
FieldConverter(const std::string &name, Field Parent::*member)