Go to the documentation of this file.
14 # pragma GCC system_header
26 #include <type_traits>
27 #include <unordered_map>
28 #include <unordered_set>
33 #include <boost/fusion/include/std_pair.hpp>
34 #include <boost/fusion/include/unused.hpp>
35 #include <boost/spirit/include/qi.hpp>
37 #include <boost/phoenix/core.hpp>
38 #include <boost/phoenix/operator.hpp>
40 #include <boost/spirit/repository/include/qi_confix.hpp>
56 namespace sp = boost::spirit;
57 namespace ph = boost::phoenix;
58 namespace qi = sp::qi;
59 namespace enc = sp::ascii;
60 namespace rep = sp::repository;
67 template <
typename Iterator,
typename T,
typename Skipper,
class Enable =
void>
78 #define REGISTER_GRAMMAR( ResultType, GrammarName ) \
79 template <typename Iterator, typename Skipper> \
80 struct Grammar_<Iterator, ResultType, Skipper> { \
81 typedef GrammarName<Iterator, Skipper> Grammar; \
84 template <
typename Iterator>
85 struct SkipperGrammar : qi::grammar<Iterator> {
87 comments = enc::space | rep::confix(
"/*",
"*/" )[*( qi::char_ -
"*/" )] |
88 rep::confix(
"//", ( sp::eol | sp::eoi ) )[*( qi::char_ - ( sp::eol | sp::eoi ) )];
93 template <
typename Iterator,
typename Skipper>
94 struct StringGrammar : qi::grammar<Iterator, std::string(), qi::locals<char>, Skipper> {
100 quote = enc::char_( qi::_r1 );
103 *( ( enc::char_(
'\\' ) >>
quote( qi::_a ) )[qi::_val += qi::_a] |
104 ( enc::char_(
'\\' ) >> enc::char_(
'\\' ) )[qi::_val +=
'\\'] |
105 ( enc::char_[qi::_val += qi::_1] -
quote( qi::_a ) ) ) >
quote( qi::_a )];
116 template <
typename Iterator,
typename Skipper>
120 ch = qi::int_parser<char>() |
'\'' >> ( qi::char_ -
'\'' ) >>
'\'';
126 template <
typename Iterator,
typename Skipper>
127 struct BoolGrammar : qi::grammar<Iterator, bool(), Skipper> {
130 boolean_literal = ( qi::lit(
"true" ) |
"True" |
"TRUE" |
"1" )[qi::_val =
true] |
131 ( qi::lit(
"false" ) |
"False" |
"FALSE" |
"0" )[qi::_val =
false];
137 template <
typename Iterator,
typename RT,
typename Skipper>
141 integer = qi::int_parser<RT>()[qi::_val = qi::_1] >> -qi::no_case[qi::char_(
'L' )];
148 template <
typename Iterator,
typename T,
typename Skipper>
153 template <
typename Iterator,
typename RT,
typename Skipper>
154 struct RealGrammar : qi::grammar<Iterator, RT(), Skipper> {
162 template <
typename Iterator,
typename T,
typename Skipper>
169 template <
typename T>
172 template <
typename T>
175 template <
typename T,
typename... Ts>
180 template <
typename T,
typename... Ts>
187 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
189 : qi::grammar<Iterator, TupleT(), qi::locals<typename tuple_get_first_type<TupleT>::type>, Skipper> {
212 ph::function<Operations>
op;
215 template <
typename Iterator,
typename TupleT,
typename Skipper>
225 std::get<0>( res ) = val;
235 ph::function<Operations>
op;
239 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
240 struct TupleGrammar : qi::grammar<Iterator, TupleT(), qi::locals<char>, Skipper> {
243 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
244 end = *( enc::char_(
',' ) ) >> enc::char_( qi::_r1 );
263 template <
typename Iterator,
typename VectorT,
typename Skipper>
264 struct VectorGrammar : qi::grammar<Iterator, VectorT(), qi::locals<char>, Skipper> {
270 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
271 end = *( enc::char_(
',' ) ) >> enc::char_( qi::_r1 );
273 vec =
begin[qi::_a = qi::_1] >> -
list[qi::_val = qi::_1] >>
end( qi::_a );
287 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
294 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
301 template <
typename Iterator,
typename InnerT,
typename CompareT,
typename AllocatorT,
typename Skipper>
307 template <
typename Iterator,
typename SetT,
typename Skipper>
308 struct SetGrammar : qi::grammar<Iterator, SetT(), qi::locals<char>, Skipper> {
319 template <
typename Iterator,
typename InnerT,
typename HashT,
typename CompareT,
typename AllocatorT,
326 template <
typename Iterator,
typename PairT,
typename Skipper>
327 struct PairGrammar : qi::grammar<Iterator, PairT(), qi::locals<char>, Skipper> {
338 begin = enc::char_(
'(' )[qi::_val =
')'] | enc::char_(
'[' )[qi::_val =
']'];
339 end = qi::char_( qi::_r1 );
356 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename Skipper>
361 template <
typename Iterator,
typename MapT,
typename Skipper>
365 typedef typename MapT::key_type
KeyT;
376 for (
auto cur = vec.
begin(); cur != vec.
end(); ++cur ) { res.insert( *cur ); }
386 list = -(
pair % enc::char_(
',' ) );
387 map = ( (
'[' >>
list >>
']' ) | (
'{' >>
list >>
'}' ) | (
'[' >>
list >>
',' >>
']' ) |
388 (
'{' >>
list >>
',' >>
'}' ) )[
op( qi::_val, qi::_1 )];
396 ph::function<Operations>
op;
402 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
410 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename HashT,
typename KeyCompareT,
411 typename AllocatorT,
typename Skipper>
418 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
424 template <
typename Iterator,
typename Po
intT,
typename Skipper>
449 list = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >>
scalar[
op( qi::_val, qi::_1,
'x' )] >>
450 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
451 scalar[
op( qi::_val, qi::_1,
'y' )] >>
',' >>
452 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >>
scalar[
op( qi::_val, qi::_1,
'z' )];
457 ph::function<Operations>
op;
463 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
470 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
475 template <
typename Iterator,
typename Po
intT,
typename Skipper>
501 res.SetPx( xyz.Px() );
502 res.SetPy( xyz.Py() );
503 res.SetPz( xyz.Pz() );
509 list4d = (
point3d[
op( qi::_val, qi::_1 )] >> enc::char_(
";," ) >>
e[
op( qi::_val, qi::_1,
'e' )] ) |
510 (
e[
op( qi::_val, qi::_1,
'e' )] >> enc::char_(
";," ) >>
point3d[
op( qi::_val, qi::_1 )] );
511 e = -( enc::no_case[enc::char_(
"te" )] >>
':' ) >>
scalar[qi::_val = qi::_1];
514 list3d = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >>
scalar[
op( qi::_val, qi::_1,
'x' )] >>
515 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
516 scalar[
op( qi::_val, qi::_1,
'y' )] >>
',' >>
517 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >>
scalar[
op( qi::_val, qi::_1,
'z' )];
523 ph::function<Operations>
op;
529 template <
typename Iterator,
typename T1,
typename Skipper>
534 template <
typename Iterator,
typename Skipper>
535 struct Histo1DGrammar : qi::grammar<Iterator, Gaudi::Histo1DDef(), qi::locals<char>, Skipper> {
557 val1 =
title[
op( qi::_val, qi::_1 )] >>
',' >> qi::double_[
op( qi::_val, qi::_1,
'l' )] >>
',' >>
558 qi::double_[
op( qi::_val, qi::_1,
'h' )] >> -(
',' >> qi::int_[
op( qi::_val, qi::_1 )] );
559 val2 = qi::double_[
op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[
op( qi::_val, qi::_1,
'h' )] >>
',' >>
560 title[
op( qi::_val, qi::_1 )] >> -(
',' >> qi::int_[
op( qi::_val, qi::_1 )] );
561 val3 = qi::double_[
op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[
op( qi::_val, qi::_1,
'h' )] >>
562 -(
',' >>
title[
op( qi::_val, qi::_1 )] ) >> -(
',' >> qi::int_[
op( qi::_val, qi::_1 )] );
563 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
564 end = enc::char_( qi::_r1 );
573 ph::function<Operations>
op;
579 template <
typename Iterator,
typename Skipper>
580 struct KeyValueGrammar : qi::grammar<Iterator, std::pair<std::string, std::string>(), Skipper> {
qi::rule< Iterator, ResultT(), Skipper > val3
TupleInnerGrammar< Iterator, TupleT, N, Skipper > grTuple
qi::rule< Iterator, char()> begin_quote
void operator()(ResultT &res, const VectorPairT &vec) const
qi::rule< Iterator, char()> begin
RealGrammar< Iterator, T, Skipper > Grammar
PairT::second_type second_type
void operator()(PairT &res, const KeyT &key, tag_key) const
qi::rule< Iterator, VectorPairT(), Skipper > list
StringGrammar< Iterator, Skipper > gstring
ph::function< Operations > op
void setLowEdge(double value)
set low edge
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > tup
qi::rule< Iterator, void(char)> end
std::string::const_iterator DefaultIterator
Pnt3DGrammar< Iterator, ROOT::Math::PositionVector3D< T1, T2 >, Skipper > Grammar
qi::rule< Iterator, ResultT(), Skipper > list
void operator()(ResultT &res, const Scalar &scalar, const char xyz) const
Grammar_< Iterator, std::tuple_element_t< 0, ResultT >, Skipper >::Grammar grFirst
void operator()(ResultT &res, const ResultT &xyz) const
enc::space_type DefaultSkipper
PairT::first_type first_type
qi::rule< Iterator, ResultT(), Skipper > pair
qi::rule< Iterator, ResultT(), Skipper > list4d
qi::rule< Iterator, ScalarT(), Skipper > e
Pnt4DGrammar< Iterator, ROOT::Math::LorentzVector< T1 >, Skipper > Grammar
ph::function< Operations > op
StringGrammar< Iterator, Skipper > title
qi::rule< Iterator, void(char)> end
ph::function< Operations > op
VectorGrammar< Iterator, std::set< InnerT, CompareT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, ResultT(), Skipper > pair_in
qi::rule< Iterator, ResultT(), Skipper > map
Grammar_< Iterator, typename PairT::second_type, Skipper >::Grammar value
struct GAUDI_API map
Parametrisation class for map-like implementation.
qi::rule< Iterator, SetT(), qi::locals< char >, Skipper > set
qi::rule< Iterator, char()> begin
MapT::mapped_type MappedT
qi::rule< Iterator, ResultT(), Skipper > list
qi::rule< Iterator, char()> begin
void setTitle(std::string value)
set the title
Pnt3DGrammar< Iterator, ROOT::Math::DisplacementVector3D< T1, T2 >, Skipper > Grammar
qi::rule< Iterator, char(), Skipper > ch
qi::rule< Iterator, void(char)> end
void operator()(PairT &res, const MappedT &value, tag_mapped) const
Grammar_< Iterator, Scalar, Skipper >::Grammar scalar
void setHighEdge(double value)
set high edge
qi::rule< Iterator, Node(), Skipper > real
Grammar_< Iterator, typename PairT::first_type, Skipper >::Grammar key
qi::rule< Iterator, PairT(), Skipper > pair
tuple_get_first_type< TupleT >::type HeadT
void operator()(ResultT &res) const
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > vec
std::pair< KeyT, MappedT > PairT
qi::rule< Iterator, void(char)> quote
qi::rule< Iterator, ResultT(), Skipper > point3d
void operator()(ResultT &res, int val) const
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > pair
qi::rule< Iterator, void(char)> end
void operator()(ResultT &res, const std::string &title) const
qi::rule< Iterator > comments
TupleInnerGrammar< Iterator, TailT, N - 1, Skipper > grLast
MapGrammar< Iterator, GaudiUtils::VectorMap< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, bool(), Skipper > boolean_literal
void operator()(ResultT &res, const std::tuple_element_t< 0, ResultT > &val) const
qi::rule< Iterator, ResultT(), Skipper > point4d
qi::rule< Iterator, ResultT(), Skipper > tup
MapGrammar< Iterator, std::map< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
PairGrammar(const std::string &delimeter)
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
VectorGrammar< Iterator, std::list< InnerT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, char()> begin
Grammar_< Iterator, HeadT, Skipper >::Grammar grHead
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > hist
Grammar_< Iterator, typename MapT::key_type, Skipper >::Grammar key
qi::rule< Iterator, ResultT(), qi::locals< HeadT >, Skipper > tup
qi::rule< Iterator, ResultT(), Skipper > point
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
void operator()(ResultT &res, const double &val, const char lh) const
SkipperGrammar< IteratorT > Skipper
REGISTER_GRAMMAR(std::string, StringGrammar)
PairGrammar< Iterator, std::pair< KeyT, ValueT >, Skipper > Grammar
std::vector< PairT > VectorPairT
MapGrammar< Iterator, std::unordered_map< KeyT, ValueT, HashT, KeyCompareT, AllocatorT >, Skipper > Grammar
VectorGrammar< Iterator, std::vector< InnerT, AllocatorT >, Skipper > Grammar
SetGrammar< Iterator, std::unordered_set< InnerT, HashT, CompareT, AllocatorT >, Skipper > Grammar
Grammar_< Iterator, typename VectorT::value_type, Skipper >::Grammar elementGrammar
qi::rule< Iterator, ResultT(), Skipper > val1
Grammar_< Iterator, typename MapT::mapped_type, Skipper >::Grammar value
void operator()(ResultT &res, HeadT &head, TailT &tail) const
Gaudi::Histo1DDef ResultT
qi::rule< Iterator, RT(), Skipper > real
VectorGrammar< Iterator, SetT, Skipper > grVector
qi::rule< Iterator, RT(), Skipper > integer
ph::function< Operations > op
void setBins(int value)
set number of bis
qi::rule< Iterator, ResultT(), Skipper > val2
qi::rule< Iterator, ResultT(), Skipper > list3d
void operator()(ResultT &res, const ScalarT &scalar, const char xyz) const
Grammar_< Iterator, ScalarT, Skipper >::Grammar scalar
std::pair< std::string, std::string > ResultT
ph::function< Operations > op
BOOST_MPL_ASSERT_MSG(false, GRAMMAR_FOR_TYPE_DOES_NOT_EXISTS,(T))
IntGrammar< Iterator, T, Skipper > Grammar
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
qi::rule< Iterator, std::string(), qi::locals< char >, Skipper > str
ph::function< Operations > op
tuple_remove_first_type< TupleT >::type TailT