Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSet.hh
Go to the documentation of this file.
1 #ifndef __JTOOLS__JSET__
2 #define __JTOOLS__JSET__
3 
4 #include <set>
5 #include <iterator>
6 
8 
9 
10 /**
11  * \author mdejong
12  */
13 
14 namespace JTOOLS {}
15 namespace JPP { using namespace JTOOLS; }
16 
17 namespace JTOOLS {
18 
19  template<class JElement_t, class JDistance_t>
20  class JCollection;
21 
22 
23  /**
24  * Simple data structure for an abstract collection of non-equidistant abscissa values.
25  *
26  * This class implements the JAbstractCollection interface.
27  */
28  template<class JAbscissa_t>
29  struct JSet :
30  public JAbstractCollection<JAbscissa_t>,
31  std::set <JAbscissa_t>
32  {
34 
35 
36  /**
37  * Default constructor.
38  */
39  JSet()
40  {}
41 
42 
43  /**
44  * Constructor.
45  *
46  * \param collection abstract collection
47  */
49  {
50  for (int i = 0; i != collection.getSize(); ++i) {
51  this->insert(collection.getX(i));
52  }
53  }
54 
55 
56  /**
57  * Constructor.
58  *
59  * \param __begin begin of abscissa values
60  * \param __end end of abscissa values
61  */
62  template<class T>
63  JSet(T __begin, T __end)
64  {
65  for (T i = __begin; i != __end; ++i) {
66  this->insert(*i);
67  }
68  }
69 
70 
71  /**
72  * Get number of elements.
73  *
74  * \return number of elements
75  */
76  virtual int getSize() const override
77  {
78  return (int) this->size();
79  }
80 
81 
82  /**
83  * Get abscissa value.
84  *
85  * \param index index
86  * \return abscissa value
87  */
88  virtual abscissa_type getX(int index) const override
89  {
90  typename std::set<abscissa_type>::const_iterator i = this->begin();
91 
92  std::advance(i, index);
93 
94  return *i;
95  }
96 
97 
98  /**
99  * Get minimal abscissa value.
100  *
101  * \return abscissa value
102  */
103  virtual abscissa_type getXmin() const override
104  {
105  return *(this->begin());
106  }
107 
108 
109  /**
110  * Get maximal abscissa value.
111  *
112  * \return abscissa value
113  */
114  virtual abscissa_type getXmax() const override
115  {
116  return *(this->rbegin());
117  }
118 
119 
120  /**
121  * Configure collection.
122  *
123  * \param collection collection
124  * \return this set
125  */
126  template<class JElement_t, class JDistance_t>
128  {
129  collection.configure(*this);
130 
131  return *this;
132  }
133  };
134 
135 
136  /**
137  * Helper method for JSet.
138  *
139  * \param __begin begin of abscissa values
140  * \param __end end of abscissa values
141  * \return set
142  */
143  template<class T>
145  {
147  }
148 
149 
150  /**
151  * Helper method for JSet.
152  *
153  * \param input abstract collection
154  * \return set
155  */
156  template<class JAbscissa_t>
158  {
159  return JSet<JAbscissa_t>(input);
160  }
161 }
162 
163 #endif
JSet(T __begin, T __end)
Constructor.
Definition: JSet.hh:63
General purpose class for collection of elements, see: &lt;a href=&quot;JTools.PDF&quot;;&gt;Collection of elements...
Definition: JCollection.hh:73
Abstract interface for abscissa values of a collection of elements.
JAbstractCollection< JAbscissa_t >::abscissa_type abscissa_type
Definition: JSet.hh:33
virtual int getSize() const override
Get number of elements.
Definition: JSet.hh:76
const JSet & operator()(JCollection< JElement_t, JDistance_t > &collection) const
Configure collection.
Definition: JSet.hh:127
virtual abscissa_type getX(int index) const override
Get abscissa value.
Definition: JSet.hh:88
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void configure(const JAbstractCollection< abscissa_type > &bounds)
Configure collection.
Definition: JCollection.hh:334
virtual abscissa_type getX(int index) const =0
Get abscissa value.
T make_set(T __begin, T __end, JResult_t std::iterator_traits< T >::value_type::*value, const JComparator_t &comparator)
Method to exclude outliers from already sorted data.
Definition: JVectorize.hh:169
counter_type advance(counter_type &counter, const counter_type value, const counter_type limit=std::numeric_limits< counter_type >::max())
Advance counter.
JSet()
Default constructor.
Definition: JSet.hh:39
virtual abscissa_type getXmin() const override
Get minimal abscissa value.
Definition: JSet.hh:103
virtual abscissa_type getXmax() const override
Get maximal abscissa value.
Definition: JSet.hh:114
virtual int getSize() const =0
Get number of elements.
Simple data structure for an abstract collection of non-equidistant abscissa values.
Definition: JSet.hh:29
JSet(const JAbstractCollection< abscissa_type > &collection)
Constructor.
Definition: JSet.hh:48