cfg_params.cpp
3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2021 Intel Corporation
#include <opencv2/gapi/util/throw.hpp>
#include <opencv2/gapi/streaming/onevpl/cfg_params.hpp>
namespace cv {
namespace gapi {
namespace wip {
namespace onevpl {
namespace util {
struct variant_comparator : cv::util::static_visitor<bool, variant_comparator> {
variant_comparator(const CfgParam::value_t& rhs_value) :
rhs(rhs_value) {}
template<typename ValueType>
bool visit(const ValueType& lhs) const {
return lhs < cv::util::get<ValueType>(rhs);
}
private:
const CfgParam::value_t& rhs;
};
} // namespace util
struct CfgParam::Priv {
Priv(const std::string& param_name, CfgParam::value_t&& param_value, bool is_major_param) :
name(param_name), value(std::forward<value_t>(param_value)), major_flag(is_major_param) {
}
const CfgParam::name_t& get_name_impl() const {
return name;
}
const CfgParam::value_t& get_value_impl() const {
return value;
}
bool is_major_impl() const {
return major_flag;
}
// comparison implementation
bool operator< (const Priv& rhs) const {
// implement default pair comparison
if (get_name_impl() < rhs.get_name_impl()) {
return true;
} else if (get_name_impl() > rhs.get_name_impl()) {
return false;
}
//TODO implement operator < for cv::util::variant
const CfgParam::value_t& lvar = get_value_impl();
const CfgParam::value_t& rvar = rhs.get_value_impl();
if (lvar.index() < rvar.index()) {
return true;
} else if (lvar.index() > rvar.index()) {
return false;
}
util::variant_comparator comp(rvar);
return cv::util::visit(comp, lvar);
}
bool operator==(const Priv& rhs) const {
return (get_name_impl() == rhs.get_name_impl())
&& (get_value_impl() == rhs.get_value_impl());
}
bool operator!=(const Priv& rhs) const {
return !(*this == rhs);
}
CfgParam::name_t name;
CfgParam::value_t value;
bool major_flag;
};
CfgParam::CfgParam (const std::string& param_name, value_t&& param_value, bool is_major_param) :
m_priv(new Priv(param_name, std::move(param_value), is_major_param)) {
}
CfgParam::~CfgParam() = default;
CfgParam& CfgParam::operator=(const CfgParam& src) {
if (this != &src) {
m_priv = src.m_priv;
}
return *this;
}
CfgParam& CfgParam::operator=(CfgParam&& src) {
if (this != &src) {
m_priv = std::move(src.m_priv);
}
return *this;
}
CfgParam::CfgParam(const CfgParam& src) :
m_priv(src.m_priv) {
}
CfgParam::CfgParam(CfgParam&& src) :
m_priv(std::move(src.m_priv)) {
}
const CfgParam::name_t& CfgParam::get_name() const {
return m_priv->get_name_impl();
}
const CfgParam::value_t& CfgParam::get_value() const {
return m_priv->get_value_impl();
}
bool CfgParam::is_major() const {
return m_priv->is_major_impl();
}
bool CfgParam::operator< (const CfgParam& rhs) const {
return *m_priv < *rhs.m_priv;
}
bool CfgParam::operator==(const CfgParam& rhs) const {
return *m_priv == *rhs.m_priv;
}
bool CfgParam::operator!=(const CfgParam& rhs) const {
return *m_priv != *rhs.m_priv;
}
} // namespace onevpl
} // namespace wip
} // namespace gapi
} // namespace cv