Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / include / opencv2 / gapi / garg.hpp
1 // This file is part of OpenCV project.
2 // It is subject to the license terms in the LICENSE file found in the top-level directory
3 // of this distribution and at http://opencv.org/license.html.
4 //
5 // Copyright (C) 2018-2019 Intel Corporation
6
7
8 #ifndef OPENCV_GAPI_GARG_HPP
9 #define OPENCV_GAPI_GARG_HPP
10
11 #include <vector>
12 #include <type_traits>
13
14 #include <opencv2/gapi/opencv_includes.hpp>
15 #include "opencv2/gapi/own/mat.hpp"
16
17 #include "opencv2/gapi/util/any.hpp"
18 #include "opencv2/gapi/util/variant.hpp"
19
20 #include "opencv2/gapi/gmat.hpp"
21 #include "opencv2/gapi/gscalar.hpp"
22 #include "opencv2/gapi/garray.hpp"
23 #include "opencv2/gapi/gtype_traits.hpp"
24 #include "opencv2/gapi/gmetaarg.hpp"
25 #include "opencv2/gapi/own/scalar.hpp"
26
27 namespace cv {
28
29 class GArg;
30
31 namespace detail {
32     template<typename T>
33     using is_garg = std::is_same<GArg, typename std::decay<T>::type>;
34 }
35
36 // Parameter holder class for a node
37 // Depending on platform capabilities, can either support arbitrary types
38 // (as `boost::any`) or a limited number of types (as `boot::variant`).
39 // FIXME: put into "details" as a user shouldn't use it in his code
40 class GAPI_EXPORTS GArg
41 {
42 public:
43     GArg() {}
44
45     template<typename T, typename std::enable_if<!detail::is_garg<T>::value, int>::type = 0>
46     explicit GArg(const T &t)
47         : kind(detail::GTypeTraits<T>::kind)
48         , value(detail::wrap_gapi_helper<T>::wrap(t))
49     {
50     }
51
52     template<typename T, typename std::enable_if<!detail::is_garg<T>::value, int>::type = 0>
53     explicit GArg(T &&t)
54         : kind(detail::GTypeTraits<typename std::decay<T>::type>::kind)
55         , value(detail::wrap_gapi_helper<T>::wrap(t))
56     {
57     }
58
59     template<typename T> inline T& get()
60     {
61         return util::any_cast<typename std::remove_reference<T>::type>(value);
62     }
63
64     template<typename T> inline const T& get() const
65     {
66         return util::any_cast<typename std::remove_reference<T>::type>(value);
67     }
68
69     template<typename T> inline T& unsafe_get()
70     {
71         return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
72     }
73
74     template<typename T> inline const T& unsafe_get() const
75     {
76         return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
77     }
78
79     detail::ArgKind kind = detail::ArgKind::OPAQUE;
80
81 protected:
82     util::any value;
83 };
84
85 using GArgs = std::vector<GArg>;
86
87 // FIXME: Express as M<GProtoArg...>::type
88 // FIXME: Move to a separate file!
89 using GRunArg  = util::variant<
90 #if !defined(GAPI_STANDALONE)
91     cv::Mat,
92     cv::Scalar,
93     cv::UMat,
94 #endif // !defined(GAPI_STANDALONE)
95     cv::gapi::own::Mat,
96     cv::gapi::own::Scalar,
97     cv::detail::VectorRef
98     >;
99 using GRunArgs = std::vector<GRunArg>;
100
101 using GRunArgP = util::variant<
102 #if !defined(GAPI_STANDALONE)
103     cv::Mat*,
104     cv::Scalar*,
105     cv::UMat*,
106 #endif // !defined(GAPI_STANDALONE)
107     cv::gapi::own::Mat*,
108     cv::gapi::own::Scalar*,
109     cv::detail::VectorRef
110     >;
111 using GRunArgsP = std::vector<GRunArgP>;
112
113
114 template<typename... Ts> inline GRunArgs gin(const Ts&... args)
115 {
116     return GRunArgs{ GRunArg(detail::wrap_host_helper<Ts>::wrap_in(args))... };
117 }
118
119 template<typename... Ts> inline GRunArgsP gout(Ts&... args)
120 {
121     return GRunArgsP{ GRunArgP(detail::wrap_host_helper<Ts>::wrap_out(args))... };
122 }
123
124 } // namespace cv
125
126 #endif // OPENCV_GAPI_GARG_HPP