入力ポートで受け取ったメッセージをすべてのサクセサーにブロードキャストするノード。各ポートで受け取ったメッセージは個別にブロードキャストされます。出力は、タグと値を含むタグ付きメッセージです。タグは、メッセージを受け取った入力ポートを識別します。
template<typename T0, typename T1...typename TN> class indexer_node;
#include "tbb/flow_graph.h"
indexer_node は、graph_node および sender<indexer_node<T0..TN>::output_type > です。入力の T0 .. TN に対応する receiver<Ti> である入力ポートのタプルが含まれます。異なる型の複数の入力レシーバーをサポートしており、受け取ったメッセージをサクセサーにブロードキャストします。join_node とは異なり、入力ポートで受け取ったメッセージは、indexer_node のすべてのサクセサーに個別にブロードキャストされます。ブロードキャストの前に、メッセージは、メッセージを受け取ったポートのインデックスでタグ付けされます。
input_port テンプレート関数は、特定の入力ポートへの参照を取得するための構文を単純化します。
indexer_node のサクセサーがメッセージを拒否した場合、「メッセージ・パッシング・プロトコル」で説明されているプロトコルを使用して処理されます。入力ポートが着信メッセージを拒否することはありません。
入力リスト T0, T1 ... TN の型は、コピー構築可能および代入可能でなければなりません。
#include<cstdio>
#include "tbb/flow_graph.h"
using namespace tbb::flow;
int main() {
graph g;
function_node<int,int> f1( g, unlimited,
[](const int &i) { return 2*i; } );
function_node<float,float> f2( g, unlimited,
[](const float &f) { return f/2; } );
typedef indexer_node<int,float> my_indexer_type;
my_indexer_type o(g);
function_node< my_indexer_type::output_type >
f3( g, unlimited,
[]( const my_indexer_type::output_type &v ) {
if (v.tag() == 0) {
printf("Received an int %d\n",
cast_to<int>(v));
} else {
printf("Received a float %f\n",
cast_to<float>(v));
}
}
);
make_edge( f1, input_port<0>(o) );
make_edge( f2, input_port<1>(o) );
make_edge( o, f3 );
f1.try_put( 3 );
f2.try_put( 3 );
g.wait_for_all();
return 0;
}
上記のサンプルでは、3 つの function_node オブジェクトが作成されます。f1 は int i に 2 を掛けて、f2 は float f を 2 で割って、f3 は f1 と f2 の値を受け取って出力します。indexer_node o は、f1 と f2 の出力をラップし、それぞれの結果を f3 に送ります。このサンプルは構文を示すことを目的としているため、ノードでほとんど作業を行っていません。
namespace tbb {
namespace flow {
template<typename T0, typename T1...typename TN>
class indexer_node : public graph_node,
public sender<implementation-dependent-output-type > {
public:
typedef tagged_msg< size_t tag, T result> output_type;
typedef receiver<output_type> successor_type;
implementation-dependent-tuple input_ports_type;
indexer_node(graph &g);
indexer_node(const indexer_node &src);
input_ports_type &input_ports();
bool register_successor( successor_type &r );
bool remove_successor( successor_type &r );
bool try_get( output_type &v );
bool try_reserve( output_type & );
bool try_release( );
bool try_consume( );
};
}
}
| メンバー | 説明 |
|---|---|
| indexer_node(graph &g) |
graph g に属する indexer_node を構築します。 |
| indexer_node( const indexer_node &src ) |
indexer_node を構築します。プレデセッサーのリスト、入力ポートのメッセージ、サクセサーはコピーされません。 |
| input_ports_type& input_ports() |
戻り値: レシーバーの flow::tuple。各要素は tbb::receiver<T> から継承されます。T はその入力で想定されるメッセージの型です。各タプル要素は、flow::receiver<T> と同じように使用できます。 |
| bool register_successor( successor_type & r ) |
サクセサーのセットに r を追加します。 戻り値: true。 |
| bool remove_successor( successor_type & r ) |
サクセサーのセットから r を削除します。 戻り値: true。 |
| bool try_get( output_type &v ) |
indexer_node にバッファーは含まれていないため、get はサポートしていません。 戻り値: false。 |
| bool try_reserve( output_type & ) |
indexer_node にバッファーは含まれていないため、予約することはできません。 戻り値: false。 |
| bool try_release( ) |
indexer_node にバッファーは含まれていないため、予約することはできません。 戻り値: false。 |
| bool try_consume( ) |
indexer_node にバッファーは含まれていないため、予約することはできません。 戻り値: false。 |
Microsoft® Windows® オペレーティング・システムでは、配列型を indexer_node に渡すときに既知の問題があります。