#include #include #include #include "JLang/JStreamAvailable.hh" #include "JLang/JBool.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" struct __A__ { /** * Read object from input. * * \param in input stream * \param object object * \return input stream */ friend inline std::istream& operator>>(std::istream& in, __A__& object) { return in; } }; template struct __B__ {}; /** * Write object to output. * * \param out output stream * \param object object * \return output stream */ template inline std::ostream& operator<<(std::ostream& out, const __B__& object) { return out << "__B__"; } struct __C__ {}; namespace std { /** * Read std::vector from input. * * \param in input stream * \param object object * \return input stream */ inline std::istream& operator>>(std::istream& in, std::vector& object) { for (int value; in >> value; ) { object.push_back(value); } return in; } /** * Write std::vector to output. * * \param out output stream * \param object object * \return output stream */ inline std::ostream& operator<<(std::ostream& out, const std::vector& object) { for (std::vector::const_iterator i = object.begin(); i != object.end(); ++i) { out << ' ' << *i; } return out; } } namespace { /** * Print object. * * \param out output stream * \param object object * \param option true */ template inline void print(std::ostream& out, const T& object, JLANG::JBool option) { out << object << std::endl; } /** * Print object. * * \param out output stream * \param object object * \param option false */ template inline void print(std::ostream& out, const T& object, JLANG::JBool option) { out << "No output operation available." << std::endl; } /** * Print object. * * \param out output stream * \param object object */ template inline void print(std::ostream& out, const T& object) { print(out, object, JLANG::JBool::has_ostream>()); } } /** * Print class parameters. * * \param OUT output stream * \param CLASS class */ #define PRINT(OUT, CLASS) \ OUT << std::setw(12) << std::left << #CLASS << ' ' ; \ OUT << JStreamAvailable::has_istream << '/'; \ OUT << JStreamAvailable::has_ostream << std::endl; /** * \file * * Example program to test JLANG::JStreamAvailable class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Example program to test availability of I/O stream redirection."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } if (debug >= debug_t) { cout << setw(12) << left << "class" << " I/O" << endl; cout << setw(12) << right << setfill('-') << "" << "+---" << setfill(' ') << endl; PRINT(cout, double); PRINT(cout, __A__); PRINT(cout, __B__); PRINT(cout, __C__); PRINT(cout, vector); print(cout, vector(5, 1)); print(cout, vector(5, 1.0)); __A__ a; __B__ b; __C__ c; cout << "STREAM << __A__: " << STREAM("?") << a << endl; cout << "STREAM << __B__: " << STREAM("?") << b << endl; cout << "STREAM << __C__: " << STREAM("?") << c << endl; } ASSERT( JStreamAvailable<__A__>::has_istream); ASSERT(!JStreamAvailable<__A__>::has_ostream); ASSERT(!JStreamAvailable< __B__ >::has_istream); ASSERT( JStreamAvailable< __B__ >::has_ostream); ASSERT(!JStreamAvailable<__C__>::has_istream); ASSERT(!JStreamAvailable<__C__>::has_ostream); ASSERT( JStreamAvailable< std::vector >::has_istream); ASSERT( JStreamAvailable< vector >::has_ostream); ASSERT(!JStreamAvailable< vector >::has_istream); ASSERT(!JStreamAvailable< vector >::has_ostream); return 0; }