1 #ifndef SDK_SDK_ANY_HELPERS_H_
11 #define SDK_SDK_ANY_HELPERS_H_
22 inline bool IsSDKAnyEmpty(
const SDKAny& any_value)
24 return ANY_IS_EMPTY(&any_value);
27 inline bool IsSDKAnyNull(
const SDKAny& any_value)
29 return ANY_IS_NULL(&any_value);
32 inline bool IsSDKAnyInteger(
const SDKAny& any_value)
38 inline bool IsSDKAnyNumeric(
const SDKAny& any_value)
44 inline bool IsSDKAnyString(
const SDKAny& any_value)
46 return ANY_IS_STR(&any_value);
49 inline bool IsSDKAnyArray(
const SDKAny& any_value)
51 return ANY_IS_ARRAY(&any_value);
54 inline bool IsSDKAnyComponent(
const SDKAny& any_value)
56 return ANY_IS_COMPONENT(&any_value);
59 inline bool IsSDKAnySimple(
const SDKAny& any_value)
64 inline bool IsSDKAnyComplex(
const SDKAny& any_value)
66 return !IsSDKAnySimple(any_value);
69 inline bool IsSDKAnyTheSame(
const SDKAny& any_value1,
const SDKAny& any_value2)
71 if (any_value1.any_type != any_value2.any_type)
74 switch(any_value1.any_type)
97 throw std::runtime_error(
"Unsupported type is used to get SDKAny value in IsAnyTheSame()");
101 inline T GetAnyValue(
const SDKAny& any_value)
103 switch(any_value.any_type)
126 throw std::runtime_error(
"Unsupported type is used to get SDKAny value in GetAnyValue<T>()");
130 inline bool GetAnyValue<bool>(
const SDKAny& any_value)
132 return 0 != GetAnyValue<SDKInt64>(any_value);
136 inline void* GetAnyValue<void*>(
const SDKAny& any_value)
138 switch(any_value.any_type)
160 throw std::runtime_error(
"Unsupported any type in GetAnyValue<void*>()");
164 inline std::string GetAnyValue<std::string>(
const SDKAny& any_value)
169 return any_value.str ?
SDKMakeString(*any_value.str) : std::string();
170 throw std::runtime_error(
"Unsupported any type in GetAnyValue<std::string>()");
174 inline std::wstring GetAnyValue<std::wstring>(
const SDKAny& any_value)
179 return any_value.str ?
SDKMakeWString(*any_value.str) : std::wstring();
180 throw std::runtime_error(
"Unsupported any type in GetAnyValue<std::wstring>()");
184 inline ISDKComponentSP GetAnyValue<ISDKComponentSP>(
const SDKAny& any_value)
187 return ISDKComponentSP(any_value.obj);
188 throw std::runtime_error(
"Unsupported any type in GetAnyValue<ISDKComponent>()");
192 inline bool GetAnyValueSafe(
const SDKAny& any_value, T& result)
196 result = GetAnyValue<T>(any_value);
204 inline T* GetAnyValueInterface(
const SDKAny& any_value)
207 return any_value.obj ? GetInterfaceT<T>(any_value.obj) : NULL;
208 throw std::runtime_error(
"Any is not a component in GetAnyValueInterface<>()");
211 inline bool IsSDKAnyEqual(
214 bool is_deep_compare,
215 double* real_threshold)
222 if (any1->any_type != any2->any_type)
225 switch(any1->any_type)
238 ? fabs(any1->flt - any2->flt) < *real_threshold
239 : any1->flt == any2->flt;
241 ? fabs(any1->dbl - any2->dbl) < *real_threshold
242 : any1->dbl == any2->dbl;
246 if (!is_deep_compare)
247 return any1->str == any2->str;
251 if (!is_deep_compare)
252 return any1->any == any2->any;
254 return IsSDKAnyEqual(any1->any, any2->any, is_deep_compare, real_threshold);
256 if (!is_deep_compare)
257 return any1->arr == any2->arr;
261 return any1->obj == any2->obj;
263 return any1->vd == any2->vd;
265 throw std::runtime_error(
"Unsupported any type in IsSDKAnyEqual()");
268 inline bool IsSDKAnyTrue(
const SDKAny& any)
292 throw std::runtime_error(
"Unsupported any type in IsSDKAnyTrue()");
295 inline bool IsSDKAnyLess(
const SDKAny& any1,
const SDKAny& any2)
297 if (any1.any_type != any2.any_type)
298 return any1.any_type < any2.any_type;
300 switch(any1.any_type)
322 throw std::runtime_error(
"Unsupported any type in IsSDKAnyLess()");
327 #endif // SDK_SDK_ANY_HELPERS_H_