2 #ifndef __INTEL_OCPROPERTY_TYPES_H_20140723
3 #define __INTEL_OCPROPERTY_TYPES_H_20140723
10 namespace OC { namespace OCReflect {
12 enum class property_type : uint8_t {
23 enum class property_attribute : uint8_t {
29 struct property_signature
31 OC::OCReflect::property_type type;
32 OC::OCReflect::property_attribute attribute;
36 : type(OC::OCReflect::property_type::nil),
37 attribute(OC::OCReflect::property_attribute::rw)
40 property_signature(const OC::OCReflect::property_type& type_)
42 attribute(OC::OCReflect::property_attribute::rw)
45 property_signature(const OC::OCReflect::property_type type_, const OC::OCReflect::property_attribute attribute_)
51 typedef std::vector<property_type> property_type_vector;
53 typedef std::vector<property_signature> property_signature_vector;
55 typedef std::vector<char> property_data;
57 typedef std::tuple<std::string, property_signature> property_binding; // ie. name + signature
58 typedef std::vector<property_binding> property_binding_vector;
60 typedef std::tuple<property_binding, property_data> property;
61 typedef std::tuple<property_signature, property_data> tagged_property; // eg. a return value
63 typedef std::vector<property> property_vector;
65 typedef std::function<property(property_vector)> bound_function;
68 }} // namespace OC::OCReflect
70 namespace OC { namespace OCReflect {
74 // zip a property type vector against an attribute:
75 inline property_signature_vector typev2signaturev(const property_type_vector& ptv, const property_attribute pa = property_attribute::rw)
77 property_signature_vector psv(ptv.size());
79 std::transform(std::begin(ptv), std::end(ptv), std::back_inserter(psv),
80 [&pa](const property_type& pt) -> property_signature { return property_signature(pt, pa); });
85 // Helper for constructing sequences (like vector<property>) from a parameter pack:
86 template <typename SeqT, typename T>
87 SeqT make_seq(const T& x)
92 template <typename SeqT, typename T, typename ...TS>
93 SeqT make_seq(const T& x, const TS&... xs)
97 auto vs = make_seq<SeqT>(xs...);
99 s.insert(s.end(), std::make_move_iterator(vs.begin()), std::make_move_iterator(vs.end()));
104 } // namespace OC::OCReflect::detail
106 struct method_signature
108 property_signature ret_signature;
109 property_signature_vector param_signatures;
112 method_signature(const property_type& return_type, const property_signature_vector& param_types_)
113 : ret_signature(return_type, OC::OCReflect::property_attribute::r),
114 param_signatures(param_types_)
117 method_signature(const property_type& return_type, const property_type_vector& param_types_)
118 : ret_signature(return_type, OC::OCReflect::property_attribute::r),
119 param_signatures(detail::typev2signaturev(param_types_))
122 template <typename ...ParameterT>
123 method_signature(const property_type& return_type, const ParameterT& ...params_)
124 : ret_signature(return_type, OC::OCReflect::property_attribute::r),
125 param_signatures { detail::make_seq<property_signature_vector>(params_...) }
129 }} // namespace OC::OCReflect
131 namespace OC { namespace OCReflect {
133 struct method_binding
135 friend std::ostream& operator<<(std::ostream& os, const OC::OCReflect::method_binding& mb);
140 method_signature signature;
143 static unsigned long long anon;
147 : name("__ANONYMOUS__"),
148 signature { property_type::nil, {{ property_type::nil, property_attribute::r }} }
151 method_binding(bound_function& f,
152 method_signature& signature_)
153 : signature(signature_)
156 method_binding(const std::string& name_, bound_function& f_,
157 const property_type& return_type_, const property_type_vector& param_types_)
160 signature { return_type_, param_types_ }
163 method_binding(const std::string& name_, bound_function& f_,
164 const method_signature& signature_)
167 signature(signature_)
171 }} // namespace OC::OCReflect
174 // Map concerete to property type enumerations (used for returning runtime types from compile time types):
175 namespace OC { namespace OCReflect {
177 template <typename T>
178 struct map_property_type
180 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::INVALID);
184 struct map_property_type<bool>
186 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::boolean);
190 struct map_property_type<int64_t>
192 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::integer);
196 struct map_property_type<double>
198 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::rational);
202 struct map_property_type<std::string>
204 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::string);
208 struct map_property_type<const char *>
210 static const uint8_t value = static_cast<const uint8_t>(OC::OCReflect::property_type::string);
214 // Sequence containers:
216 struct map_property_type< template <class T, class A> >
218 static const uint8_t value = static_const<const uint8_t>(OC::OCReflect::property_type::list);
222 struct map_property_type<std::vector>
224 static const uint8_t value = static_const<const uint8_t>(OC::OCReflect::property_type::list);
228 struct map_property_type<std::list>
230 static const uint8_t value = static_const<const uint8_t>(OC::OCReflect::property_type::list);
234 struct map_property_type<std::forward_list>
236 static const uint8_t value = static_const<const uint8_t>(OC::OCReflect::property_type::list);
240 struct map_property_type<std::deque>
242 static const uint8_t value = static_const<const uint8_t>(OC::OCReflect::property_type::list);
246 }} // namespace OC::OCReflect