#ifndef __JTOOLS__JAUTOMAP__ #define __JTOOLS__JAUTOMAP__ #include #include "JLang/JTypeList.hh" #include "JLang/JType.hh" #include "JLang/JNullType.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { using JLANG::JTypeList; using JLANG::JType; using JLANG::JNullType; /** * \cond NEVER * Forward declaration for specialisation of class JAutomate. * \endcond */ template class JAutoMap; /** * Auxiliary class for automatic element creation. * * The template argument corresponds to the data type of the elements in the map.\n * There should be a corresponding constructor *
   *    JElement_t::JElement_t(JType);
   * 
* for each data type T to be inserted in the map. */ template struct JAutomate { /** * Get element. * * \param type data type * \return element */ template static JElement_t getElement(JType type) { return JElement_t(type); } }; /** * Specialisation of class JAutomate for class JAutoMap. * * By default, the creation of elements is transfered back to the map * by calling member method JAutoMap::getAutoElement. */ template struct JAutomate< JAutoMap > { typedef JAutoMap automap_type; typedef typename automap_type::value_type value_type; /** * Get element. * * \param type data type * \return element */ template static value_type getElement(JType type) { return automap_type::getAutoElement(type); } }; /** * Wrapper class around std::map for automatic insertion of elements based on data types. */ template class JAutoMap : public std::map { public: typedef std::map map_type; typedef typename map_type::value_type value_type; using map_type::insert; /** * Default constructor. */ JAutoMap() {} /** * Creation of a map element for given data type. * * This method should be overloaded for the requested data types * if the method insert() is used without argument. * * \param type data type * \return element */ template static value_type getAutoElement(JType type); /** * Insert list of data types. */ template void insert() { insert(JType(), JAutomate()); } /** * Insert list of data types. * * \param automate type defined element */ template void insert(const JAutomate& automate) { insert(JType(), automate); } protected: /** * Insertion of single data type. * * \param type data type * \param automate element automate by data type */ template void insert(JType type, const JAutomate& automate) { map_type::insert(automate.getElement(type)); } /** * Recursive insertion of data types. * * \param typelist type list * \param automate element automate by data type */ template void insert(JType< JTypeList > typelist, const JAutomate& automate) { insert(JType(), automate); insert(JType(), automate); } /** * Template specialisation to terminate insertion of data types. * * \param type null type * \param automate element automate by data type */ template void insert(JType type, const JAutomate& automate) {} }; } #endif