source: finroc_plugins_composite_ports/internal/tInterfaceTypeInfo.h @ 28:0d9e9fd957de

Last change on this file since 28:0d9e9fd957de was 23:3c9cac2a0cc1, checked in by Max Reichardt <mreichardt@…>, 23 months ago

Adds 'interface modifiers' for customization of port composite interface creation (as there are diverse use cases). Refactors and tidies partial interface creation with this new feature.

File size: 5.4 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/tInterfaceTypeInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2020-02-07
27 *
28 * \brief   Contains tInterfaceTypeInfo
29 *
30 * \b tInterfaceTypeInfo
31 *
32 * Internal type info for port composite interface types
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __plugins__structure__internal__tInterfaceTypeInfo_h__
37#define __plugins__structure__internal__tInterfaceTypeInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "core/port/tPortGroup.h"
43
44//----------------------------------------------------------------------
45// Internal includes with ""
46//----------------------------------------------------------------------
47#include "plugins/composite_ports/tInterfaceBase.h"
48
49//----------------------------------------------------------------------
50// Namespace declaration
51//----------------------------------------------------------------------
52namespace finroc
53{
54namespace composite_ports
55{
56namespace internal
57{
58
59//----------------------------------------------------------------------
60// Forward declarations / typedefs / enums
61//----------------------------------------------------------------------
62
63class tInterfaceFactory;
64
65/*!
66 * \param Framework element to check
67 * \return Whether framework element is a component
68 */
69bool IsComponent(const core::tFrameworkElement* element);
70
71//----------------------------------------------------------------------
72// Class declaration
73//----------------------------------------------------------------------
74//! Port composite interface type info
75/*!
76 * Internal type info for port composite interface types
77 */
78class tInterfaceTypeInfo : public rrlib::rtti::detail::tTypeInfo::tSharedInfo
79{
80
81//----------------------------------------------------------------------
82// Public methods and typedefs
83//----------------------------------------------------------------------
84public:
85
86  typedef tInterfaceBase(*tCreateFunction)(const std::string& name, core::tPortGroup* parent);
87
88  tInterfaceTypeInfo(const rrlib::rtti::detail::tTypeInfo* type_info, tCreateFunction create_function, int auto_registered, bool create_partial_type, const std::type_info& partial_type_info);
89
90  tInterfaceTypeInfo(const rrlib::rtti::detail::tTypeInfo* type_info, tCreateFunction create_function, rrlib::util::tManagedConstCharPointer name) :
91    tSharedInfo(type_info, std::move(name), nullptr, 0),
92    create_function(create_function)
93  {}
94
95  ~tInterfaceTypeInfo();
96
97  /*!
98   * \return Create function for this interface type (generic instance)
99   */
100  tCreateFunction CreateFunction() const
101  {
102    return create_function;
103  }
104
105  /*!
106   * \return Returns type info for (non-generic) interface of type TInterface
107   */
108  template <typename TInterface>
109  static rrlib::rtti::tType FindType()
110  {
111    auto name = GenerateName(typeid(TInterface).name());
112    rrlib::rtti::tType type = rrlib::rtti::tType::FindType(name.Get());
113    return type.GetTypeClassification() == rrlib::rtti::tTypeClassification::PORT_COMPOSITE_INTERFACE ? type : rrlib::rtti::tType();
114  }
115
116  /*!
117   * \return Full type of interface
118   */
119  rrlib::rtti::tType GetFullType() const
120  {
121    return rrlib::rtti::tType(type_info_full);
122  }
123
124  /*!
125   * \return Partial type in case this interface type has one
126   */
127  rrlib::rtti::tType GetPartialType() const
128  {
129    return type_info_partial ? rrlib::rtti::tType(type_info_partial) : rrlib::rtti::tType();
130  }
131
132//----------------------------------------------------------------------
133// Private fields and methods
134//----------------------------------------------------------------------
135private:
136
137  /*! Create function for this interface type (generic instance) */
138  tCreateFunction create_function;
139
140  /*! Pointer to partial type info in case this interface type has a partial type info (created and deleted by this class) */
141  rrlib::rtti::detail::tTypeInfo* type_info_partial = nullptr;
142
143  /*! Pointer to full type info (possibly relevant if this interface type has a partial type info) */
144  const rrlib::rtti::detail::tTypeInfo* type_info_full = nullptr;
145
146  /*! Generates interface type name from rtti name */
147  static rrlib::util::tManagedConstCharPointer GenerateName(const char* rtti_name);
148};
149
150//----------------------------------------------------------------------
151// End of namespace declaration
152//----------------------------------------------------------------------
153}
154}
155}
156
157
158#endif
Note: See TracBrowser for help on using the repository browser.