#include #include #include "JLang/JEquals.hh" #include "JLang/JMultiEquals.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; struct __A__ : public JEquals<__A__> { __A__() : value(0) {} __A__(int __value) : value(__value) {} bool equals(const __A__& object) const { return this->value == object.value; } friend std::ostream& operator<<(std::ostream& out, const __A__& object) { return out << object.value; } int value; }; struct __B__ : public JEquals<__B__> { __B__() : value(0) {} __B__(int __value) : value(__value) {} bool equals(const __B__& object) const { return this->value == object.value; } friend std::ostream& operator<<(std::ostream& out, const __B__& object) { return out << object.value; } int value; }; struct __C__ : public __A__, public __B__, public JMultiEquals<__C__, __A__> { __C__(const int a, const int b) : __A__(a), __B__(b) {} friend std::ostream& operator<<(std::ostream& out, const __C__& object) { return out << static_cast(object) << ' ' << static_cast(object); } }; struct __D__ : public __A__, public __B__, public JMultiEquals<__D__, JTYPELIST<__A__, __B__>::typelist> { __D__(const int a, const int b) : __A__(a), __B__(b) {} friend std::ostream& operator<<(std::ostream& out, const __D__& object) { return out << static_cast(object) << ' ' << static_cast(object); } }; /** * Print. * * \param OUT output stream * \param OP operator * \param A first object * \param B second object */ #define PRINT(OUT,OP,A,B) \ OUT << "(" << A << ") " << #OP " (" << B << ") => " << (A OP B) << std::endl; } /** * \file * * Example program to test JLANG::JMultiEquals class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test object comparisons."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } __C__ c1(1,1); __C__ c2(1,1); __C__ c3(0,1); __C__ c4(1,0); PRINT(cout, ==, c1, c2); PRINT(cout, !=, c1, c2); PRINT(cout, ==, c1, c3); PRINT(cout, !=, c1, c3); PRINT(cout, ==, c1, c4); PRINT(cout, !=, c1, c4); ASSERT(c1 == c2); ASSERT(c1 != c3); ASSERT(c1 == c4); __D__ d1(1,1); __D__ d2(1,1); __D__ d3(0,1); __D__ d4(1,0); PRINT(cout, ==, d1, d2); PRINT(cout, !=, d1, d2); PRINT(cout, ==, d1, d3); PRINT(cout, !=, d1, d3); PRINT(cout, ==, d1, d4); PRINT(cout, !=, d1, d4); ASSERT(d1 == d2); ASSERT(d1 != d3); ASSERT(d1 != d4); return 0; }