#include #include #include "JMath/JZero.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { struct __A__ { /** * Default constructor. */ __A__() : a(0) {} /** * Constructor. * * \param a value */ __A__(double a) { this->a = a; } /** * Equals operator. * * \param first first value * \param second second value * \return true if first and second value are equal; else false */ friend inline bool operator==(const __A__& first, const __A__& second) { return first.a == second.a; } /** * Write object to output. * * \param out output stream * \param object object * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const __A__& object) { return out << object.a; } double a; }; /** * Test equaliilty. * * \param zero zero value * \return true if JMath::zero equals given zero value; else false */ template bool inline is_equal(const T& zero) { T value = JMATH::zero; return value == zero; } /** * Print class and zero value. * * \param out output stream * \param name class name */ template inline void print(std::ostream& out, const char* name) { using namespace std; T value = JMATH::zero; out << setw(12) << left << name << ' ' << value << endl; } #define PRINT(OUT, CLASS) print(OUT, #CLASS) } /** * \file * * Example program to test zero values (JMATH::zero). * \author mdejong */ int main(int argc, char**argv) { using namespace std; int debug; try { JParser<> zap("Example program to test zero values of non-primitive data types."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; PRINT(cout, int); PRINT(cout, float); PRINT(cout, double); PRINT(cout, __A__); ASSERT(is_equal (0)); ASSERT(is_equal (0.0)); ASSERT(is_equal(0.0)); ASSERT(is_equal<__A__> (__A__(0))); return 0; }