File indexing completed on 2025-01-18 09:14:30
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef PARSERS_SPIRIT_PARSERSFACTORY_H
0012 #define PARSERS_SPIRIT_PARSERSFACTORY_H 1
0013
0014
0015
0016
0017
0018 #include <string>
0019 #include <vector>
0020 #include <map>
0021
0022
0023
0024 #include <boost/mpl/assert.hpp>
0025 #include <boost/type_traits.hpp>
0026
0027
0028
0029 #include "Parsers/config.h"
0030 #include "Parsers/spirit/UsedParser.h"
0031 #include "Parsers/spirit/GrammarsV2.h"
0032 #include "Parsers/spirit/GrammarsV2.h"
0033 #include "Parsers/spirit/ToStream.h"
0034
0035
0036 namespace dd4hep {
0037
0038 namespace Parsers {
0039 template <typename TYPE>
0040 int parse(TYPE& result, const std::string& input);
0041 template <typename TYPE>
0042 std::ostream& toStream(const TYPE& obj, std::ostream& s);
0043
0044
0045
0046 typedef std::string::const_iterator IteratorT;
0047
0048 typedef SkipperGrammar<IteratorT> Skipper;
0049
0050 template<typename ResultT> inline int
0051 parse_(ResultT& result, const std::string& input){
0052 Skipper skipper;
0053 typename Grammar_<IteratorT, ResultT, Skipper>::Grammar g;
0054 IteratorT iter = input.begin(), end = input.end();
0055 return qi::phrase_parse( iter, end, g, skipper , result) && (iter==end);
0056 }
0057
0058 template<> inline int
0059 parse_(std::string& result, const std::string& input){
0060 Skipper skipper;
0061 Grammar_<IteratorT, std::string, Skipper>::Grammar g;
0062 IteratorT iter = input.begin(), end = input.end();
0063 if (!(qi::phrase_parse( iter, end, g, skipper, result) && (iter==end))){
0064 result = input;
0065 }
0066
0067 return true;
0068 }
0069
0070
0071 }
0072 }
0073
0074
0075
0076
0077 #define PARSERS_DEF_FOR_SINGLE(Type) \
0078 namespace dd4hep { \
0079 namespace Parsers { \
0080 template <> int parse(Type& result, const std::string& input) \
0081 { return parse_(result, input); } \
0082 template <> std::ostream& toStream(const Type& obj, std::ostream& s) \
0083 { return toStream_(obj, s); }}}
0084
0085 #define PARSERS_DEF_FOR_PAIR(First,Second) \
0086 namespace dd4hep { \
0087 namespace Parsers { \
0088 template <> int parse(std::pair<First,Second>& result, const std::string& input) \
0089 { return parse_(result, input); } \
0090 template <> std::ostream& toStream(const std::pair<First,Second>& obj, std::ostream& s) \
0091 { return toStream_(obj, s); }}}
0092
0093
0094 #endif
0095