libpniio
sequence_rule.hpp
Go to the documentation of this file.
1 // (c) Copyright 2015 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
2 //
3 // This file is part of libpniio.
4 //
5 // libpniio is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // libpniio is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
17 // ===========================================================================
18 //
19 // Created on: Jan 29, 2015
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 //
23 #pragma once
24 
25 #include<pni/core/types.hpp>
26 #include<pni/core/error.hpp>
27 
28 #include "../exceptions.hpp"
29 #include "get_rule_type.hpp"
30 #include "delimiter_rule.hpp"
31 
32 
33 namespace pni{
34 namespace io{
35 
36  //------------------------------------------------------------------------
55  template<
56  typename ITERT,
57  typename ST
58  >
59  struct sequence_rule : boost::spirit::qi::grammar<ITERT,ST()>
60  {
62  typedef typename ST::value_type value_type;
65 
68 
70  boost::spirit::qi::rule<ITERT> start_;
72  boost::spirit::qi::rule<ITERT> stop_;
78  boost::spirit::qi::rule<ITERT,ST()> sequence_;
79 
80  //--------------------------------------------------------------------
88  sequence_rule() : sequence_rule::base_type(sequence_)
89  {
90  using namespace boost::spirit;
91 
92  sequence_ = qi::omit[*qi::blank]>>
93  (element_rule_ %(+qi::blank))>>
94  qi::omit[*qi::blank];
95  }
96 
97  //--------------------------------------------------------------------
108  sequence_rule(char del):
109  sequence_rule::base_type(sequence_),
110  delimiter_(del)
111  {
112  using namespace boost::spirit;
113 
114  sequence_ = qi::omit[*qi::blank]>>
115  (element_rule_ % delimiter_)>>
116  qi::omit[*qi::blank];
117  }
118 
119  //--------------------------------------------------------------------
131  sequence_rule(char start,char stop):
132  sequence_rule::base_type(sequence_),
133  start_(start>boost::spirit::qi::omit[*boost::spirit::qi::blank]),
134  stop_(boost::spirit::qi::omit[*boost::spirit::qi::blank]>stop)
135  {
136  using namespace boost::spirit;
137  sequence_ = start_> (element_rule_ % (+qi::blank))>stop_;
138  }
139 
140  //--------------------------------------------------------------------
151  sequence_rule(char start,char stop,char del):
152  sequence_rule::base_type(sequence_),
153  delimiter_(del),
154  start_(start>boost::spirit::qi::omit[*boost::spirit::qi::blank]),
155  stop_(boost::spirit::qi::omit[*boost::spirit::qi::blank]>stop)
156  {
157  sequence_ = start_>(element_rule_ % delimiter_)>stop_;
158  }
159 
160  };
161 
162 //end of namespace
163 }
164 }
Definition: spirit_container_traits.hpp:32
sequence_rule(char start, char stop, char del)
constructor
Definition: sequence_rule.hpp:151
sequence_rule(char start, char stop)
constructor
Definition: sequence_rule.hpp:131
ST::value_type value_type
value type of the sequence type
Definition: sequence_rule.hpp:62
boost::spirit::qi::rule< ITERT > start_
rule for the start symbol of the sequence
Definition: sequence_rule.hpp:70
sequence_rule(char del)
constructor
Definition: sequence_rule.hpp:108
delimiter_rule< ITERT > delimiter_
delimiter rule
Definition: sequence_rule.hpp:67
Definition: spirit_container_traits.hpp:33
container parser
Definition: sequence_rule.hpp:59
char stop_symbol_
a possible stop symbol
Definition: sequence_rule.hpp:76
Definition: cbf_reader.hpp:41
get_rule_type< ITERT, value_type >::type element_rule_
rule to parse the value_type of the sequence
Definition: sequence_rule.hpp:64
boost::spirit::qi::rule< ITERT, ST()> sequence_
the full rule to parse the sequence
Definition: sequence_rule.hpp:78
delimiter parser
Definition: delimiter_rule.hpp:50
boost::spirit::qi::rule< ITERT > stop_
rule for the stop symbol of the sequence
Definition: sequence_rule.hpp:72
obtain rule type
Definition: get_rule_type.hpp:48
char start_symbol_
a possible start symbol
Definition: sequence_rule.hpp:74
sequence_rule()
default constructor
Definition: sequence_rule.hpp:88