Pothos  0.7.0-gf7fbae99
The Pothos dataflow programming software suite
TopologyImpl.hpp
Go to the documentation of this file.
1 
11 #pragma once
14 #include <type_traits> //enable_if
15 
16 namespace Pothos {
17 
18 class Block; //forward declare for templates below
19 class Proxy; //forward declare for templates below
20 
21 namespace Detail {
22 
23 /***********************************************************************
24  * templated conversions for connectable objects - blocks
25  **********************************************************************/
26 template <typename T>
27 typename std::enable_if<std::is_base_of<Block, T>::value, Pothos::Object>::type
28 connObjToObject(T &value)
29 {
30  return Pothos::Object(&static_cast<Block &>(value));
31 }
32 
33 template <typename T>
34 typename std::enable_if<std::is_base_of<Block, T>::value, Pothos::Object>::type
35 connObjToObject(T *value)
36 {
37  return Pothos::Object(static_cast<Block *>(value));
38 }
39 
40 template <typename T>
41 typename std::enable_if<std::is_base_of<Block, T>::value, Pothos::Object>::type
42 connObjToObject(std::shared_ptr<T> value)
43 {
44  return Pothos::Object(std::static_pointer_cast<Block>(value));
45 }
46 
47 /***********************************************************************
48  * templated conversions for connectable objects - topologies
49  **********************************************************************/
50 template <typename T>
51 typename std::enable_if<std::is_base_of<Topology, T>::value, Pothos::Object>::type
52 connObjToObject(T &value)
53 {
54  return Pothos::Object(&static_cast<Topology &>(value));
55 }
56 
57 
58 template <typename T>
59 typename std::enable_if<std::is_base_of<Topology, T>::value, Pothos::Object>::type
60 connObjToObject(T *value)
61 {
62  return Pothos::Object(static_cast<Topology *>(value));
63 }
64 
65 template <typename T>
66 typename std::enable_if<std::is_base_of<Topology, T>::value, Pothos::Object>::type
67 connObjToObject(std::shared_ptr<T> value)
68 {
69  return Pothos::Object(std::static_pointer_cast<Topology>(value));
70 }
71 
72 /***********************************************************************
73  * templated conversions for connectable objects - proxies
74  **********************************************************************/
75 template <typename T>
76 typename std::enable_if<std::is_same<Proxy, T>::value, Pothos::Object>::type
77 connObjToObject(const T &value)
78 {
79  return Pothos::Object(value);
80 }
81 
82 /***********************************************************************
83  * templated conversions for port names
84  **********************************************************************/
85 template <typename T>
86 typename std::enable_if<std::is_integral<T>::value, std::string>::type
87 portNameToStr(const T &value)
88 {
89  return std::to_string(value);
90 }
91 
92 template <typename T>
93 typename std::enable_if<!std::is_integral<T>::value, std::string>::type
94 portNameToStr(const T &value)
95 {
96  return std::string(value);
97 }
98 
99 } //namespace Detail
100 } //namespace Pothos
101 
102 /***********************************************************************
103  * templated implementation for connect and disconnect
104  **********************************************************************/
105 template <
106  typename SrcType, typename SrcPortType,
107  typename DstType, typename DstPortType>
109  SrcType &&src, const SrcPortType &srcPort,
110  DstType &&dst, const DstPortType &dstPort)
111 {
112  this->_connect(
113  Detail::connObjToObject(src), Detail::portNameToStr(srcPort),
114  Detail::connObjToObject(dst), Detail::portNameToStr(dstPort));
115 }
116 
117 template <
118  typename SrcType, typename SrcPortType,
119  typename DstType, typename DstPortType>
121  SrcType &&src, const SrcPortType &srcPort,
122  DstType &&dst, const DstPortType &dstPort)
123 {
124  this->_disconnect(
125  Detail::connObjToObject(src), Detail::portNameToStr(srcPort),
126  Detail::connObjToObject(dst), Detail::portNameToStr(dstPort));
127 }
Definition: ArchiveEntry.hpp:20
void connect(SrcType &&src, const SrcPortType &srcPort, DstType &&dst, const DstPortType &dstPort)
Definition: TopologyImpl.hpp:108
Definition: Object.hpp:47
void disconnect(SrcType &&src, const SrcPortType &srcPort, DstType &&dst, const DstPortType &dstPort)
Definition: TopologyImpl.hpp:120