Chombo + EB  3.0
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  void define(int a_firstComp,
42  int a_lastComp)
43  {
44  m_begin = a_firstComp;
45  m_end = a_lastComp;
46  }
47 
48  ///
49  /**
50  return first component number
51  */
52  int begin() const;
53 
54  ///
55  /**
56  return last component number
57  */
58  int end() const;
59 
60  ///
61  /**
62  return last - first + 1
63  */
64  int size() const
65  {
66  return m_end-m_begin+1;
67  }
68 
69  ///
70  bool contains(int a_val) const
71  {
72  return a_val >= m_begin && a_val <= m_end;
73  }
74 
75  /// test for equality
76  bool operator==(const Interval& p) const
77  {
78  return ( (m_begin == p.m_begin) && (m_end == p.m_end));
79  }
80 
81 private:
82  int m_begin, m_end;
83 };
84 
85 #ifndef WRAPPER
86 inline int Interval::begin() const
87 {
88  return m_begin;
89 }
90 
91 inline int Interval::end() const
92 {
93  return m_end;
94 }
95 #endif
96 
97 #include "BaseNamespaceFooter.H"
98 #endif
int m_begin
Definition: Interval.H:82
int m_end
Definition: Interval.H:82
int size() const
Definition: Interval.H:64
int begin() const
Definition: Interval.H:86
Structure for passing component ranges in code.
Definition: Interval.H:23
Interval(int a_firstComp, int a_lastComp)
Definition: Interval.H:35
bool operator==(const Interval &p) const
test for equality
Definition: Interval.H:76
Interval()
Definition: Interval.H:25
void define(int a_firstComp, int a_lastComp)
Definition: Interval.H:41
bool contains(int a_val) const
Definition: Interval.H:70
int end() const
Definition: Interval.H:91