Jpp  pmt_effective_area_update
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JPair.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JPAIR__
2 #define __JTOOLS__JPAIR__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JLang/JClass.hh"
8 #include "JIO/JSerialisable.hh"
9 
10 
11 /**
12  * \author mdejong
13  */
14 
15 namespace JTOOLS {}
16 namespace JPP { using namespace JTOOLS; }
17 
18 namespace JTOOLS {
19 
20  using JIO::JReader;
21  using JIO::JWriter;
22 
23 
24  /**
25  * Template specialisation for a pair of values.
26  */
27  template<class JKey_t, class JValue_t>
28  class JPair
29  {
30  public:
31 
32  typedef JKey_t key_type;
33  typedef JValue_t mapped_type;
34 
35 
36  /**
37  * Default constructor.
38  */
39  JPair() :
40  first (),
41  second()
42  {}
43 
44 
45  /**
46  * Constructor.
47  *
48  * \param key JKey_t
49  * \param value JValue_t
50  */
53  first (key),
54  second(value)
55  {}
56 
57 
58  /**
59  * Read pair from input.
60  *
61  * \param in input stream
62  * \param pair pair
63  * \return input stream
64  */
65  friend inline std::istream& operator>>(std::istream& in, JPair<JKey_t, JValue_t>& pair)
66  {
67  in >> pair.first;
68  in >> pair.second;
69 
70  return in;
71  }
72 
73 
74  /**
75  * Write pair to output.
76  *
77  * \param out output stream
78  * \param pair pair
79  * \return output stream
80  */
81  friend inline std::ostream& operator<<(std::ostream& out, const JPair<JKey_t, JValue_t>& pair)
82  {
83  out << pair.first;
84  out << ' ';
85  out << pair.second;
86 
87  return out;
88  }
89 
90 
91  /**
92  * Read pair from input.
93  *
94  * \param in reader
95  * \param pair pair
96  * \return reader
97  */
99  {
100  in >> pair.first;
101  in >> pair.second;
102 
103  return in;
104  }
105 
106 
107  /**
108  * Write pair to output.
109  *
110  * \param out writer
111  * \param pair pair
112  * \return writer
113  */
114  friend inline JWriter& operator<<(JWriter& out, const JPair<JKey_t, JValue_t>& pair)
115  {
116  out << pair.first;
117  out << pair.second;
118 
119  return out;
120  }
121 
122 
123  const key_type& getKey() const { return this->first; }
124  const mapped_type& getValue() const { return this->second; }
125 
126  mapped_type& getValue() { return this->second; }
127 
128  JKey_t first;
129  JValue_t second;
130  };
131 
132 
133  /**
134  * Template specialisation for a pair of references.
135  */
136  template<class JKey_t, class JValue_t>
137  class JPair<JKey_t&, JValue_t&>
138  {
139  public:
140 
141  typedef JKey_t key_type;
142  typedef JValue_t mapped_type;
143 
144 
145  /**
146  * Constructor.
147  *
148  * \param key JKey_t
149  * \param value JValue_t
150  */
151  JPair(key_type& key,
152  mapped_type& value) :
153  first (key),
154  second(value)
155  {}
156 
157  const key_type& getKey() const { return this->first; }
158  const mapped_type& getValue() const { return this->second; }
159 
160  key_type& getKey() { return this->first; }
161  mapped_type& getValue() { return this->second; }
162 
163  JKey_t& first;
164  JValue_t& second;
165  };
166 
167 
168  /**
169  * Template specialisation for a mixed pair of const and non-const references.
170  */
171  template<class JKey_t, class JValue_t>
172  class JPair<const JKey_t&, JValue_t&>
173  {
174  public:
175 
176  typedef JKey_t key_type;
177  typedef JValue_t mapped_type;
178 
179 
180  /**
181  * Constructor.
182  *
183  * \param key JKey_t
184  * \param value JValue_t
185  */
186  JPair(const key_type& key,
187  mapped_type& value) :
188  first (key),
189  second(value)
190  {}
191 
192  const key_type& getKey() const { return this->first; }
193  const mapped_type& getValue() const { return this->second; }
194 
195  mapped_type& getValue() { return this->second; }
196 
197  const JKey_t& first;
198  JValue_t& second;
199  };
200 
201 
202  /**
203  * Template specialisation for a pair of const references.
204  */
205  template<class JKey_t, class JValue_t>
206  class JPair<const JKey_t&, const JValue_t&>
207  {
208  public:
209 
210  typedef JKey_t key_type;
211  typedef JValue_t mapped_type;
212 
213 
214  /**
215  * Constructor.
216  *
217  * \param key JKey_t
218  * \param value JValue_t
219  */
220  JPair(const key_type& key,
221  const mapped_type& value) :
222  first (key),
223  second(value)
224  {}
225 
226  const key_type& getKey() const { return this->first; }
227  const mapped_type& getValue() const { return this->second; }
228 
229  const JKey_t& first;
230  const JValue_t& second;
231  };
232 }
233 
234 #endif
Interface for binary output.
JPair(const key_type &key, mapped_type &value)
Constructor.
Definition: JPair.hh:186
JPair(typename JLANG::JClass< key_type >::argument_type key, typename JLANG::JClass< mapped_type >::argument_type value)
Constructor.
Definition: JPair.hh:51
const mapped_type & getValue() const
Definition: JPair.hh:124
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
friend std::istream & operator>>(std::istream &in, JPair< JKey_t, JValue_t > &pair)
Read pair from input.
Definition: JPair.hh:65
mapped_type & getValue()
Definition: JPair.hh:126
JValue_t second
Definition: JPair.hh:129
friend JReader & operator>>(JReader &in, JPair< JKey_t, JValue_t > &pair)
Read pair from input.
Definition: JPair.hh:98
Template specialisation for a pair of values.
Definition: JPair.hh:28
JArgument< T >::argument_type argument_type
Definition: JClass.hh:82
JKey_t first
Definition: JPair.hh:128
const mapped_type & getValue() const
Definition: JPair.hh:227
const key_type & getKey() const
Definition: JPair.hh:157
Interface for binary input.
JPair(key_type &key, mapped_type &value)
Constructor.
Definition: JPair.hh:151
JPair(const key_type &key, const mapped_type &value)
Constructor.
Definition: JPair.hh:220
const key_type & getKey() const
Definition: JPair.hh:192
JPair()
Default constructor.
Definition: JPair.hh:39
const mapped_type & getValue() const
Definition: JPair.hh:193
const mapped_type & getValue() const
Definition: JPair.hh:158
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:40
JValue_t mapped_type
Definition: JPair.hh:33
const key_type & getKey() const
Definition: JPair.hh:123
JKey_t key_type
Definition: JPair.hh:32