00001 #ifdef CH_LANG_CC 00002 /* 00003 * _______ __ 00004 * / ___/ / ___ __ _ / / ___ 00005 * / /__/ _ \/ _ \/ V \/ _ \/ _ \ 00006 * \___/_//_/\___/_/_/_/_.__/\___/ 00007 * Please refer to Copyright.txt, in Chombo's root directory. 00008 */ 00009 #endif 00010 00011 #ifndef _INTERVAL_H_ 00012 #define _INTERVAL_H_ 00013 #include "BaseNamespaceHeader.H" 00014 00015 // 00016 // Little struct for passing component ranges in code. 00017 // 00018 00019 /// Structure for passing component ranges in code. 00020 /** 00021 A class to encapsulate component ranges 00022 */ 00023 struct Interval 00024 { 00025 Interval() 00026 : 00027 m_begin(0), 00028 m_end(-1) 00029 {} 00030 00031 /// 00032 /** 00033 initialize with first and last component numbers 00034 */ 00035 Interval(int a_firstComp, int a_lastComp) 00036 : 00037 m_begin(a_firstComp), 00038 m_end(a_lastComp) 00039 {} 00040 00041 /// 00042 /** 00043 * Copy from another Interval 00044 */ 00045 Interval& operator=(const Interval& p) 00046 { 00047 m_begin = p.m_begin; 00048 m_end = p.m_end; 00049 return *this; 00050 } 00051 00052 void define(int a_firstComp, 00053 int a_lastComp) 00054 { 00055 m_begin = a_firstComp; 00056 m_end = a_lastComp; 00057 } 00058 00059 /// 00060 /** 00061 return first component number 00062 */ 00063 int begin() const; 00064 00065 /// 00066 /** 00067 return last component number 00068 */ 00069 int end() const; 00070 00071 /// 00072 /** 00073 return last - first + 1 00074 */ 00075 int size() const 00076 { 00077 return m_end-m_begin+1; 00078 } 00079 00080 /// 00081 bool contains(int a_val) const 00082 { 00083 return a_val >= m_begin && a_val <= m_end; 00084 } 00085 00086 /// test for equality 00087 bool operator==(const Interval& p) const 00088 { 00089 return ( (m_begin == p.m_begin) && (m_end == p.m_end)); 00090 } 00091 00092 private: 00093 int m_begin, m_end; 00094 }; 00095 00096 #ifndef WRAPPER 00097 inline int Interval::begin() const 00098 { 00099 return m_begin; 00100 } 00101 00102 inline int Interval::end() const 00103 { 00104 return m_end; 00105 } 00106 #endif 00107 00108 #include "BaseNamespaceFooter.H" 00109 #endif