MCPcopy Create free account
hub / github.com/Profactor/cv-plot / Opt

Class Opt

CvPlot/ext/catch2/inc/catch.hpp:9290–9389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9288 }
9289
9290 class Opt : public ParserRefImpl<Opt> {
9291 protected:
9292 std::vector<std::string> m_optNames;
9293
9294 public:
9295 template<typename LambdaT>
9296 explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared<BoundFlagLambda<LambdaT>>( ref ) ) {}
9297
9298 explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared<BoundFlagRef>( ref ) ) {}
9299
9300 template<typename LambdaT>
9301 Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
9302
9303 template<typename T>
9304 Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {}
9305
9306 auto operator[]( std::string const &optName ) -> Opt & {
9307 m_optNames.push_back( optName );
9308 return *this;
9309 }
9310
9311 auto getHelpColumns() const -> std::vector<HelpColumns> {
9312 std::ostringstream oss;
9313 bool first = true;
9314 for( auto const &opt : m_optNames ) {
9315 if (first)
9316 first = false;
9317 else
9318 oss << ", ";
9319 oss << opt;
9320 }
9321 if( !m_hint.empty() )
9322 oss << " <" << m_hint << ">";
9323 return { { oss.str(), m_description } };
9324 }
9325
9326 auto isMatch( std::string const &optToken ) const -> bool {
9327 auto normalisedToken = normaliseOpt( optToken );
9328 for( auto const &name : m_optNames ) {
9329 if( normaliseOpt( name ) == normalisedToken )
9330 return true;
9331 }
9332 return false;
9333 }
9334
9335 using ParserBase::parse;
9336
9337 auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
9338 auto validationResult = validate();
9339 if( !validationResult )
9340 return InternalParseResult( validationResult );
9341
9342 auto remainingTokens = tokens;
9343 if( remainingTokens && remainingTokens->type == TokenType::Option ) {
9344 auto const &token = *remainingTokens;
9345 if( isMatch(token.token ) ) {
9346 if( m_ref->isFlag() ) {
9347 auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() );

Callers 1

makeCommandLineParserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected