Chombo + EB  3.0
LayoutData.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 _LAYOUTDATA_H_
12 #define _LAYOUTDATA_H_
13 
14 #include "BoxLayout.H"
15 #include "DataIterator.H"
16 #include "TimedDataIterator.H"
17 #include "NamespaceHeader.H"
18 
19 
20 //class LayoutData
21 
22 /// Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout
23 /**
24  A collection of Box-oriented objects. The arrangement of the T objects
25  is given by the underlying BoxLayout object. LayoutData does not attempt
26  to prevent users from manipulating the template class T to become out of
27  synch with the boxes in the BoxLayout. Caveat emptor.
28 
29  Non-local (off-processor access) to a LayoutData index is an error. You
30  can assure that access to the data stored in a LayoutData is local to your
31  processor by using the DataIterator object for indexing.
32 
33  Data in a LayoutData CANNOT be communicated to other processors using
34  the API presented in LevelData.
35 
36  class T must provide the following methods:
37  <PRE>
38  {
39  T()
40  }
41  </PRE>
42 
43  This class is useful for processor-local data that needs to be indexable
44  along with a BoxLayoutData. Auxillary data objects, etc.
45 */
46 template<class T> class LayoutData
47 {
48 public:
49  ///
50  LayoutData();
51 
52  ///
53  /**
54  constructor. allocates a T object for every box in the BoxLayout a_dp
55  using the T null constructor. a_dp must be closed.
56  */
57  LayoutData(const BoxLayout& a_dp);
58 
59  ///
60  virtual ~LayoutData();
61 
62  ///
63  /**
64  constructor. allocates a T object for every box in the BoxLayout a_dp
65  using the T null constructor. a_dp must be closed. previously stored
66  T objects are removed
67  */
68  virtual void define(const BoxLayout& a_dp);
69 
70  // this approach, of using the iterator itself for indexing is my own
71  // brilliance. This way you don't need all the crappy [Const][Dependent]
72  // Iterators. It also forces all data access to be done through the
73  // DataIterator, which will know how to talk to KeLP (or other parallel
74  // architectures, like multithreading, etc).
75 
76  ///
77  DataIterator dataIterator() const;
78 
80 
81  /// const accessor function
82  const T& operator [] (const DataIndex& a_index) const;
83 
84  /// const accessor function
85  /**
86  Returns member for which DataIterator is currently indexed to.
87  Equivalent to layout[a_iterator()]
88  */
89  const T& operator [] (const DataIterator& a_iterator) const;
90 
91  /// non-const accessor function
92  T& operator [] (const DataIndex& a_index);
93 
94  /// non-const accessor function
95  T& operator [] (const DataIterator& a_iterator);
96 
97  ///
98  Box box(const DataIndex& a_index) const;
99 
100  Box box(const DataIterator& a_iterator) const;
101 
102  // not really a protection mechanism, since a user can always
103  // perform a shallow copy of the BoxLayout, and be free to manipulate
104  // the data in the object. If you wish to have an actual copy
105  // of the BoxLayout, then you need to invoke the clone() method.
106 
107  ///
108  const BoxLayout& boxLayout() const
109  {
110  return m_boxLayout;
111  }
112 
113 
114 protected:
115 
117 
118  // this used to be std::vector<T>, and I could let vector handle
119  // destruction for me, but vector.resize() absolutely demands that
120  // I provide a copy constructor for T. People get uncomfortable when
121  // I make them provide me with copy constructors.
123 
124  // thinking about making this class self-documenting to a greater degree
125  // and having the component names also be kept in the class and carried
126  // around through various transformations.....
127  // vector<string> m_componentNames;
128 
130 
131 
132 private:
133  // disallow copy constructors and assignment operators
134  // to avoid very hard-to-find performance problems
135  LayoutData<T>& operator= (const LayoutData<T>& a_rhs);
136  LayoutData(const LayoutData& a_rhs);
137 
138  // handy usage function, tied to the implementation of this class
139  // as a vector<T*>. Assumes that m_comps and m_boxLayout have already
140  // been initialized correctly. Sets the correct size for the data
141  // vector, deletes the extra T objects if m_vector is to shorten, and
142  // performs either construction or define on the remaining T objects.
143  void allocate();
144 };
145 
146 //====================== inline functions ===========================
147 // not literally a .H file, but just an experiment in having useable,
148 // readable headers, while having the dependeny system work properly.
149 // Since LayoutData.H now depends on LayoutDataI.H, then changing either
150 // should cause all code that includes LayoutData.H to be recompiled.
151 // This way people can just read the interface in this file.
152 // Implementation is put in the *I.H file.
153 
154 #include "NamespaceFooter.H"
155 #include "LayoutDataI.H"
156 
157 #endif
virtual ~LayoutData()
Definition: LayoutDataI.H:116
bool m_callDelete
Definition: LayoutData.H:129
LayoutData()
Definition: LayoutDataI.H:91
Vector< T * > m_vector
Definition: LayoutData.H:122
A not-necessarily-disjoint collective of boxes.
Definition: BoxLayout.H:146
Data that maintains a one-to-one mapping of T to the boxes in a BoxLayout.
Definition: LayoutData.H:46
TimedDataIterator timedDataIterator() const
Definition: LayoutDataI.H:85
const T & operator[](const DataIndex &a_index) const
const accessor function
Definition: LayoutDataI.H:26
Definition: DataIterator.H:140
BoxLayout m_boxLayout
Definition: LayoutData.H:116
void allocate()
Definition: LayoutDataI.H:133
virtual void define(const BoxLayout &a_dp)
Definition: LayoutDataI.H:108
const BoxLayout & boxLayout() const
Definition: LayoutData.H:108
A Rectangular Domain on an Integer Lattice.
Definition: Box.H:465
Definition: DataIndex.H:112
LayoutData< T > & operator=(const LayoutData< T > &a_rhs)
DataIterator dataIterator() const
Definition: LayoutDataI.H:79
Box box(const DataIndex &a_index) const
Definition: LayoutDataI.H:67
Definition: TimedDataIterator.H:23