#ifndef __JLANG__JVALVE__ #define __JLANG__JVALVE__ #include "JLang/JDefault.hh" #include "JLang/JTypeList.hh" #include "JLang/JType.hh" /** * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Auxiliary class for selection of data type. */ template class JValve : public JDefault< JValve > { public: /** * Default constructor. * * By default, the valve is open. */ JValve() : status(true) {} /** * Constructor. * * \param controller controller of valve */ template JValve(const JController_t& controller) { (*this)(controller); } /** * Check if valve is open. * * \return true if open; else false */ bool is_open() const { return status; } /** * Open valve. */ void open() { status = true; } /** * Close valve. */ void close() { status = false; } /** * Set valve. * * The template argument JController_t refers to a data structure * which should provide for the function object operator: *
     *   bool operator()(JType& type) const;    // get status of valve
     * 
* * \param controller controller of valve */ template JValve& operator()(const JController_t& controller) { if (controller(JType())) this->open(); else this->close(); return *this; } protected: bool status; }; /** * Auxiliary class for selection of multiple data types. * * This class recursively defines the JLANG::JValve interface * for all data types by deriving from: * - JValve; and * - JValve. */ template class JValve< JTypeList > : public JDefault< JValve< JTypeList > >, public JValve, public JValve { public: using JDefault< JValve< JTypeList > >::getDefault; /** * Default constructor. */ JValve() {} /** * Constructor. * * \param controller controller of valve */ template JValve(const JController_t& controller) { (*this)(controller); } /** * Set valve. * * The template argument JController_t refers to a data structure * which should provide for the function object operator: *
     *   bool operator()(JType& type) const;    // get status of valve
     * 
* * \param controller controller of valve */ template JValve& operator()(const JController_t& controller) { static_cast&>(*this)(controller); static_cast&>(*this)(controller); return *this; } }; /** * Terminator class of recursive JValve class. */ template class JValve< JTypeList > : public JValve { public: /** * Default constructor. */ JValve() {} /** * Constructor. * * \param controller controller of valve */ template JValve(const JController_t& controller) { (*this)(controller); } }; } #endif