00001 /* _______ __ 00002 / ___/ / ___ __ _ / / ___ 00003 / /__/ _ \/ _ \/ ' \/ _ \/ _ \ 00004 \___/_//_/\___/_/_/_/_.__/\___/ 00005 */ 00006 // 00007 // This software is copyright (C) by the Lawrence Berkeley 00008 // National Laboratory. Permission is granted to reproduce 00009 // this software for non-commercial purposes provided that 00010 // this notice is left intact. 00011 // 00012 // It is acknowledged that the U.S. Government has rights to 00013 // this software under Contract DE-AC03-765F00098 between 00014 // the U.S. Department of Energy and the University of 00015 // California. 00016 // 00017 // This software is provided as a professional and academic 00018 // contribution for joint exchange. Thus it is experimental, 00019 // is provided ``as is'', with no warranties of any kind 00020 // whatsoever, no support, no promise of updates, or printed 00021 // documentation. By using this software, you acknowledge 00022 // that the Lawrence Berkeley National Laboratory and 00023 // Regents of the University of California shall have no 00024 // liability with respect to the infringement of other 00025 // copyrights by any part of this software. 00026 // 00027 00028 #ifndef LAYOUTDATA_H 00029 #define LAYOUTDATA_H 00030 00031 #include "BoxLayout.H" 00032 #include "DataIterator.H" 00033 00034 //class ArrayViewData; 00035 00037 00064 template<class T> class LayoutData 00065 { 00066 public: 00067 00068 friend class ArrayViewData; 00069 00071 LayoutData(); 00072 00074 00076 LayoutData(const BoxLayout& dp); 00077 00079 virtual ~LayoutData(); 00080 00082 00085 virtual void define(const BoxLayout& dp); 00086 00087 // this approach, of using the iterator itself for indexing is 00088 // my own brilliance. This way you don't need all the 00089 // crappy [Const][Dependent] Iterators. It also forces all 00090 // data access to be done through the DataIterator, which will 00091 // know how to talk to KeLP (or other parallel architectures, 00092 // like multithreading, etc). 00093 00095 DataIterator dataIterator() const; 00096 00098 const T& operator[](const DataIndex& a_index) const; 00099 00101 00105 const T& operator[](const DataIterator& a_iterator) const; 00106 00108 T& operator[](const DataIndex& a_index); 00109 00111 T& operator[](const DataIterator& a_iterator); 00113 00114 Box box(const DataIndex& a_index) const; 00115 Box box(const DataIterator& a_iterator) const; 00116 00117 // not really a protection mechanism, since a user can always 00118 // perform a shallow copy of the BoxLayout, and be free to manipulate 00119 // the data in the object. If you wish to have an actual copy 00120 // of the BoxLayout, then you need to invoke the clone() method. 00121 00123 const BoxLayout& boxLayout() const 00124 { 00125 return m_boxLayout; 00126 } 00127 00128 00129 protected: 00130 00131 BoxLayout m_boxLayout; 00132 00133 // this used to be std::vector<T>, and I could let vector handle 00134 // destruction for me, but vector.resize() absolutely demands that 00135 // I provide a copy constructor for T. People get uncomfortable when 00136 // I make them provide me with copy constructors. 00137 Vector<T*> m_vector; 00138 00139 // thinking about making this class self-documenting to a greater degree 00140 // and having the component names also be kept in the class and carried 00141 // around through various transformations..... 00142 // vector<string> m_componentNames; 00143 00144 bool m_callDelete; 00145 private: 00146 00147 // disallow copy constructors and assignment operators 00148 // to avoid very hard-to-find performance problems 00149 LayoutData<T>& operator= (const LayoutData<T>& rhs); 00150 LayoutData(const LayoutData& rhs); 00151 00152 // handy usage function, tied to the implementation of this class 00153 // as a vector<T*>. Assumes that m_comps and m_boxLayout have already 00154 // been initialized correctly. Sets the correct size for the data 00155 // vector, deletes the extra T objects if m_vector is to shorten, and 00156 // performs either construction or define on the remaining T objects. 00157 00158 void allocate(); 00159 00160 00161 }; 00162 00163 00164 //====================================================================== 00165 //====================================================================== 00166 00167 00168 00169 00170 //========= inline functions =========================== 00171 00172 // not literally a .H file, but just an experiment in 00173 // having useable, readable headers, while having 00174 // the dependeny system work properly. Since LayoutData.H 00175 // now depends on LayoutDataI.H, then changing either 00176 // should cause all code that includes LayoutData.H to be 00177 // recompiled. This way people can just read the interface 00178 // in this file. Implementation is put in the *I.H file. 00179 00180 #include "LayoutDataI.H" 00181 00182 #endif // LAYOUTDATA_H