1 | // |
---|
2 | // You received this file as part of Finroc |
---|
3 | // A framework for intelligent robot control |
---|
4 | // |
---|
5 | // Copyright (C) Finroc GbR (finroc.org) |
---|
6 | // |
---|
7 | // This program is free software; you can redistribute it and/or modify |
---|
8 | // it under the terms of the GNU General Public License as published by |
---|
9 | // the Free Software Foundation; either version 2 of the License, or |
---|
10 | // (at your option) any later version. |
---|
11 | // |
---|
12 | // This program is distributed in the hope that it will be useful, |
---|
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | // GNU General Public License for more details. |
---|
16 | // |
---|
17 | // You should have received a copy of the GNU General Public License along |
---|
18 | // with this program; if not, write to the Free Software Foundation, Inc., |
---|
19 | // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
---|
20 | // |
---|
21 | //---------------------------------------------------------------------- |
---|
22 | /*!\file plugins/composite_ports/tInterface.h |
---|
23 | * |
---|
24 | * \author Max Reichardt |
---|
25 | * |
---|
26 | * \date 2020-01-02 |
---|
27 | * |
---|
28 | * \brief Contains tInterface |
---|
29 | * |
---|
30 | * \b tInterface |
---|
31 | * |
---|
32 | * Base class for port composite interfaces (interfaces consisting of a set of ports) |
---|
33 | * |
---|
34 | */ |
---|
35 | //---------------------------------------------------------------------- |
---|
36 | #ifndef __plugins__structure__tInterface_h__ |
---|
37 | #define __plugins__structure__tInterface_h__ |
---|
38 | |
---|
39 | //---------------------------------------------------------------------- |
---|
40 | // External includes (system with <>, local with "") |
---|
41 | //---------------------------------------------------------------------- |
---|
42 | #include "rrlib/util/tTypeList.h" |
---|
43 | #include "core/port/tPortGroup.h" |
---|
44 | |
---|
45 | //---------------------------------------------------------------------- |
---|
46 | // Internal includes with "" |
---|
47 | //---------------------------------------------------------------------- |
---|
48 | #include "plugins/composite_ports/internal/type_traits.h" |
---|
49 | #include "plugins/composite_ports/tInterfaceType.h" |
---|
50 | #include "plugins/composite_ports/internal/tGenericPortType.h" |
---|
51 | |
---|
52 | //---------------------------------------------------------------------- |
---|
53 | // Namespace declaration |
---|
54 | //---------------------------------------------------------------------- |
---|
55 | namespace finroc |
---|
56 | { |
---|
57 | |
---|
58 | //---------------------------------------------------------------------- |
---|
59 | // Forward declarations / typedefs / enums |
---|
60 | //---------------------------------------------------------------------- |
---|
61 | |
---|
62 | namespace structure |
---|
63 | { |
---|
64 | class tComponent; |
---|
65 | } |
---|
66 | |
---|
67 | namespace composite_ports |
---|
68 | { |
---|
69 | |
---|
70 | namespace port_relation |
---|
71 | { |
---|
72 | |
---|
73 | template <template <typename T> class TPortType> |
---|
74 | using tInput = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_INPUT, TPortType, internal::MakeInputPort>; |
---|
75 | template <template <typename> class TPortType> |
---|
76 | using tOutput = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_OUTPUT, TPortType, internal::MakeOutputPort>; |
---|
77 | template <template <typename> class TPortType> |
---|
78 | using tParameter = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_PARAMETER, TPortType, internal::MakeParameter>; |
---|
79 | template <template <typename> class TPortType> |
---|
80 | using tCounterPart = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_COUNTER_PART, TPortType, internal::MakeCounterPart>; |
---|
81 | template <template <typename> class TPortType> |
---|
82 | using tCounterPartParameterInputs = typename internal::PrimaryPortRelation<internal::tPortTypeRelation::ePTR_COUNTER_PART_PARAMETER_IF_INPUT, TPortType, internal::MakeCounterPartParameterIfInput>; //::template base_port; |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | //---------------------------------------------------------------------- |
---|
87 | // Class declaration |
---|
88 | //---------------------------------------------------------------------- |
---|
89 | //! Port composite interface template base class |
---|
90 | /*! |
---|
91 | * Base class for port composite interfaces (interfaces consisting of a set of ports) |
---|
92 | */ |
---|
93 | template <template <typename> class TPrimaryPort> |
---|
94 | class tInterface : public tInterfaceBase |
---|
95 | { |
---|
96 | enum { cCONVENIENCE_PORT = std::is_base_of<structure::tConveniencePortBase, TPrimaryPort<double>>::value }; |
---|
97 | //enum { cGENERIC_INSTANCE = std::is_same<TPrimaryPort<double>, internal::tGenericPortType<0, double, false>>::value }; |
---|
98 | enum { cPRIMARY_RELATION_ID = internal::GetRelationId<TPrimaryPort<double>>::value }; |
---|
99 | |
---|
100 | //---------------------------------------------------------------------- |
---|
101 | // Public methods and typedefs |
---|
102 | //---------------------------------------------------------------------- |
---|
103 | public: |
---|
104 | |
---|
105 | typedef typename std::conditional<cCONVENIENCE_PORT, structure::tComponent*, core::tPortGroup*>::type tParent; |
---|
106 | |
---|
107 | //---------------------------------------------------------------------- |
---|
108 | // Protected methods |
---|
109 | //---------------------------------------------------------------------- |
---|
110 | protected: |
---|
111 | |
---|
112 | tInterface() : |
---|
113 | tInterfaceBase(nullptr) |
---|
114 | {} |
---|
115 | |
---|
116 | /*! |
---|
117 | * \param interface_type Interface type |
---|
118 | * \param parent Parent (component for convenience ports as template arguments - and port group(s) otherwise) |
---|
119 | * \param name Name of interface (must be unique in parent) |
---|
120 | * \param port_type_relation If this port composite interface has multiple data port types, specifies how they are typically related (relevant for generic instantiation) |
---|
121 | * \param custom_connect_function Custom connect function for this interface |
---|
122 | */ |
---|
123 | tInterface(const rrlib::rtti::tType& interface_type, tParent parent, const std::string& name, const tConnectFunction& custom_connect_function = tConnectFunction()) : |
---|
124 | tInterfaceBase(new tInterfaceBase::tBackend(interface_type, parent, GetPrimaryPortTypeParent(parent), cPRIMARY_RELATION_ID, name, cCONVENIENCE_PORT, custom_connect_function, GetDefaultCreateMissingInterfaceFunction(parent))) |
---|
125 | { |
---|
126 | } |
---|
127 | |
---|
128 | /*! |
---|
129 | * (Constructor for other port composite interface as parent) |
---|
130 | * |
---|
131 | * \param interface_type Interface type |
---|
132 | * \param parent Parent port composite interface |
---|
133 | * \param name Name of interface (must be unique in parent) |
---|
134 | * \param custom_connect_function Custom connect function for this interface |
---|
135 | */ |
---|
136 | template <typename TParent, bool Tenable = std::is_base_of<tInterfaceBase, typename std::decay<TParent>::type>::value> |
---|
137 | tInterface(typename std::enable_if<Tenable, const rrlib::rtti::tType&>::type interface_type, TParent* parent, const std::string& name, const tConnectFunction& custom_connect_function = tConnectFunction()) : |
---|
138 | tInterfaceBase(parent->Backend() ? new tInterfaceBase::tBackend(interface_type, cCONVENIENCE_PORT ? parent->ParentComponent() : parent->Backend(), parent->Backend()->GetBackend(cPRIMARY_RELATION_ID), cPRIMARY_RELATION_ID, name, cCONVENIENCE_PORT, custom_connect_function) : nullptr) |
---|
139 | { |
---|
140 | } |
---|
141 | |
---|
142 | /*! Helper constructor to extract interface type */ |
---|
143 | tInterface(const rrlib::rtti::tType& interface_type, tInterfaceTypeData* parent, const std::string& name, const tConnectFunction& custom_connect_function = tConnectFunction()) : |
---|
144 | tInterfaceBase() |
---|
145 | { |
---|
146 | parent->type = interface_type; |
---|
147 | } |
---|
148 | |
---|
149 | //---------------------------------------------------------------------- |
---|
150 | // Private fields and methods |
---|
151 | //---------------------------------------------------------------------- |
---|
152 | private: |
---|
153 | |
---|
154 | template <template <typename> class UPrimaryPort> |
---|
155 | friend class tInterface; |
---|
156 | |
---|
157 | template <int Tconvenience_port = cCONVENIENCE_PORT> |
---|
158 | static core::tFrameworkElement* GetPrimaryPortTypeParent(typename std::enable_if<Tconvenience_port, tParent>::type parent) |
---|
159 | { |
---|
160 | return &TPrimaryPort<double>::GetParentInterface(static_cast<typename TPrimaryPort<double>::tComponent&>(*parent)); |
---|
161 | } |
---|
162 | |
---|
163 | static core::tFrameworkElement* GetPrimaryPortTypeParent(core::tPortGroup* parent) |
---|
164 | { |
---|
165 | return parent; |
---|
166 | } |
---|
167 | |
---|
168 | template <int Tconvenience_port = cCONVENIENCE_PORT> |
---|
169 | static constexpr tCreateMissingComponentInterfaceFunction GetDefaultCreateMissingInterfaceFunction(typename std::enable_if<Tconvenience_port, tParent>::type parent) |
---|
170 | { |
---|
171 | return tInterfaceBase::GetDefaultCreateMissingInterfaceFunction<typename TPrimaryPort<double>::tComponent>(); |
---|
172 | } |
---|
173 | static constexpr tCreateMissingComponentInterfaceFunction GetDefaultCreateMissingInterfaceFunction(core::tPortGroup* parent) |
---|
174 | { |
---|
175 | return nullptr; |
---|
176 | } |
---|
177 | |
---|
178 | }; |
---|
179 | |
---|
180 | //---------------------------------------------------------------------- |
---|
181 | // End of namespace declaration |
---|
182 | //---------------------------------------------------------------------- |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | #endif |
---|