Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMap.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JMAP__
2 #define __JTOOLS__JMAP__
3 
4 #include "JTools/JCollection.hh"
6 #include "JTools/JElement.hh"
7 #include "JMath/JMath.hh"
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JTOOLS {}
15 namespace JPP { using namespace JTOOLS; }
16 
17 namespace JTOOLS {
18 
19  /**
20  * Map of pair-wise elements.
21  *
22  * The key_type and mapped_type refer to the pair-wise element of this map, respectively.
23  */
24  template<class JKey_t,
25  class JValue_t,
26  class JDistance_t = JDistance<JKey_t> >
27  class JMap :
28  public JCollection<JElement2D<JKey_t, JValue_t>, JDistance_t>,
29  public JMATH::JMath< JMap<JKey_t, JValue_t, JDistance_t> >
30  {
31  public:
32 
33  typedef JKey_t key_type;
34  typedef JValue_t mapped_type;
35 
37 
42 
43 
44  /**
45  * Default constructor.
46  */
47  JMap()
48  {}
49 
50 
51  /**
52  * Add map.
53  *
54  * \param map map
55  * \return this map
56  */
57  JMap& add(const JMap& map)
58  {
59  static_cast<container_type&>(*this).add(static_cast<const container_type&>(map));
60 
61  return *this;
62  }
63 
64 
65  /**
66  * Subtract map.
67  *
68  * \param map map
69  * \return this map
70  */
71  JMap& sub(const JMap& map)
72  {
73  static_cast<container_type&>(*this).sub(static_cast<const container_type&>(map));
74 
75  return *this;
76  }
77 
78 
79  /**
80  * Scale contents.
81  *
82  * \param value multiplication factor
83  * \return this map
84  */
85  JMap& mul(const double value)
86  {
87  static_cast<container_type&>(*this).mul(value);
88 
89  return *this;
90  }
91 
92  /**
93  * Scale contents.
94  *
95  * \param value division factor
96  * \return this map
97  */
98  JMap& div(const double value)
99  {
100  static_cast<container_type&>(*this).div(value);
101 
102  return *this;
103  }
104  };
105 
106 
107  /**
108  * Specialisation of JMapCollection for JMap.
109  */
110  template<>
112  /**
113  * Collection of elements.
114  */
115  template<class JElement_t,
118  public JCollection<JElement_t, JDistance_t>
119  {};
120  };
121 }
122 
123 #endif
container_type::const_reverse_iterator const_reverse_iterator
Definition: JMap.hh:39
Auxiliary base class for aritmetic operations of derived class types.
Definition: JMath.hh:26
General purpose class for collection of elements, see: &lt;a href=&quot;JTools.PDF&quot;;&gt;Collection of elements...
Definition: JCollection.hh:72
The elements in a collection are sorted according to their abscissa values and a given distance opera...
Template class for distance evaluation.
Definition: JDistance.hh:24
Map of pair-wise elements.
Definition: JMap.hh:27
container_type::const_iterator const_iterator
Definition: JMap.hh:38
JMap()
Default constructor.
Definition: JMap.hh:47
JMap & mul(const double value)
Scale contents.
Definition: JMap.hh:85
container_type::const_reverse_iterator const_reverse_iterator
Definition: JCollection.hh:91
General purpose class for a collection of sorted elements.
Template class to define the corresponding JCollection for a given template JMap. ...
JMap & div(const double value)
Scale contents.
Definition: JMap.hh:98
container_type::reverse_iterator reverse_iterator
Definition: JMap.hh:41
JMap & sub(const JMap &map)
Subtract map.
Definition: JMap.hh:71
Base class for data structures with artithmetic capabilities.
JKey_t key_type
Definition: JMap.hh:33
container_type::iterator iterator
Definition: JMap.hh:40
const char * map
Definition: elog.cc:87
JValue_t mapped_type
Definition: JMap.hh:34
JCollection< JElement2D< JKey_t, JValue_t >, JDistance_t > container_type
Definition: JMap.hh:36
JMap & add(const JMap &map)
Add map.
Definition: JMap.hh:57