14 #include <type_traits> 28 template <
typename T,
bool C>
struct extract_type_helper;
29 template <
typename T>
struct extract_type_helper<T, true>
31 typedef typename T::type type;
34 template <
typename T>
struct extract_type_helper<T, false>
40 class remove_reference_wrapper
48 static yes& test(
typename C::type*);
53 static const bool has_type_field =
sizeof(test<T>(
nullptr)) ==
sizeof(yes);
54 typedef typename extract_type_helper<T, has_type_field>::type extracted_type;
55 typedef std::is_same<std::reference_wrapper<extracted_type>, T> is_reference_wrapper;
58 typedef typename std::conditional<is_reference_wrapper::value, extracted_type, T>::type type;
66 ObjectContainer(
void);
68 virtual ~ObjectContainer(
void);
70 virtual const std::type_info &type(
void)
const = 0;
71 virtual const std::type_info &rawType(
void)
const = 0;
73 std::atomic<int> counter;
75 static void throwExtract(
const Object &obj,
const std::type_info &type);
77 template <
typename ValueType>
78 static ValueType &extract(
const Object &obj);
80 virtual void *
get(void)
const = 0;
86 template <
typename ValueType>
87 struct ObjectContainerType
89 typedef typename std::conditional<
93 std::is_base_of<std::ios_base, ValueType>::value,
94 std::reference_wrapper<ValueType>, ValueType
98 template <
typename ValueType>
99 struct ObjectContainerT : ObjectContainer
102 ObjectContainerT(
void)
107 template <
typename T>
108 ObjectContainerT(T &&value):
109 value(std::forward<T>(value))
114 ~ObjectContainerT(
void)
123 const std::type_info &type(
void)
const 125 return typeid(
typename remove_reference_wrapper<ValueType>::type);
132 const std::type_info &rawType(
void)
const 134 return typeid(ValueType);
137 typename ObjectContainerType<ValueType>::type value;
139 void *
get(void)
const 141 return (
void *)std::addressof(this->value);
148 template <
typename ValueType>
149 ValueType &ObjectContainer::extract(
const Object &obj)
151 typedef typename std::decay<ValueType>::type DecayValueType;
154 if (obj._impl ==
nullptr and obj.type() ==
typeid(ValueType))
156 return *(
reinterpret_cast<typename ObjectContainerType<DecayValueType>::type *
>(0));
161 typedef std::reference_wrapper<DecayValueType> refWrapperType;
162 if (obj._impl !=
nullptr and obj._impl->rawType() ==
typeid(refWrapperType))
164 return *(
reinterpret_cast<typename ObjectContainerType<refWrapperType>::type *
>(obj._impl->get()));
168 if (obj._impl !=
nullptr and obj.type() ==
typeid(ValueType))
170 return *(
reinterpret_cast<typename ObjectContainerType<DecayValueType>::type *
>(obj._impl->get()));
173 Detail::ObjectContainer::throwExtract(obj,
typeid(ValueType));
throw;
179 template <
typename ValueType>
180 ObjectContainer *makeObjectContainer(ValueType &&value)
182 return new ObjectContainerT<typename std::decay<ValueType>::type>(std::forward<ValueType>(value));
190 inline ObjectContainer *makeObjectContainer(NullObject &&)
201 POTHOS_API ObjectContainer *makeObjectContainer(
const char *s);
205 template <
typename ValueType>
209 o.
_impl = Detail::makeObjectContainer(std::forward<ValueType>(value));
213 template <
typename ValueType>
217 _impl = Detail::makeObjectContainer(std::forward<ValueType>(value));
220 template <
typename ValueType>
223 return Detail::ObjectContainer::extract<ValueType>(*this);
226 template <
typename ValueType>
230 return newObj.
extract<ValueType>();
#define POTHOS_API
Definition: Config.hpp:41
static Object make(ValueType &&value)
Definition: ObjectImpl.hpp:206
Definition: Testing.hpp:134
const ValueType & extract(void) const
Definition: ObjectImpl.hpp:221
Detail::ObjectContainer * _impl
Private implementation details.
Definition: Object.hpp:258
Definition: Object.hpp:55
ValueType convert(void) const
Definition: ObjectImpl.hpp:227