source: finroc_plugins_composite_ports/internal/tTypeInfo.h @ 10:475d7a686fd6

Last change on this file since 10:475d7a686fd6 was 10:475d7a686fd6, checked in by Max Reichardt <mreichardt@…>, 2 years ago

Adds support for inheritance among port composite interfaces (sub and superclass interfaces can be connected). Change also includes that connecting secondary backends (of port composite interfaces with multiple port types) will not connect the primary. This adds more flexibility/convenience w.r.t. connecting only parts of port composite interfaces.

File size: 4.9 KB
Line 
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/internal/tTypeInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2020-03-18
27 *
28 * \brief   Contains tTypeInfo
29 *
30 * \b tTypeInfo
31 *
32 * Holds rrlib_rtti type info for interface types
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __plugins__composite_ports__internal__tTypeInfo_h__
37#define __plugins__composite_ports__internal__tTypeInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42
43//----------------------------------------------------------------------
44// Internal includes with ""
45//----------------------------------------------------------------------
46#include "plugins/composite_ports/internal/tInterfaceTypeInfo.h"
47#include "plugins/composite_ports/internal/tGenericPortType.h"
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace finroc
53{
54namespace composite_ports
55{
56
57template <template <typename> class TPrimaryPort>
58class tInterface;
59class tInterfaceBase;
60
61/*!
62 * Port class that is suitable for generic instantiation of any interface
63 */
64template <typename T>
65class tAnyPortType : public internal::tGenericPortType<0, data_ports::tPort, T, false>
66{
67  using internal::tGenericPortType<0, data_ports::tPort, T, false>::tGenericPortType;
68};
69
70namespace internal
71{
72
73class tEmptyTypeInfo
74{
75public:
76  static constexpr const rrlib::rtti::detail::tTypeInfo& cTYPE_INFO = rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO;
77};
78
79//----------------------------------------------------------------------
80// Forward declarations / typedefs / enums
81//----------------------------------------------------------------------
82
83//----------------------------------------------------------------------
84// Class declaration
85//----------------------------------------------------------------------
86//! Type Info holder
87/*!
88 * Holds rrlib_rtti type info for interface types
89 */
90template <typename TGeneric>
91class tTypeInfo : public std::conditional < (!std::is_same<tInterfaceBase, typename TGeneric::tBase>::value) && (!std::is_same<tInterface<tAnyPortType>, typename TGeneric::tBase>::value), tTypeInfo<typename TGeneric::tBase>, tEmptyTypeInfo >::type
92{
93  typedef typename std::conditional < (!std::is_same<tInterfaceBase, typename TGeneric::tBase>::value) && (!std::is_same<tInterface<tAnyPortType>, typename TGeneric::tBase>::value), tTypeInfo<typename TGeneric::tBase>, tEmptyTypeInfo >::type tBase;
94  enum { cINHERITS_FROM_INTERFACE = !std::is_same<tEmptyTypeInfo, tBase>::value };
95
96public:
97
98  typedef TGeneric tGeneric;
99
100  /*! Shared Type Info for this type */
101  static tInterfaceTypeInfo shared_info;
102
103  /*! Type info for this type */
104  static constexpr rrlib::rtti::detail::tTypeInfo cTYPE_INFO = { typeid(tGeneric), static_cast<uint>(rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE) | (cINHERITS_FROM_INTERFACE ? (rrlib::rtti::trait_flags::cHAS_UNDERLYING_TYPE | rrlib::rtti::trait_flags::cIS_CAST_TO_UNDERLYING_TYPE_IMPLICIT | rrlib::rtti::trait_flags::cIS_REINTERPRET_CAST_FROM_UNDERLYING_TYPE_VALID | rrlib::rtti::trait_flags::cIS_CAST_FROM_UNDERLYING_TYPE_IMPLICIT) : 0), &tBase::cTYPE_INFO, &rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(tGeneric) };
105
106  /*! Generic create function */
107  static tInterfaceBase Create(const std::string& name, core::tPortGroup* parent)
108  {
109    return tGeneric(name, parent);
110  }
111};
112
113template <typename TGeneric>
114constexpr rrlib::rtti::detail::tTypeInfo tTypeInfo<TGeneric>::cTYPE_INFO;
115
116template <typename TGeneric>
117tInterfaceTypeInfo tTypeInfo<TGeneric>::shared_info(&tTypeInfo<TGeneric>::cTYPE_INFO, &tTypeInfo<TGeneric>::Create, 0);
118
119
120//----------------------------------------------------------------------
121// End of namespace declaration
122//----------------------------------------------------------------------
123}
124}
125}
126
127
128#endif
Note: See TracBrowser for help on using the repository browser.