5 #include <tbb/flow_graph.h> 6 #include <boost/any.hpp> 34 MockSource(
int maxcount = 10) : m_count(0), m_maxcount(maxcount) {}
38 cerr <<
"Source: " << m_count <<
endl;
39 if (m_count > m_maxcount) {
40 cerr <<
"ModeSource drained\n";
54 virtual bool insert(boost::any& anyin) {
55 int num = boost::any_cast<
int>(anyin);
56 m_numbers.push_back(num);
59 virtual bool extract(boost::any& anyout) {
60 if (m_numbers.empty()) {
63 anyout = m_numbers.front();
64 m_numbers.pop_front();
73 virtual bool insert(
const boost::any& anyin) {
74 int num = boost::any_cast<
int>(anyin);
75 cerr <<
"Sunk number " << num <<
endl;
85 if (node_desc ==
"source") {
88 if (node_desc ==
"drift") {
91 if (node_desc ==
"sink") {
124 typedef std::shared_ptr<TbbNodeWrapper>
TbbNode;
135 m_wcnode = std::dynamic_pointer_cast<
MockSource>(wcnode);
139 cerr <<
"TbbSourceBody copied\n";
146 cerr <<
"TbbSourceBody assigned\n";
151 cerr <<
"Extracting from " << m_wcnode <<
endl;
152 return m_wcnode->extract(out);
167 cerr <<
"Activating source node\n";
168 m_tbbnode->activate();
191 m_wcnode = std::dynamic_pointer_cast<
MockSink>(wcnode);
195 cerr <<
"TbbSinkBody copied\n";
202 cerr <<
"TbbSinkBody assigned\n";
207 cerr <<
"Inserting to " << m_wcnode <<
endl;
208 m_wcnode->insert(in);
240 cerr <<
"Failed to get node for " << node_desc <<
endl;
244 cerr <<
"Getting node from category: " << wcnode->category() <<
endl;
245 switch (wcnode->category()) {
263 auto sports = sender->sender_ports();
264 auto rports = receiver->receiver_ports();
266 Assert(sports.size() > sport);
267 Assert(rports.size() > rport);
274 cerr <<
"Connecting " << s <<
" and " << r <<
endl;
290 source->initialize();
293 graph.wait_for_all();
virtual bool extract(boost::any &anyout)
std::vector< receiver_port_pointer > receiver_port_vector
bool connect(TbbNode sender, TbbNode receiver, size_t sport=0, size_t rport=0)
mock_node_pointer get_node(const std::string &node_desc)
const CharType(& source)[N]
std::shared_ptr< sink_node > m_tbbnode
void operator=(const TbbSinkBody &other)
TbbNode make_node(tbb::flow::graph &graph, const std::string &node_desc)
virtual receiver_port_vector receiver_ports()
TbbSinkBody(const TbbSinkBody &other)
void operator=(const TbbSourceBody &other)
boost::any operator()(const boost::any &in)
def graph(desc, maker=maker)
virtual void initialize()
TbbSourceBody(const TbbSourceBody &other)
std::vector< sender_port_pointer > sender_port_vector
virtual bool insert(const boost::any &anyin)
virtual sender_port_vector sender_ports()
virtual sender_port_vector sender_ports()
virtual int concurrency()
std::shared_ptr< sender_type > sender_port_pointer
std::shared_ptr< source_node > m_tbbnode
TbbSinkNodeWrapper(tbb::flow::graph &graph, mock_node_pointer wcnode)
std::shared_ptr< receiver_type > receiver_port_pointer
TbbSinkBody(mock_node_pointer wcnode)
virtual NodeCategory category()
virtual bool extract(boost::any &out)
bool operator()(boost::any &out)
virtual ~TbbNodeWrapper()
virtual void initialize()
std::deque< int > m_numbers
virtual NodeCategory category()
MockSource(int maxcount=10)
std::shared_ptr< MockSink > m_wcnode
virtual NodeCategory category()
tbb::flow::function_node< boost::any > sink_node
std::shared_ptr< MockNode > mock_node_pointer
TbbSourceNodeWrapper(tbb::flow::graph &graph, mock_node_pointer wcnode)
tbb::flow::sender< boost::any > sender_type
tbb::flow::receiver< boost::any > receiver_type
std::shared_ptr< TbbNodeWrapper > TbbNode
virtual bool insert(boost::any &anyin)
TbbSourceBody(mock_node_pointer wcnode)
tbb::flow::source_node< boost::any > source_node
QTextStream & endl(QTextStream &s)
virtual receiver_port_vector receiver_ports()
std::shared_ptr< MockSource > m_wcnode