1 #ifndef OPENCV_FLANN_ANY_H_
2 #define OPENCV_FLANN_ANY_H_
22 #include "opencv2/core/cvdef.h"
23 #include "opencv2/core/utility.hpp"
33 bad_any_cast() =
default;
35 bad_any_cast(
const char* src,
const char*
dst)
36 : message_(
cv::
format(
"cvflann::bad_any_cast(from %s to %s)", src,
dst)) {}
39 const char* what() const noexcept
override
41 return message_.c_str();
48 #ifndef CV_THROW_IF_TYPE_MISMATCH
49 #define CV_THROW_IF_TYPE_MISMATCH(src_type_info, dst_type_info) \
50 if ((src_type_info) != (dst_type_info)) \
51 throw cvflann::anyimpl::bad_any_cast((src_type_info).name(), \
52 (dst_type_info).name())
65 struct base_any_policy
67 virtual void static_delete(
void**
x) = 0;
68 virtual void copy_from_value(
void const* src,
void** dest) = 0;
69 virtual void clone(
void*
const* src,
void** dest) = 0;
70 virtual void move(
void*
const* src,
void** dest) = 0;
71 virtual void* get_value(
void** src) = 0;
72 virtual const void* get_value(
void*
const * src) = 0;
73 virtual ::size_t get_size() = 0;
75 virtual void print(
std::ostream& out,
void*
const* src) = 0;
76 virtual ~base_any_policy() {}
80 struct typed_base_any_policy : base_any_policy
82 virtual ::size_t get_size()
CV_OVERRIDE {
return sizeof(
T); }
88 struct small_any_policy
CV_FINAL : typed_base_any_policy<T>
91 virtual void copy_from_value(
void const* src,
void** dest)
CV_OVERRIDE
93 new (dest)
T(*
reinterpret_cast<T const*
>(src));
95 virtual void clone(
void*
const* src,
void** dest)
CV_OVERRIDE { *dest = *src; }
96 virtual void move(
void*
const* src,
void** dest)
CV_OVERRIDE { *dest = *src; }
97 virtual void* get_value(
void** src)
CV_OVERRIDE {
return reinterpret_cast<void*
>(src); }
98 virtual const void* get_value(
void*
const * src)
CV_OVERRIDE {
return reinterpret_cast<const void*
>(src); }
99 virtual void print(
std::ostream& out,
void*
const* src)
CV_OVERRIDE { out << *reinterpret_cast<T const*>(src); }
103 struct big_any_policy
CV_FINAL : typed_base_any_policy<T>
107 if (*
x)
delete (*
reinterpret_cast<T**
>(
x));
110 virtual void copy_from_value(
void const* src,
void** dest)
CV_OVERRIDE
112 *dest =
new T(*
reinterpret_cast<T const*
>(src));
114 virtual void clone(
void*
const* src,
void** dest)
CV_OVERRIDE
116 *dest =
new T(**
reinterpret_cast<T* const*
>(src));
120 (*
reinterpret_cast<T**
>(dest))->~T();
121 **
reinterpret_cast<T**
>(dest) = **
reinterpret_cast<T* const*
>(src);
123 virtual void* get_value(
void** src)
CV_OVERRIDE {
return *src; }
124 virtual const void* get_value(
void*
const * src)
CV_OVERRIDE {
return *src; }
125 virtual void print(
std::ostream& out,
void*
const* src)
CV_OVERRIDE { out << *reinterpret_cast<T const*>(*src); }
128 template<>
inline void big_any_policy<flann_centers_init_t>::print(
std::ostream& out,
void*
const* src)
130 out << int(*reinterpret_cast<flann_centers_init_t const*>(*src));
133 template<>
inline void big_any_policy<flann_algorithm_t>::print(
std::ostream& out,
void*
const* src)
135 out << int(*reinterpret_cast<flann_algorithm_t const*>(*src));
138 template<>
inline void big_any_policy<cv::String>::print(
std::ostream& out,
void*
const* src)
140 out << (*reinterpret_cast<cv::String const*>(*src)).c_str();
146 typedef big_any_policy<T>
type;
150 struct choose_policy<
T*>
152 typedef small_any_policy<T*>
type;
160 struct choose_policy<any>
166 #define SMALL_POLICY(TYPE) \
168 struct choose_policy<TYPE> { typedef small_any_policy<TYPE> type; \
171 SMALL_POLICY(
signed char);
172 SMALL_POLICY(
unsigned char);
173 SMALL_POLICY(
signed short);
174 SMALL_POLICY(
unsigned short);
175 SMALL_POLICY(
signed int);
176 SMALL_POLICY(
unsigned int);
177 SMALL_POLICY(
signed long);
178 SMALL_POLICY(
unsigned long);
184 template <
typename T>
188 SinglePolicy(
const SinglePolicy& other);
189 SinglePolicy& operator=(
const SinglePolicy& other);
192 static base_any_policy* get_policy();
196 template <
typename T>
197 inline base_any_policy* SinglePolicy<T>::get_policy()
209 anyimpl::base_any_policy* policy;
214 template <
typename T>
216 : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
223 : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
228 : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
235 : policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
243 policy->static_delete(&
object);
247 any& assign(
const any&
x)
251 policy->clone(&
x.object, &
object);
256 template <
typename T>
257 any& assign(
const T&
x)
260 policy = anyimpl::SinglePolicy<T>::get_policy();
261 policy->copy_from_value(&
x, &
object);
267 any& operator=(
const T&
x)
273 any& operator=(
const any&
x)
280 any& operator=(
const char*
x)
297 CV_THROW_IF_TYPE_MISMATCH(policy->type(),
typeid(
T));
298 T*
r =
reinterpret_cast<T*
>(policy->get_value(&
object));
304 const T& cast()
const
306 CV_THROW_IF_TYPE_MISMATCH(policy->type(),
typeid(
T));
307 const T*
r =
reinterpret_cast<const T*
>(policy->get_value(&
object));
314 return policy->type() ==
typeid(anyimpl::empty_any);
320 policy->static_delete(&
object);
321 policy = anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy();
325 bool compatible(
const any&
x)
const
327 return policy->type() ==
x.policy->type();
334 return policy->type() ==
typeid(
T);
339 return policy->type();
347 any_val.policy->print(out,&any_val.object);
InputArrayOfArrays InputArrayOfArrays InputOutputArray InputOutputArray InputOutputArray InputOutputArray Size InputOutputArray InputOutputArray T
Definition: calib3d.hpp:1867
CvArr * dst
Definition: core_c.h:875
int int type
Definition: core_c.h:221
const CvArr CvArr * x
Definition: core_c.h:1195
#define CV_OVERRIDE
Definition: cvdef.h:792
#define CV_FINAL
Definition: cvdef.h:796
CV_EXPORTS String format(const char *fmt,...) CV_FORMAT_PRINTF(1
Returns a text string formatted using the printf-like expression.
CV_EXPORTS void swap(Mat &a, Mat &b)
Swaps two matrices.
std::ostream & operator<<(std::ostream &, const DualQuat< _Tp > &)
CvRect r
Definition: imgproc_c.h:984
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
QTextStream & reset(QTextStream &stream)