| 9055 | } |
| 9056 | |
| 9057 | class Opt : public ParserRefImpl<Opt> { |
| 9058 | protected: |
| 9059 | std::vector<std::string> m_optNames; |
| 9060 | |
| 9061 | public: |
| 9062 | template<typename LambdaT> |
| 9063 | explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {} |
| 9064 | |
| 9065 | explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {} |
| 9066 | |
| 9067 | template<typename LambdaT> |
| 9068 | Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 9069 | |
| 9070 | template<typename T> |
| 9071 | Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 9072 | |
| 9073 | auto operator[]( std::string const &optName ) -> Opt & { |
| 9074 | m_optNames.push_back( optName ); |
| 9075 | return *this; |
| 9076 | } |
| 9077 | |
| 9078 | auto getHelpColumns() const -> std::vector<HelpColumns> { |
| 9079 | std::ostringstream oss; |
| 9080 | bool first = true; |
| 9081 | for( auto const &opt : m_optNames ) { |
| 9082 | if (first) |
| 9083 | first = false; |
| 9084 | else |
| 9085 | oss << ", "; |
| 9086 | oss << opt; |
| 9087 | } |
| 9088 | if( !m_hint.empty() ) |
| 9089 | oss << " <" << m_hint << ">"; |
| 9090 | return { { oss.str(), m_description } }; |
| 9091 | } |
| 9092 | |
| 9093 | auto isMatch( std::string const &optToken ) const -> bool { |
| 9094 | auto normalisedToken = normaliseOpt( optToken ); |
| 9095 | for( auto const &name : m_optNames ) { |
| 9096 | if( normaliseOpt( name ) == normalisedToken ) |
| 9097 | return true; |
| 9098 | } |
| 9099 | return false; |
| 9100 | } |
| 9101 | |
| 9102 | using ParserBase::parse; |
| 9103 | |
| 9104 | auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { |
| 9105 | auto validationResult = validate(); |
| 9106 | if( !validationResult ) |
| 9107 | return InternalParseResult( validationResult ); |
| 9108 | |
| 9109 | auto remainingTokens = tokens; |
| 9110 | if( remainingTokens && remainingTokens->type == TokenType::Option ) { |
| 9111 | auto const &token = *remainingTokens; |
| 9112 | if( isMatch(token.token ) ) { |
| 9113 | if( m_ref->isFlag() ) { |
| 9114 | auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() ); |
no outgoing calls
no test coverage detected