Chombo + EB + MF  3.2
Interval.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _INTERVAL_H_
12 #define _INTERVAL_H_
13 #include "BaseNamespaceHeader.H"
14 
15 //
16 // Little struct for passing component ranges in code.
17 //
18 
19 /// Structure for passing component ranges in code.
20 /**
21  A class to encapsulate component ranges
22 */
23 struct Interval
24 {
26  :
27  m_begin(0),
28  m_end(-1)
29  {}
30 
31  ///
32  /**
33  initialize with first and last component numbers
34  */
35  Interval(int a_firstComp, int a_lastComp)
36  :
37  m_begin(a_firstComp),
38  m_end(a_lastComp)
39  {}
40 
41  ///
42  /**
43  * Copy from another Interval
44  */
46  {
47  m_begin = p.m_begin;
48  m_end = p.m_end;
49  return *this;
50  }
51 
52  void define(int a_firstComp,
53  int a_lastComp)
54  {
55  m_begin = a_firstComp;
56  m_end = a_lastComp;
57  }
58 
59  ///
60  /**
61  return first component number
62  */
63  int begin() const;
64 
65  ///
66  /**
67  return last component number
68  */
69  int end() const;
70 
71  ///
72  /**
73  return last - first + 1
74  */
75  int size() const
76  {
77  return m_end-m_begin+1;
78  }
79 
80  ///
81  bool contains(int a_val) const
82  {
83  return a_val >= m_begin && a_val <= m_end;
84  }
85 
86  /// test for equality
87  bool operator==(const Interval& p) const
88  {
89  return ( (m_begin == p.m_begin) && (m_end == p.m_end));
90  }
91 
92  friend std::ostream& operator<< (std::ostream& os,
93  const Interval& dit);
94 private:
95  int m_begin, m_end;
96 };
97 
98 #ifndef WRAPPER
99 inline int Interval::begin() const
100 {
101  return m_begin;
102 }
103 
104 inline int Interval::end() const
105 {
106  return m_end;
107 }
108 #endif
109 
110 #include "BaseNamespaceFooter.H"
111 #endif
bool contains(int a_val) const
Definition: Interval.H:81
int m_begin
Definition: Interval.H:95
int m_end
Definition: Interval.H:95
int size() const
Definition: Interval.H:75
Structure for passing component ranges in code.
Definition: Interval.H:23
Interval & operator=(const Interval &p)
Definition: Interval.H:45
Interval(int a_firstComp, int a_lastComp)
Definition: Interval.H:35
friend std::ostream & operator<<(std::ostream &os, const Interval &dit)
Interval()
Definition: Interval.H:25
int begin() const
Definition: Interval.H:99
void define(int a_firstComp, int a_lastComp)
Definition: Interval.H:52
bool operator==(const Interval &p) const
test for equality
Definition: Interval.H:87
int end() const
Definition: Interval.H:104