#include #include #include #include "JLang/JEquals.hh" #include "JLang/JMultiEquals.hh" #include "JLang/JTemplateWriter.hh" #include "JLang/JTemplateReader.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::istream& operator>>(std::istream& in, __A__& object) { return in >> 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::istream& operator>>(std::istream& in, __B__& object) { return in >> object.value; } friend std::ostream& operator<<(std::ostream& out, const __B__& object) { return out << object.value; } int value; }; struct __C__ : public JEquals<__C__> { __C__() : value(0) {} __C__(int __value) : value(__value) {} bool equals(const __C__& object) const { return this->value == object.value; } friend std::istream& operator>>(std::istream& in, __C__& object) { return in >> object.value; } friend std::ostream& operator<<(std::ostream& out, const __C__& object) { return out << object.value; } int value; }; /** * Composite data structure. */ struct __D__ : public __A__, public __B__, public __C__, public JMultiEquals<__D__, JTYPELIST<__A__, __B__, __C__>::typelist>, public JTemplateReader::typelist>, public JTemplateWriter::typelist> { __D__() : __A__(), __B__(), __C__() {} __D__(const int a, const int b, const int c) : __A__(a), __B__(b), __C__(c) {} }; } /** * \file * * Example program to test JLANG::JTemplateReader and JLANG::JTemplateWriter classes. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test template I/O."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; const __D__ a(1,2,3); { stringstream io; io << a; __D__ b; io >> b; DEBUG("a = " << a << endl); DEBUG("b = " << b << endl); ASSERT(a == b); } { JTemplateWriter::WHITE_SPACE = "|"; stringstream io; io << a; for (int value, i = 0; io >> value; ++i) { const int c = io.get(); ASSERT((i < 2 && c == (int) '|') || (i == 2 && c == EOF)); } } return 0; }