source: finroc_plugins_runtime_construction/tPortCreationList.h @ 134:4bc25c8cea06

17.03
Last change on this file since 134:4bc25c8cea06 was 134:4bc25c8cea06, checked in by Max Reichardt <mreichardt@…>, 3 years ago

Adds 'include' mechanism to structure xml files. Tracks info on origins of created elements for this purpose (implementation allows to cleanly remove includes at runtime - and always preserves order of elements).

File size: 9.5 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/runtime_construction/tPortCreationList.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2012-12-02
27 *
28 * \brief   Contains tPortCreationList
29 *
30 * \b tPortCreationList
31 *
32 * List of ports to create.
33 * Is only meant to be used in StaticParameters.
34 * For this reason, it is not real-time capable and a little more memory-efficient.
35 *
36 */
37//----------------------------------------------------------------------
38#ifndef __plugins__runtime_construction__tPortCreationList_h__
39#define __plugins__runtime_construction__tPortCreationList_h__
40
41//----------------------------------------------------------------------
42// External includes (system with <>, local with "")
43//----------------------------------------------------------------------
44#include "plugins/data_ports/tPort.h"
45
46//----------------------------------------------------------------------
47// Internal includes with ""
48//----------------------------------------------------------------------
49#include "plugins/runtime_construction/tDataTypeReference.h"
50#include "plugins/runtime_construction/tOriginData.h"
51
52//----------------------------------------------------------------------
53// Namespace declaration
54//----------------------------------------------------------------------
55namespace finroc
56{
57namespace runtime_construction
58{
59
60//----------------------------------------------------------------------
61// Forward declarations / typedefs / enums
62//----------------------------------------------------------------------
63
64/*! Port Creation options for single ports in port creation list */
65enum class tPortCreateOption
66{
67  OUTPUT, //!< Create an output port?
68  SHARED  //!< Create a shared port?
69};
70
71/*!
72 * Set of port creation options
73 */
74typedef rrlib::util::tEnumBasedFlags<tPortCreateOption, uint8_t> tPortCreateOptions;
75
76constexpr tPortCreateOptions operator | (const tPortCreateOptions& options1, const tPortCreateOptions& options2)
77{
78  return tPortCreateOptions(options1.Raw() | options2.Raw());
79}
80
81constexpr tPortCreateOptions operator | (tPortCreateOption option1, tPortCreateOption option2)
82{
83  return tPortCreateOptions(option1) | tPortCreateOptions(option2);
84}
85
86//----------------------------------------------------------------------
87// Class declaration
88//----------------------------------------------------------------------
89//! Port Creation Data
90/*!
91 * List of ports to create.
92 * Is only meant to be used in StaticParameters.
93 * For this reason, it is not real-time capable and a little more memory-efficient.
94 */
95class tPortCreationList : public rrlib::util::tNoncopyable
96{
97  typedef core::tFrameworkElement::tFlag tFlag;
98  typedef core::tFrameworkElement::tFlags tFlags;
99
100//----------------------------------------------------------------------
101// Public methods and typedefs
102//----------------------------------------------------------------------
103public:
104
105  typedef tOriginData::tOrigin tOrigin;
106
107
108  tPortCreationList();
109
110  /*!
111   * \param port_group Port group that this list is used for editing for
112   * \param flags Flags for port creation
113   * \param selectable_create_options Which creation options should be visible and selectable in finstruct?
114   * \param ports_flagged_finstructed Deal only with ports flagged finstructed?
115   * \param origin Origin for which to create and manage ports (all ports that do no match origin are not touched)
116   */
117  tPortCreationList(core::tFrameworkElement& port_group, tFlags flags,
118                    const tPortCreateOptions& selectable_create_options, bool ports_flagged_finstructed = true, const tOrigin* origin = nullptr);
119
120  tPortCreationList(tPortCreationList &&) = delete;
121  tPortCreationList& operator=(tPortCreationList &&) = delete;
122
123  /*!
124   * Add entry to list
125   *
126   * \param name Port name
127   * \param dt Data type
128   * \param create_options Create options for this port
129   */
130  void Add(const std::string& name, rrlib::rtti::tType dt, const tPortCreateOptions& create_options = tPortCreateOptions());
131
132  /*!
133   * Add entry to list
134   *
135   * \param T Data type
136   * \param name Port name
137   * \param create_options Create options for this port
138   */
139  template <typename T>
140  void Add(const std::string& name, const tPortCreateOptions& create_options = tPortCreateOptions())
141  {
142    Add(name, rrlib::rtti::tDataType<typename data_ports::tPort<T>::tPortBuffer>(), create_options);
143  }
144
145  /*!
146   * Applies changes to another IO vector
147   *
148   * \param io_vector Other io vector
149   * \param flags Flags to use for port creation
150   */
151  void ApplyChanges(core::tFrameworkElement& io_vector, tFlags flags);
152
153  /*!
154   * \return size of list
155   */
156  int GetSize() const;
157
158  /*!
159   * Initially set up list for local operation
160   *
161   * \param managed_io_vector FrameworkElement that list is wrapping
162   * \param port_creation_flags Flags for port creation
163   * \param selectable_create_options Which creation options should be visible and selectable in finstruct?
164   */
165  void InitialSetup(core::tFrameworkElement& managed_io_vector, tFlags port_creation_flags, const tPortCreateOptions& selectable_create_options = tPortCreateOptions());
166
167//----------------------------------------------------------------------
168// Private fields and methods
169//----------------------------------------------------------------------
170private:
171
172  friend rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tPortCreationList& list);
173  friend rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tPortCreationList& list);
174  friend rrlib::xml::tNode& operator << (rrlib::xml::tNode& node, const tPortCreationList& list);
175  friend const rrlib::xml::tNode& operator >> (const rrlib::xml::tNode& node, tPortCreationList& list);
176
177  typedef std::vector<std::pair<tOriginData::tOrder, core::tAbstractPort*>> tGetPortsResult;
178
179  /*!
180   * Entry in list
181   */
182  struct tEntry
183  {
184  public:
185
186    /*! Port name */
187    std::string name;
188
189    /*! Port type - as string (used remote) */
190    tDataTypeReference type;
191
192    /*! Port creation options for this specific port (e.g. output port? shared port?) */
193    tPortCreateOptions create_options;
194
195    tEntry(const std::string& name, const std::string& type, const tPortCreateOptions& create_options);
196
197  };
198
199  /*!
200   * Which creation options should be visible and selectable in finstruct?
201   * (the user can e.g. select whether port is input or output port - or shared)
202   */
203  tPortCreateOptions selectable_create_options;
204
205  /*! List backend (for remote Runtimes) */
206  std::vector<tEntry> list;
207
208  /*! FrameworkElement that list is wrapping (for local Runtimes) */
209  core::tFrameworkElement* io_vector;
210
211  /*! Flags for port creation */
212  tFlags flags;
213
214  /*!
215   * Deal only with ports flagged finstructed? (for local Runtimes)
216   * Created ports will be flagged finstructed. Only ports flagged finstructed will be deleted.
217   * (Used for editable interfaces in groups)
218   */
219  bool ports_flagged_finstructed;
220
221  /*! Origin for which to create and manage ports (all ports that do no match origin are not touched) */
222  const tOrigin* origin;
223
224  /*!
225   * Check whether we need to make adjustments to port
226   *
227   * \param existing_port Port to check
228   * \param io_vector Parent
229   * \param flags Creation flags
230   * \param name New name
231   * \param type new data type
232   * \param create_options Selected create options for port
233   * \param prototype Port prototype (only interesting for listener)
234   * \param index Index for origin data
235   */
236  void CheckPort(core::tAbstractPort* existing_port, core::tFrameworkElement& io_vector, tFlags flags, const std::string& name,
237                 rrlib::rtti::tType type, const tPortCreateOptions& create_options, core::tAbstractPort* prototype, size_t index);
238
239  /*!
240   * Returns all child ports of specified framework element with specified origin
241   *
242   * \param elem Framework Element
243   * \param result List containing result
244   * \param ports_flagged_finstructed Whether to return ports with FINSTRUCTED flag set - or without
245   * \param origin Origin ports must have
246   */
247  static void GetPorts(const core::tFrameworkElement& elem, tGetPortsResult& result, bool ports_flagged_finstructed, const tOrigin* origin);
248};
249
250rrlib::serialization::tOutputStream& operator << (rrlib::serialization::tOutputStream& stream, const tPortCreationList& list);
251rrlib::serialization::tInputStream& operator >> (rrlib::serialization::tInputStream& stream, tPortCreationList& list);
252rrlib::xml::tNode& operator << (rrlib::xml::tNode& node, const tPortCreationList& list);
253const rrlib::xml::tNode& operator >> (const rrlib::xml::tNode& node, tPortCreationList& list);
254
255//----------------------------------------------------------------------
256// End of namespace declaration
257//----------------------------------------------------------------------
258}
259}
260
261
262#endif
Note: See TracBrowser for help on using the repository browser.