Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / fluid / modules / gapi / include / opencv2 / gapi / gproto.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_GPROTO_HPP
9 #define OPENCV_GAPI_GPROTO_HPP
10
11 #include <type_traits>
12 #include <vector>
13 #include <ostream>
14
15 #include "opencv2/gapi/util/variant.hpp"
16
17 #include "opencv2/gapi/gmat.hpp"
18 #include "opencv2/gapi/gscalar.hpp"
19 #include "opencv2/gapi/garray.hpp"
20 #include "opencv2/gapi/garg.hpp"
21 #include "opencv2/gapi/gmetaarg.hpp"
22
23 namespace cv {
24
25 // FIXME: user shouldn't deal with it - put to detail?
26 // GProtoArg is an union type over G-types which can serve as
27 // GComputation's in/output slots. In other words, GProtoArg
28 // wraps any type which can serve as G-API exchange type.
29 //
30 // In Runtime, GProtoArgs are substituted with appropriate GRunArgs.
31 //
32 // GProtoArg objects are constructed in-place when user describes
33 // (captures) computations, user doesn't interact with these types
34 // directly.
35 using GProtoArg = util::variant
36     < GMat
37     , GScalar
38     , detail::GArrayU // instead of GArray<T>
39     >;
40
41 using GProtoArgs = std::vector<GProtoArg>;
42
43 namespace detail
44 {
45 template<typename... Ts> inline GProtoArgs packArgs(Ts... args)
46 {
47     return GProtoArgs{ GProtoArg(wrap_gapi_helper<Ts>::wrap(args))... };
48 }
49
50 }
51
52 template<class Tag>
53 struct GIOProtoArgs
54 {
55 public:
56     explicit GIOProtoArgs(const GProtoArgs& args) : m_args(args) {}
57     explicit GIOProtoArgs(GProtoArgs &&args)      : m_args(std::move(args)) {}
58
59     GProtoArgs m_args;
60 };
61
62 struct In_Tag{};
63 struct Out_Tag{};
64
65 using GProtoInputArgs  = GIOProtoArgs<In_Tag>;
66 using GProtoOutputArgs = GIOProtoArgs<Out_Tag>;
67
68 // Perfect forwarding
69 template<typename... Ts> inline GProtoInputArgs GIn(Ts&&... ts)
70 {
71     return GProtoInputArgs(detail::packArgs(std::forward<Ts>(ts)...));
72 }
73
74 template<typename... Ts> inline GProtoOutputArgs GOut(Ts&&... ts)
75 {
76     return GProtoOutputArgs(detail::packArgs(std::forward<Ts>(ts)...));
77 }
78
79 // Extract run-time arguments from node origin
80 // Can be used to extract constant values associated with G-objects
81 // (like GScalar) at graph construction time
82 GRunArg value_of(const GOrigin &origin);
83
84 // Transform run-time computation arguments into a collection of metadata
85 // extracted from that arguments
86 GMetaArg  GAPI_EXPORTS descr_of(const GRunArg  &arg );
87 GMetaArgs GAPI_EXPORTS descr_of(const GRunArgs &args);
88
89 // Transform run-time operation result argument into metadata extracted from that argument
90 // Used to compare the metadata, which generated at compile time with the metadata result operation in run time
91 GMetaArg  GAPI_EXPORTS descr_of(const GRunArgP& argp);
92
93
94 } // namespace cv
95
96 #endif // OPENCV_GAPI_GPROTO_HPP