/* * Created by Phil on 11/5/2012. * Copyright 2012 Two Blue Cubes Ltd. All rights reserved. * * Distributed under the Boost Software License, Version 1.0. (See accompanying * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #ifndef TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED #include "catch_result_builder.h" #include "catch_expressionresult_builder.h" #include "catch_evaluate.hpp" #include "catch_tostring.h" #include namespace Catch { struct ResultBuilder; ExpressionResultBuilder& getResultBuilder( ResultBuilder* rb ); // Wraps the LHS of an expression and captures the operator and RHS (if any) - // wrapping them all in an ExpressionResultBuilder object template class ExpressionLhs { ExpressionLhs& operator = ( ExpressionLhs const& ); # ifdef CATCH_CPP11_OR_GREATER ExpressionLhs& operator = ( ExpressionLhs && ) = delete; # endif public: ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( &rb ), m_lhs( lhs ) {} # ifdef CATCH_CPP11_OR_GREATER ExpressionLhs( ExpressionLhs const& ) = default; ExpressionLhs( ExpressionLhs && ) = default; # endif template ExpressionResultBuilder& operator == ( RhsT const& rhs ) { return captureExpression( rhs ); } template ExpressionResultBuilder& operator != ( RhsT const& rhs ) { return captureExpression( rhs ); } template ExpressionResultBuilder& operator < ( RhsT const& rhs ) { return captureExpression( rhs ); } template ExpressionResultBuilder& operator > ( RhsT const& rhs ) { return captureExpression( rhs ); } template ExpressionResultBuilder& operator <= ( RhsT const& rhs ) { return captureExpression( rhs ); } template ExpressionResultBuilder& operator >= ( RhsT const& rhs ) { return captureExpression( rhs ); } ExpressionResultBuilder& operator == ( bool rhs ) { return captureExpression( rhs ); } ExpressionResultBuilder& operator != ( bool rhs ) { return captureExpression( rhs ); } void endExpression() { assert( m_rb ); bool value = m_lhs ? true : false; getResultBuilder( m_rb ) .setLhs( Catch::toString( value ) ) .setResultType( value ) .endExpression(); } // Only simple binary expressions are allowed on the LHS. // If more complex compositions are required then place the sub expression in parentheses template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); template STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); private: template ExpressionResultBuilder& captureExpression( RhsT const& rhs ) { assert( m_rb ); return getResultBuilder( m_rb ) .setResultType( Internal::compare( m_lhs, rhs ) ) .setLhs( Catch::toString( m_lhs ) ) .setRhs( Catch::toString( rhs ) ) .setOp( Internal::OperatorTraits::getName() ); } private: ResultBuilder* m_rb; T m_lhs; }; } // end namespace Catch #endif // TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED