#include #include #include "JLang/JCategory.hh" #include "Jeep/JProperties.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; /** * Test data structure. */ struct JABC { /** * Constructor. * * \param a a * \param b b * \param c c * \param d d * \param e e */ JABC(const int a, const int b, const int c, const int d, const int e) { this->a = a; this->b = b; this->c = c; this->d = d; this->e = e; } int a; int b; int c; int d; int e; /** * Get equation parameters. * * \return equation parameters */ static inline JEquationParameters& getEquationParameters() { static JEquationParameters equation("=", "\n;", "./", "#"); return equation; } /** * Get format. * * \return equation parameters */ static inline std::string& getFormat() { static std::string format("a b c d e"); return format; } /** * Get properties of this class. * * \param object test data * \param equation equation parameters */ template static JProperties getProperties(typename JCategory::reference_type object, const JEquationParameters& equation = JABC::getEquationParameters(), const int debug = 0) { JProperties properties(equation, debug); properties.insert(gmake_property(object.a)); properties.insert(gmake_property(object.b)); properties.insert(gmake_property(object.c)); properties.insert(gmake_property(object.d)); properties.insert(gmake_property(object.e)); return properties; } /** * Stream input of test data. * * \param in input stream * \param object test data * \return input stream */ friend inline std::istream& operator>>(std::istream& in, JABC& object) { return JEEP::getProperties(object, getEquationParameters(), 1).read(in, getFormat()); } /** * Stream output of test data. * * \param out output stream * \param object test data * \return output stream */ friend inline std::ostream& operator<<(std::ostream& out, const JABC& object) { return JEEP::getProperties(object, getEquationParameters(), 1).write(out, getFormat()); } }; } /** * \file * Example program to test JPROPERTIES::JProperties class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; string buffer; string format; int debug; try { JParser<> zap; zap['f'] = make_field(buffer); zap['F'] = make_field(format); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } JABC test(10, 20, 30, 40, 50); ASSERT(buffer != ""); ASSERT(format != ""); DEBUG("test: " << endl); DEBUG(getProperties(test)); DEBUG("processing " << buffer << endl); istringstream is(buffer); is >> getProperties(test); DEBUG("test: " << endl); DEBUG(getProperties(test)); DEBUG("format " << format << endl); JProperties properties = getProperties(test); DEBUG("--> " << properties.sed(format, "%") << endl); // output for test cout << properties.sed(format, "%") << flush; return 0; }