-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiconnection.cpp
54 lines (44 loc) · 1.96 KB
/
multiconnection.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <algorithm>
#include <utility>
#include "core/manager.hpp"
#include "multiconnection.hpp"
#include "core/properties.hpp"
#include "utility_stream.hpp"
using namespace std;
namespace sc {
static PropertyKey const inputsProperty( "inputs" );
MultiConnection::MultiConnection( string&& id, Manager& manager, PropertyNode const& properties )
: Component( move( id ) )
, Output( manager, properties[ inputsProperty ], multipleInputs )
, channels_(
( *max_element(
inputs().begin(), inputs().end(),
[]( auto const& a, auto const& b ) { return a->emitsChannels() < b->emitsChannels(); } )
)->emitsChannels() )
, values_( channels_ )
{
}
void MultiConnection::set( Input const& input, ChannelBuffer const& values )
{
buffers_[ input.id() ] = values;
values_.fill();
for_each( buffers_.cbegin(), buffers_.cend(),
[this]( auto const& entry ) {
transform( entry.second.cbegin(), entry.second.cend(), values_.begin(), values_.begin(),
[]( auto const& a, auto const& b ) {
return ChannelValue( max( a.get(), b.get() ) );
} );
} );
inputChangeEvent_( values_ );
}
void MultiConnection::doStatistics( ostream& os ) const
{
os << ", channels: " << channels_ << ", buffers: " << buffers_.size()
<< "\n\t\tvalues: " << makeStatistics( values_ );
transform( buffers_.begin(), buffers_.end(), OutputStreamIterator( os ),
[]( auto const& entry ) {
return make_tuple( "\n\t\tbuffer[", ref( entry.first ), "]: ", makeStatistics( entry.second ) );
} );
}
static ComponentRegistry< MultiConnection > registry( "multiconnection" );
} // namespace sc