16 #include <type_traits> 28 ObjectContainer(
const std::type_info &);
30 virtual ~ObjectContainer(
void);
34 const std::type_info &type;
36 std::atomic<unsigned> counter;
42 template <
typename ValueType>
43 struct ObjectContainerT : ObjectContainer
45 template <
typename... Args>
46 ObjectContainerT(Args&&... args):
47 ObjectContainer(typeid(ValueType)),
48 value(std::forward<Args>(args)...)
50 internal = (
void*)std::addressof(this->value);
53 ~ObjectContainerT(
void)
61 template <
typename ValueType,
typename... Args>
62 typename std::enable_if<!std::is_same<NullObject, ValueType>::value, ObjectContainer *>::type
63 makeObjectContainer(Args&&... args)
65 return new ObjectContainerT<Pothos::Util::special_decay_t<ValueType>>(std::forward<Args>(args)...);
68 template <
typename ValueType,
typename... Args>
69 typename std::enable_if<std::is_same<NullObject, ValueType>::value, ObjectContainer *>::type
70 makeObjectContainer(Args&&...)
78 template <
typename ValueType>
79 ValueType &extractObject(
const Object &obj)
83 typedef typename std::decay<ValueType>::type DecayValueType;
84 return *(
reinterpret_cast<DecayValueType *
>((obj._impl ==
nullptr)?0:obj._impl->internal));
87 [[noreturn]]
POTHOS_API void throwExtract(
const Object &obj,
const std::type_info &type);
94 typename std::enable_if<!std::is_same<T, Object>::value, T>::type
95 convertObject(
const Object &obj)
97 return extractObject<T>(obj.convert(
typeid(T)));
100 template <
typename T>
101 typename std::enable_if<std::is_same<T, Object>::value, T>::type
102 convertObject(
const Object &obj)
109 template <
typename ValueType>
115 template <
typename ValueType,
typename... Args>
121 template <
typename ValueType,
typename>
123 _impl(Detail::makeObjectContainer<ValueType>(std::forward<ValueType>(value)))
128 template <
typename ValueType,
typename... Args>
130 _impl(Detail::makeObjectContainer<ValueType>(std::forward<Args>(args)...))
136 _impl(Detail::makeObjectContainer<std::string>(s))
146 template <
typename ValueType>
149 if (this->
type() ==
typeid(ValueType))
151 return Detail::extractObject<ValueType>(*this);
153 Detail::throwExtract(*
this,
typeid(ValueType));
156 template <
typename ValueType>
159 if (not this->
unique())
throw ObjectConvertError(
"Pothos::Object::ref()",
160 "Multiple object ownership, access denied to non-const reference");
161 return const_cast<ValueType &
>(this->extract<ValueType>());
164 template <
typename ValueType>
167 if (this->
type() ==
typeid(ValueType))
169 return Detail::extractObject<ValueType>(*this);
171 return Detail::convertObject<ValueType>(*this);
174 template <
typename ValueType>
175 Object::operator ValueType(
void)
const 177 return this->convert<ValueType>();
Emplace dummy type to pass type to Object emplacement constructor.
Definition: Object.hpp:102
#define POTHOS_API
Definition: Config.hpp:41
static Object make(ValueType &&value)
Definition: ObjectImpl.hpp:110
const ValueType & extract(void) const
Definition: ObjectImpl.hpp:147
Definition: ArchiveEntry.hpp:20
const std::type_info & type(void) const
Definition: ObjectImpl.hpp:141
Detail::ObjectContainer * _impl
Private implementation details.
Definition: Object.hpp:293
Definition: Object.hpp:47
ValueType convert(void) const
Definition: ObjectImpl.hpp:165
static Object emplace(Args &&... args)
Definition: ObjectImpl.hpp:116
Definition: Object.hpp:29
ValueType & ref(void)
Definition: ObjectImpl.hpp:157