source: finroc_plugins_composite_ports/tInterfaceType.h @ 0:fc6a246893ce

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

Initial commit

File size: 5.3 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/tInterfaceType.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2020-02-07
27 *
28 * \brief   Contains tInterfaceType
29 *
30 * \b tInterfaceType
31 *
32 * Port composite interface type for rrlib_rtti.
33 * Needs to be initialized once so that rrlib_rtti knows this interface type
34 * (used similarly to rrlib::rtti::tDataType).
35 *
36 */
37//----------------------------------------------------------------------
38#ifndef __plugins__structure__tInterfaceType_h__
39#define __plugins__structure__tInterfaceType_h__
40
41//----------------------------------------------------------------------
42// External includes (system with <>, local with "")
43//----------------------------------------------------------------------
44#include "core/port/tPortGroup.h"
45#include "rrlib/util/tIntegerSequence.h"
46
47//----------------------------------------------------------------------
48// Internal includes with ""
49//----------------------------------------------------------------------
50#include "plugins/composite_ports/internal/tInterfaceTypeInfo.h"
51#include "plugins/composite_ports/internal/tGenericPortType.h"
52
53//----------------------------------------------------------------------
54// Namespace declaration
55//----------------------------------------------------------------------
56namespace finroc
57{
58namespace composite_ports
59{
60
61//----------------------------------------------------------------------
62// Forward declarations / typedefs / enums
63//----------------------------------------------------------------------
64
65/*!
66 * Port class that is suitable for generic instantiation of any interface
67 */
68template <typename T>
69class tAnyPortType : public internal::tGenericPortType<0, data_ports::tPort, T, false>
70{
71  using internal::tGenericPortType<0, data_ports::tPort, T, false>::tGenericPortType;
72};
73
74//----------------------------------------------------------------------
75// Class declaration
76//----------------------------------------------------------------------
77//! Port composite interface type
78/*!
79 * Port composite interface type for rrlib_rtti.
80 * Needs to be initialized once so that rrlib_rtti knows this interface type
81 * (used similarly to rrlib::rtti::tDataType).
82 */
83template <template <template <typename> class TPrimaryPort, template <typename> class ... TSecondaryPorts> class TInterface>
84class tInterfaceType : public rrlib::rtti::tType
85{
86
87//----------------------------------------------------------------------
88// Public methods and typedefs
89//----------------------------------------------------------------------
90public:
91
92  typedef TInterface<tAnyPortType> tGeneric;
93
94  tInterfaceType() :
95    rrlib::rtti::tType(&cTYPE_INFO)
96  {
97  }
98
99  template <size_t Tchars>
100  tInterfaceType(const char(&name)[Tchars]) :
101    rrlib::rtti::tType(&cTYPE_INFO)
102  {
103    GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name, false), &cTYPE_INFO);
104  }
105
106  template <typename ... TFunctions>
107  tInterfaceType(const std::string& name) :
108    rrlib::rtti::tType(&cTYPE_INFO)
109  {
110    GetSharedInfo().SetName(rrlib::util::tManagedConstCharPointer(name.c_str(), true), &cTYPE_INFO);
111  }
112
113//----------------------------------------------------------------------
114// Private fields and methods
115//----------------------------------------------------------------------
116private:
117
118  /*! Shared Type Info for this type */
119  static internal::tInterfaceTypeInfo shared_info;
120
121  /*! Type info for this type */
122  static constexpr rrlib::rtti::detail::tTypeInfo cTYPE_INFO = { typeid(tGeneric), static_cast<uint>(rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE), &rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO, &rrlib::rtti::detail::tTypeInfo::cNULL_TYPE_INFO, &shared_info, sizeof(tGeneric) };
123
124  /*! Generic create function */
125  static tInterfaceBase Create(const std::string& name, core::tPortGroup* parent)
126  {
127    return tGeneric(name, parent);
128  }
129
130};
131
132
133template <template <template <typename> class TPrimaryPort, template <typename> class ... TSecondaryPorts> class TInterface>
134constexpr rrlib::rtti::detail::tTypeInfo tInterfaceType<TInterface>::cTYPE_INFO;
135
136template <template <template <typename> class TPrimaryPort, template <typename> class ... TSecondaryPorts> class TInterface>
137internal::tInterfaceTypeInfo tInterfaceType<TInterface>::shared_info(&tInterfaceType<TInterface>::cTYPE_INFO, &tInterfaceType<TInterface>::Create, 0);
138
139//----------------------------------------------------------------------
140// End of namespace declaration
141//----------------------------------------------------------------------
142}
143}
144
145#endif
Note: See TracBrowser for help on using the repository browser.