catch2/include/internal/catch_expression.hpp

120 lines
3.5 KiB
C++
Raw Normal View History

2012-05-11 09:03:05 +02:00
/*
* 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_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED
#include "catch_resultinfo_builder.hpp"
#include "catch_evaluate.hpp"
2012-05-15 08:42:26 +02:00
namespace Catch {
2012-05-11 09:03:05 +02:00
template<typename T>
2012-05-15 08:42:26 +02:00
class Expression {
2012-05-11 09:03:05 +02:00
void operator = ( const Expression& );
public:
2012-05-11 09:16:12 +02:00
Expression( ResultInfoBuilder& result, T lhs )
2012-05-11 09:03:05 +02:00
: m_result( result ),
m_lhs( lhs )
2012-05-11 09:16:12 +02:00
{}
2012-05-11 09:03:05 +02:00
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator == ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator != ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator < ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator > ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
}
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator == ( bool rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
}
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator != ( bool rhs ) {
2012-05-11 09:03:05 +02:00
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
}
2012-05-11 09:16:12 +02:00
operator ResultInfoBuilder& () {
2012-05-11 09:03:05 +02:00
return m_result.captureBoolExpression( m_lhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
2012-05-11 09:03:05 +02:00
template<typename RhsT>
2012-05-11 09:16:12 +02:00
STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
2012-05-11 09:03:05 +02:00
private:
ResultInfoBuilder& m_result;
T m_lhs;
};
template<typename LhsT>
2012-05-15 08:42:26 +02:00
class PtrExpression {
2012-05-11 09:03:05 +02:00
public:
2012-05-11 09:16:12 +02:00
PtrExpression ( ResultInfoBuilder& result, const LhsT* lhs )
2012-05-11 09:03:05 +02:00
: m_result( &result ),
m_lhs( lhs )
{}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator == ( const RhsT* rhs ) {
2012-05-11 09:03:05 +02:00
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
}
// This catches NULL
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator == ( LhsT* rhs ) {
2012-05-11 09:03:05 +02:00
return m_result->captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
}
template<typename RhsT>
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator != ( const RhsT* rhs ) {
2012-05-11 09:03:05 +02:00
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
}
// This catches NULL
2012-05-11 09:16:12 +02:00
ResultInfoBuilder& operator != ( LhsT* rhs ) {
2012-05-11 09:03:05 +02:00
return m_result->captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
}
2012-05-11 09:16:12 +02:00
operator ResultInfoBuilder& () {
2012-05-11 09:03:05 +02:00
return m_result->captureBoolExpression( m_lhs );
}
private:
ResultInfoBuilder* m_result;
const LhsT* m_lhs;
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED