source: finroc_plugins_data_ports/common/tAbstractDataPortCreationInfo.h @ 41:eb5957b12387

Last change on this file since 41:eb5957b12387 was 41:eb5957b12387, checked in by Max Reichardt <mreichardt@…>, 6 years ago

Refactored implementation of variadic argument constructors in port wrapper classes.

File size: 7.2 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
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (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
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20//
21//----------------------------------------------------------------------
22/*!\file    plugins/data_ports/common/tAbstractDataPortCreationInfo.h
23 *
24 * \author  Max Reichardt
25 *
26 * \date    2012-10-29
27 *
28 * \brief   Contains tAbstractDataPortCreationInfo
29 *
30 * \b tAbstractDataPortCreationInfo
31 *
32 * This class bundles various parameters for the creation of data ports.
33 *
34 */
35//----------------------------------------------------------------------
36#ifndef __plugins__data_ports__common__tAbstractDataPortCreationInfo_h__
37#define __plugins__data_ports__common__tAbstractDataPortCreationInfo_h__
38
39//----------------------------------------------------------------------
40// External includes (system with <>, local with "")
41//----------------------------------------------------------------------
42#include "core/port/tAbstractPortCreationInfo.h"
43
44//----------------------------------------------------------------------
45// Internal includes with ""
46//----------------------------------------------------------------------
47#include "plugins/data_ports/tBounds.h"
48#include "plugins/data_ports/tQueueSettings.h"
49#include "plugins/data_ports/tUnit.h"
50
51//----------------------------------------------------------------------
52// Namespace declaration
53//----------------------------------------------------------------------
54namespace finroc
55{
56namespace data_ports
57{
58namespace common
59{
60
61//----------------------------------------------------------------------
62// Forward declarations / typedefs / enums
63//----------------------------------------------------------------------
64
65//----------------------------------------------------------------------
66// Class declaration
67//----------------------------------------------------------------------
68//! Bundle of port creation parameters
69/*!
70 * This class bundles various parameters for the creation of data ports.
71 *
72 * Instead of providing suitable constructors for all types of sensible
73 * combinations of the numerous (often optional) construction parameters,
74 * there is only one constructor taking a single argument of this class.
75 */
76class tAbstractDataPortCreationInfo : public core::tAbstractPortCreationInfo
77{
78
79//----------------------------------------------------------------------
80// Public fields and methods
81//----------------------------------------------------------------------
82public:
83
84  /*! Base class */
85  typedef core::tAbstractPortCreationInfo tBase;
86
87  /*! SI Unit of port. NULL for no unit = provides raw numbers */
88  tUnit unit;
89
90  /*! Input Queue size; value <= 0 means flexible size */
91  int max_queue_size;
92
93  /*! Minimum Network update interval; value < 0 => default values */
94  int16_t min_net_update_interval;
95
96  /*! config entry in config file */
97  tString config_entry;
98
99  /*!
100   * Creates port creation info with default values
101   * (Typically, at least flags and name should be set to something sensible)
102   */
103  tAbstractDataPortCreationInfo();
104
105  /*!
106   * \return Have bounds for port been set?
107   */
108  bool BoundsSet() const
109  {
110    return bounds.GetSize() > 0;
111  }
112
113  /*!
114   * \return Has a default value been set?
115   */
116  bool DefaultValueSet() const
117  {
118    return default_value.GetSize() > 0;
119  }
120
121  /*!
122   * \return Bounds (when their exact type is not known at compile time)
123   */
124  const rrlib::serialization::tConstSource& GetBoundsGeneric() const
125  {
126    return bounds;
127  }
128
129  /*!
130   * \return Bounds (when their exact type is not known at compile time)
131   */
132  const rrlib::serialization::tConstSource& GetDefaultGeneric() const
133  {
134    return default_value;
135  }
136
137  /*! Various Set methods for different port properties */
138  void Set(const tQueueSettings& queue_settings)
139  {
140    max_queue_size = queue_settings.GetMaximumQueueLength();
141    flags |= core::tFrameworkElement::tFlag::HAS_QUEUE | core::tFrameworkElement::tFlag::USES_QUEUE;
142    if (queue_settings.DequeueAllQueue())
143    {
144      flags |= core::tFrameworkElement::tFlag::HAS_DEQUEUE_ALL_QUEUE;
145    }
146  }
147
148  void Set(const tUnit& unit)
149  {
150    this->unit = unit;
151  }
152
153  void Set(const tAbstractDataPortCreationInfo& other)
154  {
155    *this = other;
156  }
157
158  /*!
159   * Set bounds when type is not known at compile time
160   *
161   * \param min Minimum value
162   * \param max Maximum value
163   * \param out_of_bounds_action How to proceed if an incoming value is out of bounds
164   */
165  void SetBoundsGeneric(const rrlib::rtti::tGenericObject& min, const rrlib::rtti::tGenericObject& max,
166                        tOutOfBoundsAction out_of_bounds_action = tOutOfBoundsAction::ADJUST_TO_RANGE)
167  {
168    rrlib::serialization::tOutputStream stream(bounds);
169    // critical: needs to be the same serialization as used in tBounds
170    min.Serialize(stream);
171    max.Serialize(stream);
172    stream << out_of_bounds_action;
173  }
174
175  void SetDefaultGeneric(const rrlib::rtti::tGenericObject& default_val)
176  {
177    rrlib::serialization::tOutputStream stream(default_value);
178    default_val.Serialize(stream);
179  }
180
181  /*!
182   * Removes default value from port creation info
183   */
184  void UnsetDefaultValue()
185  {
186    default_value.Clear();
187  }
188
189//----------------------------------------------------------------------
190// Protected classes and fields (used by derived class tPortCreationInfo also)
191//----------------------------------------------------------------------
192protected:
193
194  /*!
195   * Class to store default values and bounds of arbitrary types (in serialized form)
196   */
197  template <size_t INITIAL_SIZE>
198  class tStorage : public rrlib::serialization::tStackMemoryBuffer<INITIAL_SIZE>
199  {
200  public:
201    tStorage() :
202      rrlib::serialization::tStackMemoryBuffer<INITIAL_SIZE>(5, true)
203    {}
204
205    tStorage(const tStorage& o)
206    {
207      this->CopyFrom(o);
208    }
209
210    tStorage& operator=(const tStorage& o)
211    {
212      this->CopyFrom(o);
213      return *this;
214    }
215  };
216
217  /*! Storage for default value */
218  tStorage<150> default_value;
219
220  /*! Storage for bounds */
221  tStorage<300> bounds;
222
223  /*! Has name been set? (we do not check name for zero length, because ports without names may be created) */
224  bool name_set;
225
226
227  /*!
228   * Processes next string argument
229   */
230  void SetString(const tString& s);
231
232//----------------------------------------------------------------------
233// Private fields and methods
234//----------------------------------------------------------------------
235private:
236
237};
238
239//----------------------------------------------------------------------
240// End of namespace declaration
241//----------------------------------------------------------------------
242}
243}
244}
245
246
247#endif
Note: See TracBrowser for help on using the repository browser.