#ifndef __JTOOLS__JMAPPABLECOLLECTION__ #define __JTOOLS__JMAPPABLECOLLECTION__ #include "JLang/JClass.hh" /** * \author mdejong */ namespace JTOOLS {} namespace JPP { using namespace JTOOLS; } namespace JTOOLS { using JLANG::JClass; /** * Template interface definition for associative collection of elements. * The concrete associative collection should implement the following methods. *
 
   *             void clear();
   *
   *             mapped_type& get(key_type key);
   * 
* This class implements the operator [key_type key] and method put(key_type key, mapped_type value). */ template struct JMappableCollection { typedef JKey_t key_type; typedef JValue_t mapped_type; /** * Virtual destructor. */ virtual ~JMappableCollection() {} /** * Clear. */ virtual void clear() = 0; /** * Get mapped value. * * \param key key * \return value */ virtual const mapped_type& get(typename JClass::argument_type key) const = 0; /** * Get mapped value. * * \param key key * \return value */ virtual mapped_type& get(typename JClass::argument_type key) = 0; /** * Get mapped value. * * \param key key * \return value */ const mapped_type& operator[](typename JClass::argument_type key) const { return get(key); } /** * Get mapped value. * * \param key key * \return value */ mapped_type& operator[](typename JClass::argument_type key) { return get(key); } /** * Put pair-wise element (key,value) into collection. * * \param key key * \param value value */ void put(typename JClass ::argument_type key, typename JClass::argument_type value) { get(key) = value; } }; /** * Auxiliary class to define JMappableCollection for given template. */ template struct JMappable { /** * Type definition of JMappableCollection. */ typedef JMappableCollection map_type; }; } #endif