#include #include #include #include "Jeep/JStatus.hh" #include "Jeep/JPrint.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; enum { A, B = 5, C }; /** * Auxiliary class to map key to status bit. */ struct JGetStatusBit_t : public JGetStatusBit { /** * Default constructor. */ JGetStatusBit_t() { #define MAKE_ENTRY(A) std::make_pair(#A, A) this->insert(MAKE_ENTRY(A)); this->insert(MAKE_ENTRY(B)); this->insert(MAKE_ENTRY(C)); #undef MAKE_ENTRY } }; /** * Type definition to map status bit to key. */ typedef JPutStatusBit JPutStatusBit_t; /** * Function object to map key to PMT status bit. */ static const JGetStatusBit_t getStatusBit; /** * Function object to map status bit to key. */ static const JPutStatusBit_t putStatusBit(getStatusBit); } /** * \file * * Auxiliary program to test status handling. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Auxiliary program to test status handling."); zap['d'] = make_field(debug) = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JStatus status; for (int bit : { A, B, C }) { ASSERT(!status.has(bit), "Test of status bit " << bit); status.set(bit); if (debug >= debug_t) { print(cout, status, putStatusBit); } ASSERT( status.has(bit), "Test of status bit " << bit); status.reset(bit); ASSERT(!status.has(bit), "Test of status bit " << bit); } #define TEST(STATUS,A) \ STATUS.set(getStatusBit(#A)); \ if (debug >= debug_t) { print(cout, STATUS, getStatusBit); } \ ASSERT( STATUS.has(A), "Test of status bit " << #A); \ STATUS.reset(A); \ ASSERT(!STATUS.has(A), "Test of status bit " << #A); TEST(status, A); TEST(status, B); TEST(status, C); return 0; }