#ifndef __JLANG__JCSV__ #define __JLANG__JCSV__ #include #include "JLang/JClass.hh" #include "JLang/JSTDTypes.hh" #include "JLang/JSTDObjectWriter.hh" /** * \file * * Utility method to assign multiple values to STD container. * * \code{.cpp} #include #include "JLang/JCSV.hh" using namespace std; using namespace JLANG; set buffer; assign(buffer) = 1.1, 9.9, 8.8, 7.7; \endcode * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Auxiliary class to assign a sequence of Comma Separated Values (CSV). */ template class JAssignSequence : public JSTDObjectWriter { protected: typedef typename JClass::argument_type argument_type; /** * Auxiliary class to assign the remainder of a sequence of Comma Separated Values. */ struct JCSV : public JSTDObjectWriter { /** * Constructor * * \param out output iterator */ JCSV(const JSTDObjectWriter& out) : JSTDObjectWriter(out) {} /** * Iterator assignment. * * \param value value * \return value parser */ JCSV& operator,(argument_type value) { this->put(value); return *this; } }; public: /** * Constructor * * \param out output iterator */ JAssignSequence(const JSTDObjectWriter& out) : JSTDObjectWriter(out) {} /** * Assignment operator. * * This operator assigns the first of a sequence of Comma Separated Values and * returns the corresponding object to assign the remainder of this sequence. * * \param value value * \return value parser */ JCSV operator=(argument_type value) { this->put(value); return JCSV(*this); } }; /** * Helper method to assign sequence of Comma Separated Values to output iterator. * * \param out output iterator * \return value assigner */ template JAssignSequence iter_assign(const JOutputIterator_t& out) { typedef typename JOutputIterator_t::container_type::value_type value_type; return JAssignSequence(JSTDObjectWriter(JSTDObjectOutput(out))); } /** * Helper method to assign sequence of Comma Separated Values to output container. * * \param out output container * \return value assigner */ template JAssignSequence assign(JContainer_t& out) { typedef typename JContainer_t::value_type value_type; return JAssignSequence(JSTDObjectWriter(out)); } /** * Helper method to assign sequence of Comma Separated Values to output iterator. * * \param out output iterator * \return value assigner */ template JAssignSequence assign(const JOutputIterator_t& out) { return iter_assign(out); } } #endif