1
#ifndef OPENCV_FLANN_ANY_H_
2
#define OPENCV_FLANN_ANY_H_
36
inline
std::ostream& operator <<(std::ostream& out,
const
empty_any&)
42
struct
base_any_policy
44
virtual
void
static_delete(
void** x) = 0;
45
virtual
void
copy_from_value(
void
const* src,
void** dest) = 0;
46
virtual
void
clone(
void*
const* src,
void** dest) = 0;
47
virtual
void
move(
void*
const* src,
void** dest) = 0;
48
virtual
void* get_value(
void** src) = 0;
49
virtual
const
void* get_value(
void*
const
* src) = 0;
50
virtual ::size_t get_size() = 0;
51
virtual
const
std::type_info& type() = 0;
52
virtual
void
print(std::ostream& out,
void*
const* src) = 0;
53
virtual
~base_any_policy() {}
57
struct
typed_base_any_policy : base_any_policy
59
virtual ::size_t get_size() CV_OVERRIDE {
return
sizeof(T); }
60
virtual
const
std::type_info& type() CV_OVERRIDE {
return
typeid(T); }
65
struct
small_any_policy CV_FINAL : typed_base_any_policy<T>
67
virtual
void
static_delete(
void**) CV_OVERRIDE { }
68
virtual
void
copy_from_value(
void
const* src,
void** dest) CV_OVERRIDE
70
new
(dest) T(*
reinterpret_cast<T const*
>(src));
72
virtual
void
clone(
void*
const* src,
void** dest) CV_OVERRIDE { *dest = *src; }
73
virtual
void
move(
void*
const* src,
void** dest) CV_OVERRIDE { *dest = *src; }
74
virtual
void* get_value(
void** src) CV_OVERRIDE {
return
reinterpret_cast<
void*
>(src); }
75
virtual
const
void* get_value(
void*
const
* src) CV_OVERRIDE {
return
reinterpret_cast<
const
void*
>(src); }
76
virtual
void
print(std::ostream& out,
void*
const* src) CV_OVERRIDE { out << *reinterpret_cast<T const*>(src); }
80
struct
big_any_policy CV_FINAL : typed_base_any_policy<T>
82
virtual
void
static_delete(
void** x) CV_OVERRIDE
84
if
(* x)
delete
(*
reinterpret_cast<T**
>(x));
87
virtual
void
copy_from_value(
void
const* src,
void** dest) CV_OVERRIDE
89
*dest =
new
T(*
reinterpret_cast<T const*
>(src));
91
virtual
void
clone(
void*
const* src,
void** dest) CV_OVERRIDE
93
*dest =
new
T(**
reinterpret_cast<T* const*
>(src));
95
virtual
void
move(
void*
const* src,
void** dest) CV_OVERRIDE
97
(*
reinterpret_cast<T**
>(dest))->~T();
98
**
reinterpret_cast<T**
>(dest) = **
reinterpret_cast<T* const*
>(src);
100
virtual
void* get_value(
void** src) CV_OVERRIDE {
return
*src; }
101
virtual
const
void* get_value(
void*
const
* src) CV_OVERRIDE {
return
*src; }
102
virtual
void
print(std::ostream& out,
void*
const* src) CV_OVERRIDE { out << *reinterpret_cast<T const*>(*src); }
105
template<>
inline
void
big_any_policy<flann_centers_init_t>::print(std::ostream& out,
void*
const* src)
107
out << int(*reinterpret_cast<flann_centers_init_t const*>(*src));
110
template<>
inline
void
big_any_policy<flann_algorithm_t>::print(std::ostream& out,
void*
const* src)
112
out << int(*reinterpret_cast<flann_algorithm_t const*>(*src));
115
template<>
inline
void
big_any_policy<cv::String>::print(std::ostream& out,
void*
const* src)
117
out << (*reinterpret_cast<cv::String const*>(*src)).c_str();
123
typedef
big_any_policy<T> type;
127
struct
choose_policy<T*>
129
typedef
small_any_policy<T*> type;
137
struct
choose_policy<any>
143
#define SMALL_POLICY(TYPE) \
145
struct choose_policy<TYPE> { typedef small_any_policy<TYPE> type; \
148SMALL_POLICY(
signed
char);
149SMALL_POLICY(
unsigned
char);
150SMALL_POLICY(
signed
short);
151SMALL_POLICY(
unsigned
short);
152SMALL_POLICY(
signed
int);
153SMALL_POLICY(
unsigned
int);
154SMALL_POLICY(
signed
long);
155SMALL_POLICY(
unsigned
long);
161
template
<
typename
T>
165
SinglePolicy(
const
SinglePolicy& other);
166
SinglePolicy& operator=(
const
SinglePolicy& other);
169
static
base_any_policy* get_policy();
173
template
<
typename
T>
174
inline
base_any_policy* SinglePolicy<T>::get_policy()
176
static
typename
choose_policy<T>::type policy;
186
anyimpl::base_any_policy* policy;
191
template
<
typename
T>
193
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
200
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
205
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
212
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
220
policy->static_delete(&
object);
224
any& assign(
const
any& x)
228
policy->clone(&x.object, &
object);
233
template
<
typename
T>
234
any& assign(
const
T& x)
237
policy = anyimpl::SinglePolicy<T>::get_policy();
238
policy->copy_from_value(&x, &
object);
244
any& operator=(
const
T& x)
250
any& operator=(
const
any& x)
257
any& operator=(
const
char* x)
274
if
(policy->type() !=
typeid(T))
throw
anyimpl::bad_any_cast();
275
T* r =
reinterpret_cast<T*
>(policy->get_value(&
object));
281
const
T& cast()
const
283
if
(policy->type() !=
typeid(T))
throw
anyimpl::bad_any_cast();
284
const
T* r =
reinterpret_cast<
const
T*
>(policy->get_value(&
object));
291
return
policy->type() ==
typeid(anyimpl::empty_any);
297
policy->static_delete(&
object);
298
policy = anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy();
302
bool
compatible(
const
any& x)
const
304
return
policy->type() == x.policy->type();
311
return
policy->type() ==
typeid(T);
314
const
std::type_info& type()
const
316
return
policy->type();
319
friend
std::ostream& operator <<(std::ostream& out,
const
any& any_val);
322
inline
std::ostream& operator <<(std::ostream& out,
const
any& any_val)
324
any_val.policy->print(out,&any_val.object);
CV_EXPORTS void swap(Mat &a, Mat &b)
Swaps two matrices