SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
monolithic_source.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_MONOLITHIC_SOURCE_HPP__
27 #define SHORE_PROCESSING_MONOLITHIC_SOURCE_HPP__
28 
29 #include <stdexcept>
30 #include <boost/utility/enable_if.hpp>
31 
36 #include "shore/base/stringops.hpp"
37 
38 namespace shore {
39 
44 template<typename S,
45  typename T=typename source_traits<S>::current_type,
46  typename Cmp=bool (*)(const T &,const T &)>
48 :public buffer_chain<T>
49 {
50  public:
51 
52  typedef S source_type;
53  typedef T current_type;
54  typedef Cmp compare_type;
55 
56  private:
57 
59  source_type m_basic;
60 
62  sorting_check<T,Cmp> m_check;
63 
64 
67  template<typename _S>
68  static std::string get_name(_S &b,
69  typename boost::enable_if<shore::has_get_name<_S> >::type * =0)
70  {
71  return b.get_name();
72  }
73 
76  template<typename _S>
77  static std::string get_name(_S &b,
78  typename boost::disable_if<shore::has_get_name<_S> >::type * =0)
79  {
80  return "<unnamed source "+shore::to_string(&b)+">";
81  }
82 
84  void get_source_data()
85  {
87  {
88  while(m_basic.next(buffer_chain<T>::buffer_chain_push()))
90  return;
91 
92  // No more data, flush.
93  // The last buffer pushed could not be initialized, so
96  }
97  }
98 
99  protected:
100 
104  Cmp get_comparator() const
105  {
106  return m_check.get_comparator();
107  }
108 
109  public:
110 
114  monolithic(Cmp cmp=Cmp())
115  :m_check(get_name(m_basic),cmp)
116  {
117  if(is_valid_comparator(cmp))
118  add_plugin(&m_check);
119  }
120 
125  template<typename Arg>
126  monolithic(Arg a1,Cmp cmp=Cmp())
127  :m_basic(a1),
128  m_check(get_name(m_basic),cmp)
129  {
130  if(is_valid_comparator(cmp))
131  add_plugin(&m_check);
132  }
133 
138  template<typename Arg1,typename Arg2>
139  monolithic(Arg1 a1,Arg2 a2,Cmp cmp=Cmp())
140  :m_basic(a1,a2),
141  m_check(get_name(m_basic),cmp)
142  {
143  if(is_valid_comparator(cmp))
144  add_plugin(&m_check);
145  }
146 
150  source_type &basic()
151  {
152  return m_basic;
153  }
154 
158  const source_type &basic() const
159  {
160  return m_basic;
161  }
162 
166  const current_type &current() const
167  {
169  }
170 
174  bool has_data()
175  {
176  get_source_data();
178  }
179 
183  void next()
184  {
186  get_source_data();
187  }
188 };
189 
190 } //namespace shore
191 
192 #endif // SHORE_PROCESSING_MONOLITHIC_SOURCE_HPP__
193