| 7261 | } |
| 7262 | |
| 7263 | class Opt : public ParserRefImpl<Opt> { |
| 7264 | protected: |
| 7265 | std::vector<std::string> m_optNames; |
| 7266 | |
| 7267 | public: |
| 7268 | template<typename LambdaT> |
| 7269 | explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {} |
| 7270 | |
| 7271 | explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {} |
| 7272 | |
| 7273 | template<typename LambdaT> |
| 7274 | Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 7275 | |
| 7276 | template<typename T> |
| 7277 | Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} |
| 7278 | |
| 7279 | auto operator[]( std::string const &optName ) -> Opt & { |
| 7280 | m_optNames.push_back( optName ); |
| 7281 | return *this; |
| 7282 | } |
| 7283 | |
| 7284 | auto getHelpColumns() const -> std::vector<HelpColumns> { |
| 7285 | std::ostringstream oss; |
| 7286 | bool first = true; |
| 7287 | for( auto const &opt : m_optNames ) { |
| 7288 | if (first) |
| 7289 | first = false; |
| 7290 | else |
| 7291 | oss << ", "; |
| 7292 | oss << opt; |
| 7293 | } |
| 7294 | if( !m_hint.empty() ) |
| 7295 | oss << " <" << m_hint << ">"; |
| 7296 | return { { oss.str(), m_description } }; |
| 7297 | } |
| 7298 | |
| 7299 | auto isMatch( std::string const &optToken ) const -> bool { |
| 7300 | auto normalisedToken = normaliseOpt( optToken ); |
| 7301 | for( auto const &name : m_optNames ) { |
| 7302 | if( normaliseOpt( name ) == normalisedToken ) |
| 7303 | return true; |
| 7304 | } |
| 7305 | return false; |
| 7306 | } |
| 7307 | |
| 7308 | using ParserBase::parse; |
| 7309 | |
| 7310 | auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { |
| 7311 | auto validationResult = validate(); |
| 7312 | if( !validationResult ) |
| 7313 | return InternalParseResult( validationResult ); |
| 7314 | |
| 7315 | auto remainingTokens = tokens; |
| 7316 | if( remainingTokens && remainingTokens->type == TokenType::Option ) { |
| 7317 | auto const &token = *remainingTokens; |
| 7318 | if( isMatch(token.token ) ) { |
| 7319 | if( m_ref->isFlag() ) { |
| 7320 | auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() ); |
no outgoing calls
no test coverage detected