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.
5 // Copyright (C) 2018-2019 Intel Corporation
8 #ifndef OPENCV_GAPI_GARG_HPP
9 #define OPENCV_GAPI_GARG_HPP
12 #include <type_traits>
14 #include <opencv2/gapi/opencv_includes.hpp>
15 #include "opencv2/gapi/own/mat.hpp"
17 #include "opencv2/gapi/util/any.hpp"
18 #include "opencv2/gapi/util/variant.hpp"
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"
33 using is_garg = std::is_same<GArg, typename std::decay<T>::type>;
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
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))
52 template<typename T, typename std::enable_if<!detail::is_garg<T>::value, int>::type = 0>
54 : kind(detail::GTypeTraits<typename std::decay<T>::type>::kind)
55 , value(detail::wrap_gapi_helper<T>::wrap(t))
59 template<typename T> inline T& get()
61 return util::any_cast<typename std::remove_reference<T>::type>(value);
64 template<typename T> inline const T& get() const
66 return util::any_cast<typename std::remove_reference<T>::type>(value);
69 template<typename T> inline T& unsafe_get()
71 return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
74 template<typename T> inline const T& unsafe_get() const
76 return util::unsafe_any_cast<typename std::remove_reference<T>::type>(value);
79 detail::ArgKind kind = detail::ArgKind::OPAQUE;
85 using GArgs = std::vector<GArg>;
87 // FIXME: Express as M<GProtoArg...>::type
88 // FIXME: Move to a separate file!
89 using GRunArg = util::variant<
90 #if !defined(GAPI_STANDALONE)
94 #endif // !defined(GAPI_STANDALONE)
96 cv::gapi::own::Scalar,
99 using GRunArgs = std::vector<GRunArg>;
101 using GRunArgP = util::variant<
102 #if !defined(GAPI_STANDALONE)
106 #endif // !defined(GAPI_STANDALONE)
108 cv::gapi::own::Scalar*,
109 cv::detail::VectorRef
111 using GRunArgsP = std::vector<GRunArgP>;
114 template<typename... Ts> inline GRunArgs gin(const Ts&... args)
116 return GRunArgs{ GRunArg(detail::wrap_host_helper<Ts>::wrap_in(args))... };
119 template<typename... Ts> inline GRunArgsP gout(Ts&... args)
121 return GRunArgsP{ GRunArgP(detail::wrap_host_helper<Ts>::wrap_out(args))... };
126 #endif // OPENCV_GAPI_GARG_HPP