00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef MOCKPP_OR_H
00035 #define MOCKPP_OR_H
00036
00037 #include <mockpp/mockpp.h>
00038
00039 #include <mockpp/constraint/ConstraintHolder.h>
00040
00041
00042 MOCKPP_NS_START
00043
00044
00051 template <typename T>
00052 class Or : public Constraint<T>
00053 {
00054 public:
00055
00062 Or( const ConstraintHolder<T> &in_left,
00063 const ConstraintHolder<T> &in_right,
00064 bool in_short = true )
00065 : left( in_left )
00066 , right( in_right )
00067 , shortcut(in_short)
00068 {}
00069
00072 virtual ~Or()
00073 {}
00074
00080 virtual bool eval( const T &o ) const
00081 {
00082 if (shortcut)
00083 return left->eval( o ) || right->eval( o );
00084
00085 else
00086 {
00087 const bool res_left = left->eval( o );
00088 const bool res_right = right->eval( o );
00089
00090 return res_left || res_right;
00091 }
00092 }
00093
00099 virtual bool verify( const T &arg ) const
00100 {
00101 if (shortcut)
00102 return left->verify(arg) || right->verify(arg);
00103
00104 else
00105 {
00106 const bool res_left = left->verify( arg );
00107 const bool res_right = right->verify( arg );
00108
00109 return res_left || res_right;
00110 }
00111 }
00112
00117 virtual String describeTo( String &buffer ) const
00118 {
00119 buffer += MOCKPP_PCHAR( "(" );
00120 buffer = left->describeTo( buffer );
00121 buffer += MOCKPP_PCHAR( " || " );
00122 buffer = right->describeTo( buffer );
00123 buffer += MOCKPP_PCHAR( ")" );
00124 return buffer;
00125 }
00126
00127 private:
00128
00129 const typename Constraint<T>::AP left;
00130 const typename Constraint<T>::AP right;
00131 bool shortcut;
00132 };
00133
00134
00135 MOCKPP_NS_END
00136
00137
00138 #endif // MOCKPP_OR_H