libpniio
spirit_container_traits.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2015 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 //
20 // Created on: Feb 11, 2015
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 //
24 #pragma once
25 
26 #include <pni/core/types.hpp>
27 #include <pni/core/arrays.hpp>
28 #include <pni/core/type_erasures.hpp>
29 #include <boost/spirit/include/karma.hpp>
30 
31 
32 namespace boost{
33 namespace spirit{
34 namespace traits{
35 
36  //-------------------------------------------------------------------------
37  // Traits for Karma and the mdarray template
38  //-------------------------------------------------------------------------
46  template<typename ...OTYPES>
47  struct is_container<pni::core::mdarray<OTYPES...> const>: mpl::true_
48  { };
49 
50  //-------------------------------------------------------------------------
59  template<typename ...OTYPES>
60  struct container_iterator<pni::core::mdarray<OTYPES...> const>
61  {
63  typedef typename pni::core::mdarray<OTYPES...>::const_iterator type;
64  };
65 
66  //-------------------------------------------------------------------------
76  template<typename ...OTYPES>
77  struct begin_container<pni::core::mdarray<OTYPES...> const>
78  {
85  static typename pni::core::mdarray<OTYPES...>::const_iterator
86  call(pni::core::mdarray<OTYPES...> const& c)
87  {
88  return c.begin();
89  }
90  };
91 
92  //-------------------------------------------------------------------------
102  template<typename ...OTYPES>
103  struct end_container<pni::core::mdarray<OTYPES...> const>
104  {
111  static typename pni::core::mdarray<OTYPES...>::const_iterator
112  call(pni::core::mdarray<OTYPES...> const &c)
113  {
114  return c.end();
115  }
116  };
117 
118  //-------------------------------------------------------------------------
119  // Traits for Karma and the array type erasure
120  //-------------------------------------------------------------------------
128  template<>
129  struct is_container<pni::core::array const>: mpl::true_
130  { };
131 
132  //-------------------------------------------------------------------------
140  template<>
141  struct container_iterator<pni::core::array const>
142  {
143  typedef pni::core::array::const_iterator type;
144  };
145 
146  //-------------------------------------------------------------------------
154  template<>
155  struct begin_container<pni::core::array const>
156  {
163  static pni::core::array::const_iterator
164  call(pni::core::array const& c)
165  {
166  std::cout<<"begin"<<std::endl;
167  return c.begin();
168  }
169  };
170 
171  //-------------------------------------------------------------------------
179  template<>
180  struct end_container<pni::core::array const>
181  {
188  static pni::core::array::const_iterator
189  call(pni::core::array const &c)
190  {
191  std::cout<<"end"<<std::endl;
192  return c.end();
193  }
194  };
195 
196 //end of namespace
197 }
198 }
199 }
Definition: spirit_container_traits.hpp:32
static pni::core::array::const_iterator call(pni::core::array const &c)
get iterator to first element
Definition: spirit_container_traits.hpp:164
Definition: cbf_reader.hpp:41
static pni::core::mdarray< OTYPES...>::const_iterator call(pni::core::mdarray< OTYPES...> const &c)
get iterator for first element
Definition: spirit_container_traits.hpp:86
static pni::core::mdarray< OTYPES...>::const_iterator call(pni::core::mdarray< OTYPES...> const &c)
get end iterator
Definition: spirit_container_traits.hpp:112
pni::core::mdarray< OTYPES...>::const_iterator type
iterator type for mdarray
Definition: spirit_container_traits.hpp:63
static pni::core::array::const_iterator call(pni::core::array const &c)
get iterator to last element
Definition: spirit_container_traits.hpp:189
pni::core::array::const_iterator type
Definition: spirit_container_traits.hpp:143