Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-13 07:38:47

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 //==========================================================================
0011 #ifndef PARSERS_SPIRIT_PARSERSFACTORY_H
0012 #define PARSERS_SPIRIT_PARSERSFACTORY_H 1
0013 // ============================================================================
0014 // Include files
0015 // ============================================================================
0016 // STD & STL
0017 // ============================================================================
0018 #include <string>
0019 // ============================================================================
0020 // Boost:
0021 // ============================================================================
0022 #include <boost/mpl/assert.hpp>
0023 #include <boost/type_traits.hpp>
0024 // ============================================================================
0025 // dd4hep
0026 // ============================================================================
0027 #include "Parsers/config.h"
0028 #include "Parsers/spirit/UsedParser.h"
0029 #include "Parsers/spirit/GrammarsV2.h"
0030 #include "Parsers/spirit/GrammarsV2.h"
0031 #include "Parsers/spirit/ToStream.h"
0032 // ============================================================================
0033 /// Namespace for the AIDA detector description toolkit
0034 namespace dd4hep {
0035   /// Namespace for the AIDA detector for utilities using boost::spirit parsers
0036   namespace Parsers {
0037     template <typename TYPE>
0038     int parse(TYPE& result, const std::string& input);
0039     template <typename TYPE>
0040     std::ostream& toStream(const TYPE& obj, std::ostream& s);
0041 
0042     
0043     // ========================================================================
0044     typedef std::string::const_iterator IteratorT;
0045     //typedef boost::spirit::ascii::space_type Skipper;
0046     typedef SkipperGrammar<IteratorT> Skipper;
0047     // ========================================================================
0048     template<typename ResultT> inline int
0049     parse_(ResultT& result, const std::string& input){
0050       Skipper skipper;
0051       typename Grammar_<IteratorT, ResultT, Skipper>::Grammar g;
0052       IteratorT iter = input.begin(), end = input.end();
0053       return qi::phrase_parse( iter, end, g, skipper , result) && (iter==end);
0054     }
0055     //=========================================================================
0056     template<> inline int
0057     parse_(std::string& result, const std::string& input){
0058       Skipper skipper;
0059       Grammar_<IteratorT, std::string, Skipper>::Grammar g;
0060       IteratorT iter = input.begin(), end = input.end();
0061       if (!(qi::phrase_parse( iter, end, g, skipper, result) && (iter==end))){
0062         result = input;
0063       }
0064       //@attention always
0065       return true;
0066     }
0067     //=========================================================================
0068 
0069   }                                        //  end of namespace Parsers
0070 }                                          //  end of namespace dd4hep
0071 
0072 //=============================================================================
0073 
0074 // ============================================================================
0075 #define PARSERS_DEF_FOR_SINGLE(Type)                                    \
0076   namespace dd4hep  {                                                   \
0077     namespace Parsers  {                        \
0078       template <> int parse(Type& result, const std::string& input) \
0079     {  return parse_(result, input);  }             \
0080       template <> std::ostream& toStream(const Type& obj, std::ostream& s) \
0081     {  return toStream_(obj, s); }}}
0082 // ============================================================================
0083 #define PARSERS_DEF_FOR_PAIR(First,Second)              \
0084   namespace dd4hep  {                                                   \
0085     namespace Parsers  {                        \
0086       template <> int parse(std::pair<First,Second>& result, const std::string& input) \
0087     {  return parse_(result, input);  }             \
0088       template <> std::ostream& toStream(const std::pair<First,Second>& obj, std::ostream& s) \
0089     {  return toStream_(obj, s); }}}
0090 // ============================================================================
0091 
0092 #endif // PARSERS_SPIRIT_PARSERSFACTORY_H
0093