@@ -255,25 +255,27 @@ using Result = Expected<std::monostate>;
255255[[nodiscard]]
256256bool IsAllowedPortName (StringView str);
257257
258- class PortInfo
258+ struct AnyTypeAllowed
259+ {};
260+
261+ class TypeInfo
259262{
260263public:
261- struct AnyTypeAllowed
262- {
263- };
264264
265- PortInfo (PortDirection direction = PortDirection::INOUT) :
266- type_ (direction), type_info_(typeid (AnyTypeAllowed)),
265+ template <typename T>
266+ static TypeInfo Create () {
267+ return TypeInfo{typeid (T), GetAnyFromStringFunctor<T>()};
268+ }
269+
270+ TypeInfo (): type_info_(typeid (AnyTypeAllowed)),
267271 type_str_ (" AnyTypeAllowed" )
268272 {}
269273
270- PortInfo (PortDirection direction, std::type_index type_info, StringConverter conv) :
271- type_ (direction), type_info_(type_info), converter_(conv),
274+ TypeInfo ( std::type_index type_info, StringConverter conv) :
275+ type_info_(type_info), converter_(conv),
272276 type_str_(BT::demangle(type_info))
273277 {}
274278
275- [[nodiscard]] PortDirection direction () const ;
276-
277279 [[nodiscard]] const std::type_index& type () const ;
278280
279281 [[nodiscard]] const std::string& typeName () const ;
@@ -289,6 +291,38 @@ class PortInfo
289291 return {};
290292 }
291293
294+ [[nodiscard]] bool isStronglyTyped () const
295+ {
296+ return type_info_ != typeid (AnyTypeAllowed);
297+ }
298+
299+ [[nodiscard]] const StringConverter& converter () const
300+ {
301+ return converter_;
302+ }
303+
304+ private:
305+
306+ std::type_index type_info_;
307+ StringConverter converter_;
308+ std::string type_str_;
309+ };
310+
311+
312+ class PortInfo : public TypeInfo
313+ {
314+ public:
315+
316+ PortInfo (PortDirection direction = PortDirection::INOUT) :
317+ TypeInfo (), direction_(direction)
318+ {}
319+
320+ PortInfo (PortDirection direction, std::type_index type_info, StringConverter conv) :
321+ TypeInfo (type_info, conv), direction_(direction)
322+ {}
323+
324+ [[nodiscard]] PortDirection direction () const ;
325+
292326 void setDescription (StringView description);
293327
294328 template <typename T>
@@ -306,27 +340,14 @@ class PortInfo
306340
307341 [[nodiscard]] const std::string& defaultValueString () const ;
308342
309- [[nodiscard]] bool isStronglyTyped () const
310- {
311- return type_info_ != typeid (AnyTypeAllowed);
312- }
313-
314- [[nodiscard]] const StringConverter& converter () const
315- {
316- return converter_;
317- }
318-
319343private:
320- PortDirection type_;
321- std::type_index type_info_;
322- StringConverter converter_;
344+ PortDirection direction_;
323345 std::string description_;
324346 Any default_value_;
325347 std::string default_value_str_;
326- std::string type_str_;
327348};
328349
329- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
350+ template <typename T = AnyTypeAllowed> [[nodiscard]]
330351std::pair<std::string, PortInfo> CreatePort (PortDirection direction,
331352 StringView name,
332353 StringView description = {})
@@ -357,28 +378,28 @@ std::pair<std::string, PortInfo> CreatePort(PortDirection direction,
357378}
358379
359380// ----------
360- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
381+ template <typename T = AnyTypeAllowed> [[nodiscard]]
361382inline std::pair<std::string, PortInfo> InputPort (StringView name,
362383 StringView description = {})
363384{
364385 return CreatePort<T>(PortDirection::INPUT, name, description);
365386}
366387
367- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
388+ template <typename T = AnyTypeAllowed> [[nodiscard]]
368389inline std::pair<std::string, PortInfo> OutputPort (StringView name,
369390 StringView description = {})
370391{
371392 return CreatePort<T>(PortDirection::OUTPUT, name, description);
372393}
373394
374- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
395+ template <typename T = AnyTypeAllowed> [[nodiscard]]
375396inline std::pair<std::string, PortInfo> BidirectionalPort (StringView name,
376397 StringView description = {})
377398{
378399 return CreatePort<T>(PortDirection::INOUT, name, description);
379400}
380401// ----------
381- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
402+ template <typename T = AnyTypeAllowed> [[nodiscard]]
382403inline std::pair<std::string, PortInfo> InputPort (StringView name, const T& default_value,
383404 StringView description)
384405{
@@ -387,7 +408,7 @@ inline std::pair<std::string, PortInfo> InputPort(StringView name, const T& defa
387408 return out;
388409}
389410
390- template <typename T = PortInfo:: AnyTypeAllowed> [[nodiscard]]
411+ template <typename T = AnyTypeAllowed> [[nodiscard]]
391412inline std::pair<std::string, PortInfo> BidirectionalPort (StringView name,
392413 const T& default_value,
393414 StringView description)
0 commit comments