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