MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / ExeName

Class ExeName

unittests/catch.hpp:6076–6116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6074 };
6075
6076 class ExeName : public ComposableParserImpl<ExeName> {
6077 std::shared_ptr<std::string> m_name;
6078 std::shared_ptr<BoundValueRefBase> m_ref;
6079
6080 template<typename LambdaT>
6081 static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundValueRefBase> {
6082 return std::make_shared<BoundLambda<LambdaT>>( lambda) ;
6083 }
6084
6085 public:
6086 ExeName() : m_name( std::make_shared<std::string>( "<executable>" ) ) {}
6087
6088 explicit ExeName( std::string &ref ) : ExeName() {
6089 m_ref = std::make_shared<BoundValueRef<std::string>>( ref );
6090 }
6091
6092 template<typename LambdaT>
6093 explicit ExeName( LambdaT const& lambda ) : ExeName() {
6094 m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda );
6095 }
6096
6097 // The exe name is not parsed out of the normal tokens, but is handled specially
6098 auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
6099 return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
6100 }
6101
6102 auto name() const -> std::string { return *m_name; }
6103 auto set( std::string const& newName ) -> ParserResult {
6104
6105 auto lastSlash = newName.find_last_of( "\\/" );
6106 auto filename = ( lastSlash == std::string::npos )
6107 ? newName
6108 : newName.substr( lastSlash+1 );
6109
6110 *m_name = filename;
6111 if( m_ref )
6112 return m_ref->setValue( filename );
6113 else
6114 return ParserResult::ok( ParseResultType::Matched );
6115 }
6116 };
6117
6118 class Arg : public ParserRefImpl<Arg> {
6119 public:

Callers 1

makeCommandLineParserFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected