Chombo + EB  3.2
Tuple.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 _TUPLE_H_
12 #define _TUPLE_H_
13 
14 #include <cstdlib>
15 #include "CH_assert.H"
16 #include "BaseNamespaceHeader.H"
17 using namespace std;
18 
19 //
20 /// Ordered Tuples for Types T
21 /**
22 
23  This class represents ordered tuples of some user-specified concrete
24  type T for N > 0. The type T must have a default constructor. If the
25  non-default constructor, copy constructor, or copy assignment operator
26  are used, T must also have a copy constructor.
27 */
28 
29 template <class T, size_t N>
30 class Tuple
31 {
32 public:
33 
34  /**: The default constructor. For user-defined types T, the
35  default constructor for T will be run on each of the N
36  objects in the Tuple. For builtin (intrinsic) types,
37  the values in the Tuple will be garbage.
38  */
39  Tuple ();
40 
41  /**: Constructs a Tuple, initializing the elements in the Tuple
42  with the corresponding elements in the vector v. This assumes
43  that v contains at least N elements of type T -- an assumption
44  that is NOT checked. For user-defined types, T must have a
45  well-defined and accessible copy constructor.
46  */
47  //explicit Tuple (const T* v);
48  //
49  // The copy constructor.
50  //
51  Tuple (const Tuple& rhs);
52  //
53  // The copy assignment operator.
54  //
55  Tuple& operator= (const Tuple& rhs);
56 
57  /**: Returns a modifiable lvalue reference to the i'th
58  element in the Tuple, counting from zero. Performs
59  range checking when the library is compiled in debug
60  mode. */
61  T& operator[] (int i);
62 
63  /**: Returns a constant reference to the i'th element in the Tuple,
64  counting from zero. Performs range checking when the library
65  is compiled in debug mode.
66  */
67  const T& operator[] (int i) const;
68 
69  /**: Returns the address of the underlying vector of T
70  representation. This should ONLY be used when interfacing
71  to Fortran as it breaks the encapsulation of the class.
72  */
73  operator const T* () const;
74 
75 protected:
76  //
77  // The underlying vector of T representing the Tuple.
78  //
79  T vect[N];
80 };
81 
82 //
83 // Inlines.
84 //
85 
86 template <class T, size_t N>
87 inline
89 {
90 }
91 
92 template <class T, size_t N>
93 inline
94 T&
96 {
97  CH_assert(0 <= i && i < (int)N);
98  return vect[i];
99 }
100 
101 template <class T, size_t N>
102 inline
103 const T&
105 {
106  CH_assert(0 <= i && i < (int)N);
107  return vect[i];
108 }
109 
110 template <class T, size_t N>
111 inline
112 Tuple<T,N>::operator const T* () const
113 {
114  return &vect[0];
115 }
116 
117 //template <class T, size_t N>
118 //Tuple<T,N>::Tuple (const T* v)
119 //{
120 // CH_assert(v != 0);
121 // for (size_t i = 0; i < N; ++i)
122 // vect[i] = v[i];
123 //}
124 
125 template <class T, size_t N>
127 {
128  for (size_t i = 0; i < N; ++i)
129  vect[i] = rhs.vect[i];
130 }
131 
132 template <class T, size_t N>
133 Tuple<T,N>&
135 {
136  for (size_t i = 0; i < N; ++i)
137  vect[i] = rhs.vect[i];
138  return *this;
139 }
140 
141 #include "BaseNamespaceFooter.H"
142 #endif /*CH_TUPLE_H*/
#define CH_assert(cond)
Definition: CHArray.H:37
Tuple()
Definition: Tuple.H:88
Ordered Tuples for Types T.
Definition: Tuple.H:30
void const char const int const int * N
Definition: Lapack.H:83
T & operator[](int i)
Definition: Tuple.H:95
T vect[N]
Definition: Tuple.H:79
Tuple & operator=(const Tuple &rhs)
Definition: Tuple.H:134