Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
JSet.hh
Go to the documentation of this file.
1#ifndef __JTOOLS__JSET__
2#define __JTOOLS__JSET__
3
4#include <istream>
5#include <ostream>
6#include <set>
7#include <iterator>
8
10
11
12/**
13 * \author mdejong
14 */
15
16namespace JTOOLS {}
17namespace JPP { using namespace JTOOLS; }
18
19namespace JTOOLS {
20
21 template<class JElement_t, class JDistance_t>
23
24
25 /**
26 * Simple data structure for an abstract collection of non-equidistant abscissa values.
27 *
28 * This class implements the JAbstractCollection interface.
29 */
30 template<class JAbscissa_t>
31 struct JSet :
32 public JAbstractCollection<JAbscissa_t>,
33 std::set <JAbscissa_t>
34 {
36
37
38 /**
39 * Default constructor.
40 */
42 {}
43
44
45 /**
46 * Constructor.
47 *
48 * \param collection abstract collection
49 */
51 {
52 for (int i = 0; i != collection.getSize(); ++i) {
53 this->insert(collection.getX(i));
54 }
55 }
56
57
58 /**
59 * Constructor.
60 *
61 * \param __begin begin of abscissa values
62 * \param __end end of abscissa values
63 */
64 template<class T>
65 JSet(T __begin, T __end)
66 {
67 for (T i = __begin; i != __end; ++i) {
68 this->insert(*i);
69 }
70 }
71
72
73 /**
74 * Get number of elements.
75 *
76 * \return number of elements
77 */
78 virtual int getSize() const override
79 {
80 return (int) this->size();
81 }
82
83
84 /**
85 * Get abscissa value.
86 *
87 * \param index index
88 * \return abscissa value
89 */
90 virtual abscissa_type getX(int index) const override
91 {
92 typename std::set<abscissa_type>::const_iterator i = this->begin();
93
94 std::advance(i, index);
95
96 return *i;
97 }
98
99
100 /**
101 * Get minimal abscissa value.
102 *
103 * \return abscissa value
104 */
105 virtual abscissa_type getXmin() const override
106 {
107 return *(this->begin());
108 }
109
110
111 /**
112 * Get maximal abscissa value.
113 *
114 * \return abscissa value
115 */
116 virtual abscissa_type getXmax() const override
117 {
118 return *(this->rbegin());
119 }
120
121
122 /**
123 * Configure collection.
124 *
125 * \param collection collection
126 * \return this set
127 */
128 template<class JElement_t, class JDistance_t>
130 {
131 collection.configure(*this);
132
133 return *this;
134 }
135
136
137 /**
138 * Read set from input.
139 *
140 * \param in input stream
141 * \param object object
142 * \return input stream
143 */
144 friend inline std::istream& operator>>(std::istream& in, JSet<JAbscissa_t>& object)
145 {
146 for (JAbscissa_t value; in >> value; ) {
147 object.insert(value);
148 }
149
150 return in;
151 }
152
153
154 /**
155 * Write set to output.
156 *
157 * \param out output stream
158 * \param object object
159 * \return output stream
160 */
161 friend inline std::ostream& operator<<(std::ostream& out, const JSet<JAbscissa_t>& object)
162 {
163 for (typename JSet<JAbscissa_t>::const_iterator i = object.begin(); i != object.end(); ++i) {
164 out << ' ' << *i;
165 }
166
167 return out;
168 }
169 };
170
171
172 /**
173 * Helper method for JSet.
174 *
175 * \param __begin begin of abscissa values
176 * \param __end end of abscissa values
177 * \return set
178 */
179 template<class T>
184
185
186 /**
187 * Helper method for JSet.
188 *
189 * \param input abstract collection
190 * \return set
191 */
192 template<class JAbscissa_t>
194 {
195 return JSet<JAbscissa_t>(input);
196 }
197}
198
199#endif
General purpose class for collection of elements, see: <a href="JTools.PDF";>Collection of elements....
Definition JSet.hh:22
void configure(const JAbstractCollection< abscissa_type > &bounds)
Configure collection.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for multi-dimensional interpolations and histograms.
JSet< typename std::iterator_traits< T >::value_type > make_set(T __begin, T __end)
Helper method for JSet.
Definition JSet.hh:180
Abstract interface for abscissa values of a collection of elements.
virtual int getSize() const =0
Get number of elements.
virtual abscissa_type getX(int index) const =0
Get abscissa value.
Simple data structure for an abstract collection of non-equidistant abscissa values.
Definition JSet.hh:34
virtual abscissa_type getXmin() const override
Get minimal abscissa value.
Definition JSet.hh:105
const JSet & operator()(JCollection< JElement_t, JDistance_t > &collection) const
Configure collection.
Definition JSet.hh:129
JSet(T __begin, T __end)
Constructor.
Definition JSet.hh:65
JSet(const JAbstractCollection< abscissa_type > &collection)
Constructor.
Definition JSet.hh:50
virtual abscissa_type getXmax() const override
Get maximal abscissa value.
Definition JSet.hh:116
JAbstractCollection< JAbscissa_t >::abscissa_type abscissa_type
Definition JSet.hh:35
friend std::istream & operator>>(std::istream &in, JSet< JAbscissa_t > &object)
Read set from input.
Definition JSet.hh:144
JSet()
Default constructor.
Definition JSet.hh:41
virtual int getSize() const override
Get number of elements.
Definition JSet.hh:78
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition JSet.hh:90
friend std::ostream & operator<<(std::ostream &out, const JSet< JAbscissa_t > &object)
Write set to output.
Definition JSet.hh:161