BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
TRange.h
Go to the documentation of this file.
1 // ************************************************************************** //
2 //
3 // BornAgain: simulate and fit scattering at grazing incidence
4 //
5 //! @file Sample/Particle/TRange.h
6 //! @brief Defines and implements template classes TRange and TSampledRange.
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2018
11 //! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************** //
14 
15 #ifndef BORNAGAIN_CORE_PARTICLE_TRANGE_H
16 #define BORNAGAIN_CORE_PARTICLE_TRANGE_H
17 
18 #include <cstddef>
19 
20 //! An interval [lowerBound..upperBound[.
21 //! @ingroup tools_internal
22 
23 template <class T> class TRange
24 {
25 public:
26  TRange(T lowerBound, T upperBound) : m_lower_bound(lowerBound), m_upper_bound(upperBound) {}
27  virtual ~TRange() {}
28 
29  T getLowerBound() const { return m_lower_bound; }
30  T getUpperBound() const { return m_upper_bound; }
31  T getDifference() const { return m_upper_bound - m_lower_bound; }
32 
33  bool inRange(T value) const { return value >= m_lower_bound && value < m_upper_bound; }
34 
35 private:
37 };
38 
39 //! An interval [lowerBound..upperBound[, and a number of samples.
40 
41 template <class T> class TSampledRange : public TRange<T>
42 {
43 public:
44  TSampledRange(size_t n_samples, T lowerBound, T upperBound)
45  : TRange<T>(lowerBound, upperBound), m_n_samples(n_samples)
46  {
47  }
48 
49  size_t getNSamples() const { return m_n_samples; }
50 
51 private:
52  size_t m_n_samples;
53 };
54 
55 #endif // BORNAGAIN_CORE_PARTICLE_TRANGE_H
An interval [lowerBound..upperBound[.
Definition: TRange.h:24
T m_lower_bound
Definition: TRange.h:36
bool inRange(T value) const
Definition: TRange.h:33
T getUpperBound() const
Definition: TRange.h:30
T getDifference() const
Definition: TRange.h:31
T getLowerBound() const
Definition: TRange.h:29
T m_upper_bound
Definition: TRange.h:36
virtual ~TRange()
Definition: TRange.h:27
TRange(T lowerBound, T upperBound)
Definition: TRange.h:26
An interval [lowerBound..upperBound[, and a number of samples.
Definition: TRange.h:42
size_t m_n_samples
Definition: TRange.h:52
TSampledRange(size_t n_samples, T lowerBound, T upperBound)
Definition: TRange.h:44
size_t getNSamples() const
Definition: TRange.h:49