00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef MOCKPP_ResponseVector1_H
00032 #define MOCKPP_ResponseVector1_H
00033
00034 #include <mockpp/constraint/ConstraintHolder.h>
00035 #include <mockpp/constraint/IsEqual.h>
00036 #include <mockpp/visiting/VisitableMockObject_template.h>
00037
00038
00039 MOCKPP_NS_START
00040
00041
00045 template <typename P1>
00046 class ResponseThrowableVector1 : public ResponseVectorBase
00047 {
00048 public:
00049
00055 ResponseThrowableVector1(const String &aName, VerifiableList *parent)
00056 : ResponseVectorBase(aName, parent)
00057 {}
00058
00061 virtual ~ResponseThrowableVector1()
00062 {
00063 reset();
00064 }
00065
00071 void add(Throwable *throwable, const P1 &p1, unsigned count)
00072 {
00073 const ConstraintHolder<P1> h1 = new IsEqual<P1>(p1);
00074 add(throwable, h1, count);
00075 }
00076
00082 void add(Throwable *throwable,
00083 const ConstraintHolder<P1> &p1,
00084 unsigned count)
00085 {
00086 counter.push_back(count);
00087 tvec.push_back(throwable);
00088 typename MOCKPP_NS::Constraint<P1>::AP cons1 (p1);
00089 t1vec.push_back(cons1.release());
00090 }
00091
00094 void reset()
00095 {
00096 counter.clear();
00097 tvec.reset();
00098
00099 for (unsigned i1 = 0; i1 < t1vec.size(); ++i1)
00100 delete t1vec[i1];
00101 t1vec.clear();
00102 }
00103
00109 bool find(Throwable * &throwable, const P1 &p1)
00110 {
00111 for (unsigned i = 0; i < t1vec.size(); ++i)
00112 if ( counter[i] > 0
00113 && t1vec[i]->eval(p1)
00114 )
00115 {
00116 if (tvec.at(i) == 0)
00117 return false;
00118
00119 if (counter[i] != MOCKPP_UNLIMITED)
00120 --counter[i];
00121
00122 throwable = tvec.at(i);
00123 return true;
00124 }
00125 return false;
00126 }
00127
00128 protected:
00129
00130 MOCKPP_STL::vector<Constraint<P1>*> t1vec;
00131 };
00132
00133
00137 template <typename R, typename P1>
00138 class ResponseVector1 : public ResponseThrowableVector1<P1>
00139 {
00140 public:
00141
00146 ResponseVector1(const String &aName, VerifiableList *parent)
00147 : ResponseThrowableVector1<P1>(aName, parent)
00148 {}
00149
00155 void add(Throwable *throwable, const P1 &p1, unsigned count)
00156 {
00157 MOCKPP_ASSERT_TRUE(throwable != 0);
00158 ResponseThrowableVector1<P1>::add(throwable, p1, count);
00159 R r;
00160 rvec.push_back(r);
00161 }
00162
00168 void add(Throwable *throwable,
00169 const ConstraintHolder<P1> &p1,
00170 unsigned count)
00171 {
00172 MOCKPP_ASSERT_TRUE(throwable != 0);
00173 ResponseThrowableVector1<P1>::add (throwable, p1, count);
00174 R r;
00175 rvec.push_back(r);
00176 }
00177
00183 void add(const R &r, const P1 &p1, unsigned count)
00184 {
00185 ResponseThrowableVector1<P1>::add((Throwable*)0, p1, count);
00186 rvec.push_back(r);
00187 }
00188
00194 void add(const R &r,
00195 const ConstraintHolder<P1> &p1,
00196 unsigned count)
00197 {
00198 ResponseThrowableVector1<P1>::add((Throwable*)0, p1, count);
00199 rvec.push_back(r);
00200 }
00201
00204 void reset()
00205 {
00206 ResponseThrowableVector1<P1>::reset();
00207 rvec.clear();
00208 }
00209
00210 #if defined(__BORLANDC__) || (__GNUC__ < 3) // ==> BCB5.5.1 ?? F1004 Internal compiler error at 0x12548c1 with base 0x1200000
00211 bool find(Throwable * &throwable, const P1 &p1)
00212 {
00213 return ResponseThrowableVector1<P1>::find(throwable, p1);
00214 }
00215 #else
00216 using ResponseThrowableVector1<P1>::find;
00217 #endif
00218
00224 bool find(R &r, const P1 &p1)
00225 {
00226 for (unsigned i = 0; i < this->t1vec.size(); ++i)
00227 if ( this->counter[i] > 0
00228 && this->t1vec[i]->eval(p1)
00229 )
00230 {
00231 if (this->tvec.at(i) != 0)
00232 return false;
00233
00234 if (this->counter[i] != MOCKPP_UNLIMITED)
00235 --this->counter[i];
00236
00237 r = rvec[i];
00238 return true;
00239 }
00240 return false;
00241 }
00242
00243 private:
00244
00245 MOCKPP_STL::vector<R> rvec;
00246 };
00247
00248 MOCKPP_NS_END
00249
00250
00251 #endif // MOCKPP_ResponseVector1_H
00252