RaftLib  0.3a
C++ Stream Processing Template Library
splitmethod.hpp
1 
20 #ifndef _SPLITMETHOD_HPP_
21 #define _SPLITMETHOD_HPP_ 1
22 
23 #include <type_traits>
24 #include <functional>
25 
26 #include "autoreleasebase.hpp"
27 #include "signalvars.hpp"
28 #include "port.hpp"
29 #include "fifo.hpp"
30 
31 
32 class autoreleasebase;
33 
36 {
37 public:
38  splitmethod() = default;
39  virtual ~splitmethod() = default;
40 
41  template < class T /* item */,
42  typename std::enable_if<
43  std::is_fundamental< T >::value >::type* = nullptr >
44  bool send( T &item, const raft::signal signal, Port &outputs )
45  {
46  auto * const fifo( select_fifo( outputs, sendtype ) );
47  if( fifo != nullptr )
48  {
49  fifo->push( item, signal );
50  return( true );
51  }
52  else
53  {
54  return( false );
55  }
56  }
57 
66  template < class T /* peek range obj, */,
67  typename std::enable_if<
68  not std::is_base_of< autoreleasebase,
69  T >::value >::type* = nullptr >
70  bool send( T &range, Port &outputs )
71  {
72  auto * const fifo( select_fifo( outputs, sendtype ) );
73  if( fifo != nullptr )
74  {
75  const auto space_avail(
76  std::min( fifo->space_avail(), range.size() ) );
77  for( auto i( 0 ); i < space_avail; i++ )
78  {
79  fifo->push( range[ i ].ele, range[ i ].sig );
80  }
81  return( true );
82  }
83  else
84  {
85  return( false );
86  }
87  }
88 
89  template < class T /* item */ >
90  bool get( T &item, raft::signal &signal, Port &inputs )
91  {
92  auto * const fifo( select_fifo( inputs, gettype ) );
93  if( fifo != nullptr )
94  {
95  fifo->pop< T >( item, &signal );
96  return( true );
97  }
98  else
99  {
100  return( false );
101  }
102  }
103 
104 
105 protected:
106  enum functype { sendtype, gettype };
107  virtual FIFO* select_fifo( Port &port_list, const functype type ) = 0;
108 };
109 #endif /* END _SPLITMETHOD_HPP_ */
Definition: autoreleasebase.hpp:37
Definition: port.hpp:57
bool send(T &range, Port &outputs)
Definition: splitmethod.hpp:70
Definition: fifo.hpp:48
Definition: splitmethod.hpp:35