Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit 5fa7b72

Browse files
committed
v1.1.1
1 parent b94d908 commit 5fa7b72

File tree

3 files changed

+38
-49
lines changed

3 files changed

+38
-49
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Clara 1.1.0
1+
# Clara v1.1.1
22
[![Build Status](https://travis-ci.org/catchorg/Clara.svg?branch=master)](https://travis-ci.org/catchorg/Clara)
33
[![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Clara?brach=master&svg=true)](https://ci.appveyor.com/project/catchorg/clara)
44
[![codecov](https://codecov.io/gh/catchorg/Clara/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Clara)
@@ -94,7 +94,7 @@ To see which direction Clara is going in, please see [the roadmap](Roadmap.md)
9494
## Old version
9595

9696
If you used the earlier, v0.x, version of Clara please note that this is a complete rewrite which assumes C++11 and has
97-
a different interface (composability was a big step forward). Conversion between v0.x and v1.x is a fairly simple and mechanical task, but is a bit of manual
97+
a different interface (composability was a big step forward). Conversion between v0.x and v1.x is a fairly simple and mechanical task, but is a bit of manual
9898
work - so don't take this version until you're ready (and, of course, able to use C++11).
9999

100100
I hope you'll find the new interface an improvement - and this will be built on to offer new features moving forwards.

include/clara.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// See https://github.com/philsquared/Clara for more details
77

8-
// Clara v1.1.0
8+
// Clara v1.1.1
99

1010
#ifndef CLARA_HPP_INCLUDED
1111
#define CLARA_HPP_INCLUDED
@@ -462,7 +462,7 @@ namespace detail {
462462
public:
463463
template<typename T>
464464
auto operator|( T const &other ) const -> Parser;
465-
465+
466466
template<typename T>
467467
auto operator+( T const &other ) const -> Parser;
468468
};

single_include/clara.hpp

Lines changed: 34 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
// See https://github.com/philsquared/Clara for more details
77

8-
// Clara v1.1.0
8+
// Clara v1.1.1
99

1010
#ifndef CLARA_HPP_INCLUDED
1111
#define CLARA_HPP_INCLUDED
@@ -659,57 +659,41 @@ namespace detail {
659659
return ParserResult::ok( ParseResultType::Matched );
660660
}
661661

662-
struct BoundRefBase {
663-
BoundRefBase() = default;
664-
BoundRefBase( BoundRefBase const & ) = delete;
665-
BoundRefBase( BoundRefBase && ) = delete;
666-
BoundRefBase &operator=( BoundRefBase const & ) = delete;
667-
BoundRefBase &operator=( BoundRefBase && ) = delete;
668-
669-
virtual ~BoundRefBase() = default;
662+
struct NonCopyable {
663+
NonCopyable() = default;
664+
NonCopyable( NonCopyable const & ) = delete;
665+
NonCopyable( NonCopyable && ) = delete;
666+
NonCopyable &operator=( NonCopyable const & ) = delete;
667+
NonCopyable &operator=( NonCopyable && ) = delete;
668+
};
670669

671-
virtual auto isFlag() const -> bool = 0;
670+
struct BoundRef : NonCopyable {
671+
virtual ~BoundRef() = default;
672672
virtual auto isContainer() const -> bool { return false; }
673-
virtual auto setValue( std::string const &arg ) -> ParserResult = 0;
674-
virtual auto setFlag( bool flag ) -> ParserResult = 0;
675673
};
676-
677-
struct BoundValueRefBase : BoundRefBase {
678-
auto isFlag() const -> bool override { return false; }
679-
680-
auto setFlag( bool ) -> ParserResult override {
681-
return ParserResult::logicError( "Flags can only be set on boolean fields" );
682-
}
674+
struct BoundValueRefBase : BoundRef {
675+
virtual auto setValue( std::string const &arg ) -> ParserResult = 0;
683676
};
684-
685-
struct BoundFlagRefBase : BoundRefBase {
686-
auto isFlag() const -> bool override { return true; }
687-
688-
auto setValue( std::string const &arg ) -> ParserResult override {
689-
bool flag = false;
690-
auto result = convertInto( arg, flag );
691-
if( result )
692-
setFlag( flag );
693-
return result;
694-
}
677+
struct BoundFlagRefBase : BoundRef {
678+
virtual auto setFlag( bool flag ) -> ParserResult = 0;
695679
};
696680

697681
template<typename T>
698-
struct BoundRef : BoundValueRefBase {
682+
struct BoundValueRef : BoundValueRefBase {
699683
T &m_ref;
700684

701-
explicit BoundRef( T &ref ) : m_ref( ref ) {}
685+
explicit BoundValueRef( T &ref ) : m_ref( ref ) {}
702686

703687
auto setValue( std::string const &arg ) -> ParserResult override {
704688
return convertInto( arg, m_ref );
705689
}
706690
};
707691

708692
template<typename T>
709-
struct BoundRef<std::vector<T>> : BoundValueRefBase {
693+
struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
710694
std::vector<T> &m_ref;
711695

712-
explicit BoundRef( std::vector<T> &ref ) : m_ref( ref ) {}
696+
explicit BoundValueRef( std::vector<T> &ref ) : m_ref( ref ) {}
713697

714698
auto isContainer() const -> bool override { return true; }
715699

@@ -754,7 +738,7 @@ namespace detail {
754738

755739
template<typename ArgType, typename L>
756740
inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult {
757-
ArgType temp;
741+
ArgType temp{};
758742
auto result = convertInto( arg, temp );
759743
return !result
760744
? result
@@ -819,16 +803,16 @@ namespace detail {
819803
class ParserRefImpl : public ComposableParserImpl<DerivedT> {
820804
protected:
821805
Optionality m_optionality = Optionality::Optional;
822-
std::shared_ptr<BoundRefBase> m_ref;
806+
std::shared_ptr<BoundRef> m_ref;
823807
std::string m_hint;
824808
std::string m_description;
825809

826-
explicit ParserRefImpl( std::shared_ptr<BoundRefBase> const &ref ) : m_ref( ref ) {}
810+
explicit ParserRefImpl( std::shared_ptr<BoundRef> const &ref ) : m_ref( ref ) {}
827811

828812
public:
829813
template<typename T>
830814
ParserRefImpl( T &ref, std::string const &hint )
831-
: m_ref( std::make_shared<BoundRef<T>>( ref ) ),
815+
: m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
832816
m_hint( hint )
833817
{}
834818

@@ -869,18 +853,18 @@ namespace detail {
869853

870854
class ExeName : public ComposableParserImpl<ExeName> {
871855
std::shared_ptr<std::string> m_name;
872-
std::shared_ptr<BoundRefBase> m_ref;
856+
std::shared_ptr<BoundValueRefBase> m_ref;
873857

874858
template<typename LambdaT>
875-
static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundRefBase> {
859+
static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundValueRefBase> {
876860
return std::make_shared<BoundLambda<LambdaT>>( lambda) ;
877861
}
878862

879863
public:
880864
ExeName() : m_name( std::make_shared<std::string>( "<executable>" ) ) {}
881865

882866
explicit ExeName( std::string &ref ) : ExeName() {
883-
m_ref = std::make_shared<BoundRef<std::string>>( ref );
867+
m_ref = std::make_shared<BoundValueRef<std::string>>( ref );
884868
}
885869

886870
template<typename LambdaT>
@@ -923,7 +907,10 @@ namespace detail {
923907
if( token.type != TokenType::Argument )
924908
return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
925909

926-
auto result = m_ref->setValue( remainingTokens->token );
910+
assert( dynamic_cast<detail::BoundValueRefBase*>( m_ref.get() ) );
911+
auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() );
912+
913+
auto result = valueRef->setValue( remainingTokens->token );
927914
if( !result )
928915
return InternalParseResult( result );
929916
else
@@ -996,20 +983,22 @@ namespace detail {
996983
if( remainingTokens && remainingTokens->type == TokenType::Option ) {
997984
auto const &token = *remainingTokens;
998985
if( isMatch(token.token ) ) {
999-
if( m_ref->isFlag() ) {
1000-
auto result = m_ref->setFlag( true );
986+
if( auto flagRef = dynamic_cast<detail::BoundFlagRefBase*>( m_ref.get() ) ) {
987+
auto result = flagRef->setFlag( true );
1001988
if( !result )
1002989
return InternalParseResult( result );
1003990
if( result.value() == ParseResultType::ShortCircuitAll )
1004991
return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
1005992
} else {
993+
assert( dynamic_cast<detail::BoundValueRefBase*>( m_ref.get() ) );
994+
auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() );
1006995
++remainingTokens;
1007996
if( !remainingTokens )
1008997
return InternalParseResult::runtimeError( "Expected argument following " + token.token );
1009998
auto const &argToken = *remainingTokens;
1010999
if( argToken.type != TokenType::Argument )
10111000
return InternalParseResult::runtimeError( "Expected argument following " + token.token );
1012-
auto result = m_ref->setValue( argToken.token );
1001+
auto result = valueRef->setValue( argToken.token );
10131002
if( !result )
10141003
return InternalParseResult( result );
10151004
if( result.value() == ParseResultType::ShortCircuitAll )

0 commit comments

Comments
 (0)