ZFFramework
 
Loading...
Searching...
No Matches
ZFObjectUtil.h
Go to the documentation of this file.
1
5
6#ifndef _ZFI_ZFObjectUtil_h_
7#define _ZFI_ZFObjectUtil_h_
8
9#include "ZFObjectCore.h"
10#include "ZFObjectRetain.h"
12
13// ============================================================
14// compare
22 ZF_IN ZFObject *const &e0
23 , ZF_IN ZFObject *const &e1
24 ) {
25 if(e0 == zfnull) {
26 if(e1 == zfnull) {
27 return ZFCompareEqual;
28 }
29 else {
31 }
32 }
33 else {
34 if(e1 == zfnull) {
36 }
37 else {
38 return e0->objectCompare(e1);
39 }
40 }
41}
42
46 ZF_IN ZFObject *const &e0
47 , ZF_IN ZFObject *const &e1
48 ) {
49 if(e0 == zfnull) {
50 if(e1 == zfnull) {
51 return ZFCompareEqual;
52 }
53 else {
54 switch(e1->objectCompareValue(e0)) {
55 case ZFCompareEqual:
56 return ZFCompareEqual;
58 return ZFCompareGreater;
60 return ZFCompareSmaller;
62 default:
64 }
65 }
66 }
67 else {
68 return e0->objectCompareValue(e1);
69 }
70}
71
72// ============================================================
76 , ZF_IN ZFObject *obj
77 ) {
78 if(obj == zfnull) {
79 ret += ZFTOKEN_zfnull;
80 }
81 else {
82 obj->objectInfoOfInstanceT(ret);
83 }
84}
85
91 return ((obj == zfnull) ? zfstring(ZFTOKEN_zfnull) : obj->objectInfoOfInstance());
92}
93
94inline void ZFObjectInfoT(
96 , ZF_IN ZFObject *obj
97 ) {
98 if(obj == zfnull) {
99 ret += ZFTOKEN_zfnull;
100 }
101 else {
102 obj->objectInfoT(ret);
103 }
104}
105
111 return ((obj == zfnull) ? zfstring(ZFTOKEN_zfnull) : obj->objectInfo());
112}
113
119 return ((obj == zfnull) ? zfidentityInvalid() : obj->objectHash());
120}
121
122// ============================================================
123// special fix for ZFObject types
125template<typename T0, typename T1>
127 , void, void
128 , typename zftEnableIf<zftIsZFObject(typename zftTraits<T0>::TrType)>::Value
129 , typename zftEnableIf<zftIsZFObject(typename zftTraits<T1>::TrType)>::Value
130 > {
131public:
132 static ZFCompareResult comparer(
133 ZF_IN T0 const &e0
134 , ZF_IN T1 const &e1
135 ) {
136 return ZFObjectCompare(zfcast(ZFObject *, e0), zfcast(ZFObject *, e1));
137 }
138};
140
141// ============================================================
143 return ZFObjectCompare(v0.toObject(), v1.toObject());
144 })
146 return ZFObjectCompare(v0.toObject(), v1.toObject());
147 })
148
149// ============================================================
154 ZF_IN const ZFListener &impl
155 , ZF_IN_OPT const ZFArgs &zfargs = ZFArgs()
156 ) {
157 impl.execute(zfargs);
158 return zfargs.result();
159}
160
162#endif // #ifndef _ZFI_ZFObjectUtil_h_
163
#define ZFCOMPARER_DEFAULT_DECLARE(T_Comparable0, T_Comparable1, compareAction)
declare a template specialization for ZFComparerDefault
Definition ZFComparer.h:264
#define ZF_IN
dummy macro that shows the param used as required input
Definition ZFCoreTypeDef_ClassType.h:180
#define ZF_IN_OPT
dummy macro that shows the param used as optional input
Definition ZFCoreTypeDef_ClassType.h:184
#define zfclassNotPOD
shows the class is not a POD type, you should not memset it or declare it in stack or copy value by c...
Definition ZFCoreTypeDef_ClassType.h:48
#define ZF_IN_OUT
dummy macro that shows the param used as required input and output
Definition ZFCoreTypeDef_ClassType.h:196
_zft_zfidentity zfidentity
identity type, ensured at least 32 bit, ensured unsigned
Definition ZFCoreTypeDef_CoreType.h:225
#define zfidentityInvalid()
an invalid id value, ensured ((zfidentity)-1)
Definition ZFCoreTypeDef_CoreType.h:229
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:88
#define ZFTOKEN_zfnull
string tokens
Definition ZFCoreTypeDef_OtherType.h:16
ZFCompareResult
compare result of two ZFObjects
Definition ZFCoreTypeDef_OtherType.h:28
@ ZFCompareSmaller
Definition ZFCoreTypeDef_OtherType.h:30
@ ZFCompareUncomparable
Definition ZFCoreTypeDef_OtherType.h:29
@ ZFCompareEqual
Definition ZFCoreTypeDef_OtherType.h:31
@ ZFCompareGreater
Definition ZFCoreTypeDef_OtherType.h:32
zft_zfstring< zfchar > zfstring
see zft_zfstring
Definition ZFCoreTypeDef_StringType.h:15
#define ZF_NAMESPACE_GLOBAL_BEGIN
begin namespace ZFFramework
Definition ZFNamespace.h:97
#define ZF_NAMESPACE_GLOBAL_END
end namespace ZFFramework
Definition ZFNamespace.h:98
#define zfcast(T_To, obj)
safely cast ZFObject types, return null if not desired type
Definition ZFObjectCast.h:28
#define zftIsZFObject(Type)
true if Type is ZFObject type or ZFInterface type
Definition ZFObjectClassTypeFwd.h:106
base class of all objects
retain count logic for ZFFramework
zfstring ZFObjectInfoOfInstance(ZFObject *obj)
util method to get info of object or return ZFTOKEN_zfnull if obj is null
Definition ZFObjectUtil.h:90
zfidentity ZFObjectHash(ZFObject *obj)
util method to calculate hash of object, or return zfidentityInvalid if null
Definition ZFObjectUtil.h:118
zfstring ZFObjectInfo(ZFObject *obj)
util method to get info of object or return ZFTOKEN_zfnull if obj is null
Definition ZFObjectUtil.h:110
ZFCompareResult ZFObjectCompareValue(ZFObject *const &e0, ZFObject *const &e1)
util method to ZFObject::objectCompareValue
Definition ZFObjectUtil.h:45
ZFCompareResult ZFObjectCompare(ZFObject *const &e0, ZFObject *const &e1)
util method to compare two ZFObject, return ZFCompareEqual if both null, return ZFCompareUncomparable...
Definition ZFObjectUtil.h:21
zfauto ZFObjectCreator(const ZFListener &impl, const ZFArgs &zfargs=ZFArgs())
util to create object from custom impl
Definition ZFObjectUtil.h:153
void ZFObjectInfoOfInstanceT(zfstring &ret, ZFObject *obj)
see ZFObjectInfoOfInstance
Definition ZFObjectUtil.h:74
void ZFObjectInfoT(zfstring &ret, ZFObject *obj)
see ZFObjectInfo
Definition ZFObjectUtil.h:94
listener data used by ZFListener
Definition ZFArgs.h:20
comparer holder fo ZFComparerDefault, you may specialize this class to supply your custom type's comp...
Definition ZFComparer.h:199
listener as ZFCallback, mostly used by ZFObject::observerNotify
Definition ZFObjectObserver.h:30
base class of all objects
Definition ZFObjectCore.h:209
util method to cast ZFObject types freely
Definition zfany.h:35
a ZFObject holder which would release content object automatically when destroyed
Definition zfautoFwd.h:34
std::enable_if wrapper
Definition ZFCoreUtilTemplate.h:409
T_Type TrType
normal type
Definition ZFCoreUtilTemplate.h:105