SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
pipe_box.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_PROCESSING_PIPE_BOX_HPP__
27 #define SHORE_PROCESSING_PIPE_BOX_HPP__
28 
29 #include <iostream>
30 #include <string>
31 
35 
36 namespace shore {
37 
38 template<typename Pipe,
39  typename S=typename source_traits<Pipe>::current_type,
40  typename T=typename sink_traits<Pipe>::append_type>
41 class pipe_box
42 {
43  public:
44 
45  typedef S current_type;
46  typedef T append_type;
47  typedef Pipe pipe_type;
48 
49  private:
50 
51  shore::feed<T> m_feed;
52  shore::extractor<S> m_extractor;
53  pipe_type m_pipe;
54 
55  public:
56 
57  pipe_box()
58  {
59  m_feed|m_pipe|m_extractor;
60  }
61 
62  pipe_box(const pipe_box<Pipe,S,T> & other)
63  :m_pipe(other.m_pipe)
64  {
65  m_feed|m_pipe|m_extractor;
66  }
67 
68  template<typename Arg1>
69  pipe_box(Arg1 arg1)
70  :m_pipe(arg1)
71  {
72  m_feed|m_pipe|m_extractor;
73  }
74 
75  template<typename Arg1,typename Arg2>
76  pipe_box(Arg1 arg1,Arg2 arg2)
77  :m_pipe(arg1,arg2)
78  {
79  m_feed|m_pipe|m_extractor;
80  }
81 
83  pipe_type * operator->()
84  {
85  return &m_pipe;
86  }
87 
89  pipe_type & operator*()
90  {
91  return m_pipe;
92  }
93 
94  const current_type & current() const
95  {
96  return m_extractor.current();
97  }
98 
99  bool has_data()
100  {
101  return m_extractor.has_data();
102  }
103 
104  void next()
105  {
106  m_extractor.next();
107  }
108 
109  void append(const append_type & d)
110  {
111  m_feed.append(d);
112  }
113 
114  void flush()
115  {
116  m_feed.flush();
117  }
118 };
119 
120 
121 } // namespace
122 
123 #endif // SHORE_PROCESSING_PIPE_BOX_HPP__
124