28 #ifndef YSL_INC_Core_yobject_h_
29 #define YSL_INC_Core_yobject_h_ 1
32 #include YFM_YSLib_Core_YCoreUtilities
33 #include YFM_YSLib_Adaptor_YContainer
71 template<
class _tOwner,
typename _type>
73 std::is_base_of<OwnershipTag<_type>, _tOwner>::value>
83 DeclIEntry(
bool operator==(const IValueHolder&) const)
94 template<typename _type1, typename _type2>
95 struct
HeldEqual : private ystdex::examiners::equal_examiner
100 template<
typename _type1,
typename _type2>
104 are_equal(
const weak_ptr<_type1>& x,
const weak_ptr<_type2>& y)
110 template<
typename _type1,
typename _type2,
typename _type3,
typename _type4>
111 struct HeldEqual<pair<_type1, _type2>, pair<_type3, _type4>>
114 are_equal(
const pair<_type1, _type2>& x,
const pair<_type3, _type4>& y)
116 return x.first == y.first && x.second == y.second;
128 template<
typename _type1,
typename _type2>
145 template<
typename _type>
148 static_assert(std::is_object<_type>::value,
"Non-object type found.");
149 static_assert(!(std::is_const<_type>::value
150 || std::is_volatile<_type>::value),
"Cv-qualified type found.");
166 :
held(std::move(value))
174 ImplI(IValueHolder)
bool
175 operator==(const IValueHolder& obj)
const override
184 ImplI(IValueHolder)
void*
187 return std::addressof(
held);
191 ImplI(IValueHolder) const std::type_info&
194 return typeid(_type);
207 template<
typename _type>
210 static_assert(std::is_object<_type>::value,
"Invalid type found.");
246 ImplI(IValueHolder)
bool
247 operator==(const IValueHolder& obj)
const
250 *static_cast<const PointerHolder&>(obj).
p_held);
257 ImplI(IValueHolder)
void*
264 ImplI(IValueHolder) const std::type_info&
267 return p_held ?
typeid(_type) :
typeid(
void);
299 template<typename _type,
301 ValueObject(_type&& obj)
303 typename ystdex::remove_rcv<_type>::type>>(
yforward(obj)))
311 template<
typename _type>
322 template<
typename _type>
373 template<typename _type>
375 GetMutableObject()
const
378 YAssert(content.type() ==
typeid(_type),
"Invalid type found.");
380 return *
static_cast<_type*
>(content.get());
384 template<
typename _type>
388 return GetMutableObject<_type>();
390 template<
typename _type>
394 return GetMutableObject<_type>();
397 DefGetter(
const ynothrow,
const std::type_info&, Type, content.type())
405 template<typename _type>
409 return ystdex::any_cast<_type&>(content);
411 template<
typename _type>
415 return ystdex::any_cast<
const _type&>(content);
424 template<
typename _type>
428 return ystdex::any_cast<_type*>(&content);
430 template<
typename _type>
434 return ystdex::any_cast<
const _type*>(&content);
443 PDefH(
void, Clear, ) ynothrow
472 template<typename _type, class _tOwnerPointer = shared_ptr<_type>>
476 using DependentType = _type;
477 using PointerType = _tOwnerPointer;
478 using ConstReferenceType = decltype(*PointerType());
480 ConstReferenceType>>;
481 using ReferenceType = ReferentType&;
488 GDependency(PointerType p = PointerType())
497 DefCvt(
const ynothrow, ConstReferenceType, *ptr)
498 DefCvt(ynothrow, ReferenceType, *ptr)
499 DefCvt(
const ynothrow,
bool,
bool(ptr))
501 DefGetter(
const ynothrow, ConstReferenceType, Ref,
502 operator ConstReferenceType())
503 DefGetter(ynothrow, ReferenceType, Ref,
operator ReferenceType())
504 DefGetter(ynothrow, ReferenceType, NewRef, *GetCopyOnWritePtr())
511 ptr = PointerType(
new DependentType());
512 else if(!ptr.unique())
531 template<
typename _type>
545 : max_value(m), value(v)
549 DefGetter(
const ynothrow, ValueType, MaxValue, max_value)
#define ImplBodyMem(_m, _n,...)
const _type * AccessPtr() const ynothrow
static bool are_equal(const weak_ptr< _type1 > &x, const weak_ptr< _type2 > &y)
PointerHolder(_type *value)
const _type & Access() const
#define DefDeDtor(_t)
定义默认析构函数。
typename remove_reference< _type >::type remove_reference_t
#define DefDeCopyCtor(_t)
ValueHolder(const _type &value)
const class ystdex::nullptr_t nullptr
PointerHolder(PointerHolder &&h)
ValueObject(unique_ptr< _type > &&p, PointerTag)
构造:使用对象 unique_ptr 指针。
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
#define DefGetter(_q, _t, _n,...)
ValueObject(_type *p, PointerTag)
构造:使用对象指针。
void swap(any &x, any &y)
交换对象。
yconstfn bool AreEqualHeld(const _type1 &x, const _type2 &y)
判断动态泛型的持有值是否相等。
ValueHolder(_type &&value)
#define DefDeMoveCtor(_t)
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
DeclDerivedI(, GIHEvent, ystdex::cloneable) DeclIEntry(size_t operator()(_tParams...) const ) DeclIEntry(GIHEvent *clone() const override) EndDecltemplate< typename > class GHEvent
事件处理器接口模板。
#define YAssertNonnull(_expr)
#define yconstfn
指定编译时常量函数。
enable_if_t<!is_same< _tClass &, remove_rcv_t< _tParam > & >::value, _type > exclude_self_ctor_t
移除选择类类型的特定重载避免构造模板和复制/转移构造函数冲突。
unsigned long Reset(COMPtr< _iCOM > &ptr) ynothrow
#define DefClone(_q, _t)
动态复制。
PointerHolder(const PointerHolder &h)
#define DefDeMoveAssignment(_t)
#define DefCvt(_q, _t,...)
DefGetter(const ynothrow, const std::type_info &, Type, content.type()) template< typename _type > inline _type &Access()
访问指定类型对象。 空实例或类型检查失败 。
const _type & GetObject() const
enable_if_t<!is_array< _type >::value, std::unique_ptr< _type > > make_unique(_tParams &&...args)
使用 new 和指定参数构造指定类型的 std::unique_ptr 实例。
YF_API yimpl(GUIApplication &) FetchGlobalInstance() ynothrow
取全局应用程序实例。
GMRange(ValueType m, ValueType v)
构造:使用指定最大取值和值。
bool reset(_type *&p) ynothrow
yconstfn auto CloneNonpolymorphic(const _type &p) -> decltype(&*p)
使用 new 复制指定指针指向的对象。
#define DefDeCopyAssignment(_t)
_type * AccessPtr() ynothrow
访问指定类型对象指针。
typename remove_const< _type >::type remove_const_t
ISO C++ 1y 兼容类型操作别名。
#define YAssert(_expr, _msg)
static bool are_equal(_type1 &&x, _type2 &&y, decltype(x==y)={})
static yconstfn bool are_equal(const pair< _type1, _type2 > &x, const pair< _type3, _type4 > &y)