| 
									
										
										
										
											2012-11-01 08:27:09 +00: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_LHS_HPP_INCLUDED
 | 
					
						
							|  |  |  | #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "catch_expressionresult_builder.h"
 | 
					
						
							|  |  |  | #include "catch_evaluate.hpp"
 | 
					
						
							| 
									
										
										
										
											2013-09-14 19:58:45 +01:00
										 |  |  | #include "catch_tostring.hpp"
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Catch { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  | // Wraps the LHS of an expression and captures the operator and RHS (if any) -
 | 
					
						
							|  |  |  | // wrapping them all in an ExpressionResultBuilder object
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | template<typename T> | 
					
						
							|  |  |  | class ExpressionLhs { | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  |     ExpressionLhs& operator = ( ExpressionLhs const& ); | 
					
						
							|  |  |  | #  ifdef CATCH_CPP11_OR_GREATER
 | 
					
						
							|  |  |  |     ExpressionLhs& operator = ( ExpressionLhs && ) = delete; | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2012-11-16 10:47:33 +01:00
										 |  |  |     ExpressionLhs( T lhs ) : m_lhs( lhs ) {} | 
					
						
							| 
									
										
										
										
											2014-03-20 12:48:19 +01:00
										 |  |  | #  ifdef CATCH_CPP11_OR_GREATER
 | 
					
						
							|  |  |  |     ExpressionLhs( ExpressionLhs const& ) = default; | 
					
						
							|  |  |  |     ExpressionLhs( ExpressionLhs && )     = default; | 
					
						
							|  |  |  | #  endif
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator == ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator != ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsNotEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator < ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsLessThan>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator > ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsGreaterThan>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator <= ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     template<typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& operator >= ( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ExpressionResultBuilder& operator == ( bool rhs ) { | 
					
						
							|  |  |  |         return captureExpression<Internal::IsEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     ExpressionResultBuilder& operator != ( bool rhs ) { | 
					
						
							|  |  |  |         return captureExpression<Internal::IsNotEqualTo>( rhs ); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-07-03 19:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-13 21:59:50 +00:00
										 |  |  |     ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         bool value = m_lhs ? true : false; | 
					
						
							|  |  |  |         return m_result | 
					
						
							|  |  |  |             .setLhs( Catch::toString( value ) ) | 
					
						
							|  |  |  |             .setResultType( value ) | 
					
						
							| 
									
										
										
										
											2012-11-13 21:59:50 +00:00
										 |  |  |             .endExpression( resultDisposition ); | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Only simple binary expressions are allowed on the LHS.
 | 
					
						
							|  |  |  |     // If more complex compositions are required then place the sub expression in parentheses
 | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); | 
					
						
							|  |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); | 
					
						
							|  |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); | 
					
						
							|  |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); | 
					
						
							| 
									
										
										
										
											2013-06-29 12:07:33 +01:00
										 |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); | 
					
						
							|  |  |  |     template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     template<Internal::Operator Op, typename RhsT> | 
					
						
							| 
									
										
										
										
											2013-04-23 18:58:56 +01:00
										 |  |  |     ExpressionResultBuilder& captureExpression( RhsT const& rhs ) { | 
					
						
							| 
									
										
										
										
											2012-11-01 08:27:09 +00:00
										 |  |  |         return m_result | 
					
						
							|  |  |  |             .setResultType( Internal::compare<Op>( m_lhs, rhs ) ) | 
					
						
							|  |  |  |             .setLhs( Catch::toString( m_lhs ) ) | 
					
						
							|  |  |  |             .setRhs( Catch::toString( rhs ) ) | 
					
						
							|  |  |  |             .setOp( Internal::OperatorTraits<Op>::getName() ); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     ExpressionResultBuilder m_result; | 
					
						
							|  |  |  |     T m_lhs; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // end namespace Catch
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
 |