Jpp
JMappableCollection.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMAPPABLECOLLECTION__
2 #define __JTOOLS__JMAPPABLECOLLECTION__
3 
4 #include "JLang/JClass.hh"
5 
6 
7 /**
8  * \author mdejong
9  */
10 
11 namespace JTOOLS {}
12 namespace JPP { using namespace JTOOLS; }
13 
14 namespace JTOOLS {
15 
16  using JLANG::JClass;
17 
18 
19  /**
20  * Template interface definition for associative collection of elements.
21  * The concrete associative collection should implement the following methods.
22  * <pre>
23  * void clear();
24  *
25  * mapped_type& get(key_type key);
26  * </pre>
27  * This class implements the operator <tt>[key_type key]</tt> and method <tt>put(key_type key, mapped_type value)</tt>.
28  */
29  template<class JKey_t, class JValue_t>
31  {
32 
33  typedef JKey_t key_type;
34  typedef JValue_t mapped_type;
35 
36  /**
37  * Virtual destructor.
38  */
40  {}
41 
42 
43  /**
44  * Clear.
45  */
46  virtual void clear() = 0;
47 
48 
49  /**
50  * Get mapped value.
51  *
52  * \param key key
53  * \return value
54  */
55  virtual mapped_type& get(typename JClass<key_type>::argument_type key) = 0;
56 
57 
58  /**
59  * Get mapped value.
60  *
61  * \param key key
62  * \return value
63  */
65  {
66  return get(key);
67  }
68 
69 
70  /**
71  * Put pair-wise element (key,value) into collection.
72  *
73  * \param key key
74  * \param value value
75  */
78  {
79  get(key) = value;
80  }
81  };
82 
83 
84  /**
85  * Auxiliary class to define JMappableCollection for given template.
86  */
87  template<class T>
88  struct JMappable {
89  /**
90  * Type definition of JMappableCollection.
91  */
92  typedef JMappableCollection<typename T::abscissa_type,
93  typename T::ordinate_type> map_type;
94  };
95 }
96 
97 #endif
JTOOLS::JMappableCollection::key_type
JKey_t key_type
Definition: JMappableCollection.hh:33
JTOOLS::JMappableCollection
Template interface definition for associative collection of elements.
Definition: JMappableCollection.hh:30
JLANG::JClass::argument_type
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JLANG::JClass
Template for generic class types.
Definition: JClass.hh:80
JTOOLS::JMappableCollection::put
void put(typename JClass< key_type > ::argument_type key, typename JClass< mapped_type >::argument_type value)
Put pair-wise element (key,value) into collection.
Definition: JMappableCollection.hh:76
JTOOLS::JMappableCollection::get
virtual mapped_type & get(typename JClass< key_type >::argument_type key)=0
Get mapped value.
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JTOOLS::JMappableCollection::mapped_type
JValue_t mapped_type
Definition: JMappableCollection.hh:34
JTOOLS::JMappableCollection::~JMappableCollection
virtual ~JMappableCollection()
Virtual destructor.
Definition: JMappableCollection.hh:39
JTOOLS::JMappable
Auxiliary class to define JMappableCollection for given template.
Definition: JMappableCollection.hh:88
JClass.hh
JTOOLS::JMappableCollection::operator[]
mapped_type & operator[](typename JClass< key_type >::argument_type key)
Get mapped value.
Definition: JMappableCollection.hh:64
JTOOLS
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
Definition: JAbstractCollection.hh:9
JTOOLS::JMappable::map_type
JMappableCollection< typename T::abscissa_type, typename T::ordinate_type > map_type
Type definition of JMappableCollection.
Definition: JMappableCollection.hh:93
JTOOLS::JMappableCollection::clear
virtual void clear()=0
Clear.