Classes | Functions
test_faninout.cxx File Reference
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/Faninout.h"
#include <boost/signals2.hpp>
#include <boost/optional.hpp>
#include <iostream>
#include <vector>

Go to the source code of this file.

Classes

struct  Counter
 
struct  Echoer
 
struct  Consumer
 moved to templated version in Faninout.h More...
 

Functions

void test_plug_and_play ()
 
void test_ref ()
 
void test_fanout_addressing ()
 
int test_fanin ()
 
int main ()
 

Function Documentation

int main ( void  )

Definition at line 145 of file test_faninout.cxx.

146 {
148  test_ref();
150  test_fanin();
151  return 0;
152 }
int test_fanin()
void test_fanout_addressing()
void test_plug_and_play()
void test_ref()
int test_fanin ( )

Definition at line 121 of file test_faninout.cxx.

122 {
123  Counter c1(10),c2(20),c3(30);
124 
125  // Fan-in concept is inherent in boost::signals2, but does require
126  // some "combiner" to enact whatever fan-in policy is desired.
127  // This one synchronizes input into a collection.
128  boost::signals2::signal< int (), Fanin< std::vector<int> > > sig;
129  sig.connect(c1);
130  sig.connect(c2);
131  sig.connect(c3);
132 
133  for (int ind=0; ind<10; ++ind) {
134  auto vec = sig();
135  cerr << ind;
136  for (auto x: vec) {
137  cerr << " " << x;
138  }
139  cerr << endl;
140  }
141 
142  return 0;
143 }
list x
Definition: train.py:276
QTextStream & endl(QTextStream &s)
void test_fanout_addressing ( )

Definition at line 94 of file test_faninout.cxx.

95 {
96  Counter counter;
97  Fanout<int> fanout;
98  fanout.address(0);
99  fanout.address(1);
100  fanout.connect(counter);
101 
102 
103  Addresser<int> addr0(0), addr1(1);
104  addr0.connect(boost::ref(fanout));
105  addr1.connect(boost::ref(fanout));
106 
107  Consumer consumer0, consumer1;
108  consumer0.sig.connect(boost::ref(addr0));
109  consumer1.sig.connect(boost::ref(addr1));
110 
111  cerr << consumer1() << endl;
112  cerr << consumer0() << endl;
113  cerr << consumer0() << endl;
114  cerr << consumer0() << endl;
115  cerr << consumer1() << endl;
116  cerr << consumer0() << endl;
117 
118 }
moved to templated version in Faninout.h
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
signal sig
void address(const address_type &addr)
Register an address.
Definition: Faninout.h:31
void connect(const slot &s)
Definition: Faninout.h:28
QTextStream & endl(QTextStream &s)
void test_plug_and_play ( )

Definition at line 55 of file test_faninout.cxx.

56 {
57  Counter counter;
58  Fanout<int> fanout;
59  fanout.connect(counter);
60 
61  int addresses[] = {1,2,3,0,0,0,2,4,4,4,4,4,1,1,2,1,1,-1};
62  int want_val[] = {0,1,2,3,4,5,2,0,1,2,3,4,1,2,3,3,4,-1};
63 
64  // pre-register
65  fanout.address(4);
66 
67  for (int ind=0; addresses[ind] >= 0; ++ind) {
68  int addr = addresses[ind];
69  if (addr < 0) { break; }
70  int want = want_val[ind];
71  int got = fanout(addr);
72  cerr << "addr=" << addr << " got:" << got << " want:" << want << endl;
73  Assert(want == got);
74  }
75 
76 }
#define Assert
Definition: Testing.h:7
auto counter(T begin, T end)
Returns an object to iterate values from begin to end in a range-for loop.
Definition: counter.h:285
void address(const address_type &addr)
Register an address.
Definition: Faninout.h:31
constexpr std::enable_if_t< are_cv_compatible< TO, FROM >::value, std::add_pointer_t< std::remove_pointer_t< TO > > > addr(FROM &from)
Definition: ensurePointer.h:35
void connect(const slot &s)
Definition: Faninout.h:28
QTextStream & endl(QTextStream &s)
void test_ref ( )

Definition at line 78 of file test_faninout.cxx.

79 {
80  Echoer echo;
81 
82  Addresser<int> addr0(0), addr1(1);
83  addr0.connect(echo);
84  addr1.connect(echo);
85 
86  Consumer consumer0, consumer1;
87  consumer0.sig.connect(boost::ref(addr0));
88  consumer1.sig.connect(boost::ref(addr1));
89 
90  cerr << consumer0() << endl;
91  cerr << consumer1() << endl;
92 }
moved to templated version in Faninout.h
signal sig
QTextStream & endl(QTextStream &s)