#include #include #include #include #include "JLang/JSTDObjectReader.hh" #include "JLang/JSTDObjectWriter.hh" #include "JLang/JStreamObjectOutput.hh" #include "JLang/JObjectSelector.hh" #include "JLang/JPipe.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { using namespace JPP; /** * Modulo selector. */ struct JModulo : public JObjectSelector { typedef JObjectSelector::argument_type argument_type; /** * Constructor. * * \param mod modulo */ JModulo(int mod) { this->mod = mod; } /** * Accept object. * * \param object object * \return true if accepted; else false */ virtual bool accept(argument_type object) const { if (mod == 0) return true; else if (mod > 0) return ((int) object) % mod == 0; else return false; } int mod; }; } /** * \file * * Example program to test JLANG::JPipe class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int mod; int debug; try { JParser<> zap("Example program to test object iteration using pipe."); zap['M'] = make_field(mod) = 2; zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } typedef vector buffer_type; buffer_type buffer; for (int i = 0; i != 20; ++i) { buffer.push_back(i); } JSTDObjectReader in(buffer); if (debug >= debug_t) { JStreamObjectOutput out(cout, "\n"); in | JModulo(mod) | out; } buffer_type data; JSTDObjectWriter out(data); in.rewind(); in | JModulo(mod) | out; ASSERT(!data.empty()); for (buffer_type::const_iterator i = data.begin(); i != data.end(); ++i) { ASSERT((*i)%mod == 0); } return 0; }