TPIE

v1.1rc1-6-g0c97303
factory.h
1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 // Copyright 2013, The TPIE development team
4 //
5 // This file is part of TPIE.
6 //
7 // TPIE is free software: you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License as published by the
9 // Free Software Foundation, either version 3 of the License, or (at your
10 // option) any later version.
11 //
12 // TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 // License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with TPIE. If not, see <http://www.gnu.org/licenses/>
19 
20 #ifndef __TPIE_PIPELINING_PARALLEL_FACTORY_H__
21 #define __TPIE_PIPELINING_PARALLEL_FACTORY_H__
22 
23 namespace tpie {
24 
25 namespace pipelining {
26 
27 namespace parallel_bits {
28 
32 template <typename fact_t>
33 class factory : public factory_base {
34  fact_t fact;
35  const options opts;
36 public:
37  template <typename dest_t>
38  struct constructed {
39  typedef typename dest_t::item_type T2;
40 
41  typedef after<T2> after_t;
42  typedef typename fact_t::template constructed<after_t>::type processor_t;
43  typedef typename processor_t::item_type T1;
44 
45  typedef producer<T1, T2> type;
46  };
47 
48  factory(const fact_t & fact, const options opts)
49  : fact(fact)
50  , opts(opts)
51  {
52  }
53 
54  template <typename dest_t>
55  typename constructed<dest_t>::type
56  construct(const dest_t & dest) const {
57  typedef constructed<dest_t> gen_t;
58 
59  typedef typename gen_t::T1 input_type;
60  typedef typename gen_t::T2 output_type;
61  typedef state<input_type, output_type> state_t;
62 
64 
65  typedef typename gen_t::type producer_t;
66 
67  typename state_t::ptr st(new state_t(opts, fact));
68 
69  consumer_t consumer(dest, st);
70  this->init_node(consumer);
71  producer_t producer(st, consumer);
72  this->init_node(producer);
73  return producer;
74  }
75 };
76 
77 } // namespace parallel_bits
78 
79 } // namespace pipelining
80 
81 } // namespace tpie
82 
83 #endif // __TPIE_PIPELINING_PARALLEL_FACTORY_H__
Factory instantiating a parallel multithreaded pipeline.
Definition: factory.h:33
Accepts output items and sends them to the main thread.
Definition: base.h:42
Node running in main thread, accepting an output buffer from the managing producer and forwards them ...
Definition: base.h:363
User-supplied options to the parallelism framework.
Definition: options.h:32
State subclass containing the item type specific state, i.e.
Definition: base.h:44
Producer, running in main thread, managing the parallel execution.
Definition: base.h:748
Concrete consumer implementation.
Definition: base.h:713