Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

LayoutDataI.H

Go to the documentation of this file.
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 #include "MayDay.H"
00029 #include "DataIterator.H"
00030 #include "SPMD.H"
00031 
00032 template<class T>
00033 inline const T& LayoutData<T>::operator[](const DataIndex& index) const
00034 {
00035   assert(m_boxLayout.check(index));
00036   assert(m_boxLayout.procID(index) == procID()); // using a DataIndex for data on another processor
00037                                        //if you are reading this error in a debugger, then
00038                                        // you haven't used addBox(Box, int) correctly, or
00039                                        // you are using a LayoutIterator to access a data holder.
00040   return *(m_vector[m_boxLayout.index(index)]);
00041 }
00042 
00043 template<class T>
00044 inline const T& LayoutData<T>::operator[](const DataIterator& index) const
00045 {
00046   return (*this)[index()];
00047 }
00048 
00049 template<class T>
00050 inline T& LayoutData<T>::operator[](const DataIndex& index)
00051 {
00052   assert(m_boxLayout.check(index));
00053   assert(m_boxLayout.procID(index) == procID());// using a DataIndex for data on another processor
00054                                        //if you are reading this error in a debugger, then
00055                                        // you haven't used addBox(Box, int) correctly, or
00056                                        // you are using a LayoutIterator to access a data holder.
00057 
00058   return *(m_vector[m_boxLayout.index(index)]);
00059 }
00060 
00061 template<class T>
00062 inline T& LayoutData<T>::operator[](const DataIterator& index)
00063 {
00064 
00065   return (*this)[index()];
00066 }
00067 
00068 template<class T>
00069 inline Box LayoutData<T>::box(const DataIndex& index) const
00070 {
00071   return m_boxLayout.get(index);
00072 }
00073 
00074 template<class T>
00075 inline Box LayoutData<T>::box(const DataIterator& index) const
00076 {
00077   return m_boxLayout.get(index());
00078 }
00079 template<class T>
00080 inline DataIterator LayoutData<T>::dataIterator() const
00081 {
00082   return m_boxLayout.dataIterator();
00083 }
00084 
00085 template<class T>
00086 inline LayoutData<T>::LayoutData()
00087 {
00088   m_boxLayout.close();
00089   m_callDelete = true;
00090 }
00091 
00092 template<class T>
00093 inline LayoutData<T>::LayoutData(const BoxLayout& dp)
00094   : m_boxLayout(dp)
00095 {
00096   assert(dp.isClosed());
00097   m_callDelete = true;
00098   allocate();
00099 }
00100 
00101 template<class T>
00102 inline void LayoutData<T>::define(const BoxLayout& dp)
00103 {
00104   assert(dp.isClosed());
00105   m_boxLayout = dp;
00106   allocate();
00107 }
00108 
00109 template<class T>
00110 inline LayoutData<T>::~LayoutData()
00111 {
00112   if(m_callDelete == true){
00113   for(DataIterator it(dataIterator()); it.ok(); ++it)
00114     {
00115       delete m_vector[m_boxLayout.index(it())];
00116     }
00117   }
00118 }
00119 
00120 
00121 template<class T>
00122 inline void LayoutData<T>::allocate()
00123 {
00124   m_callDelete = true;
00125   for(unsigned int i=0; i<m_vector.size(); ++i)
00126     {
00127       delete m_vector[i];
00128       m_vector[i] = NULL;
00129     }
00130 
00131   m_vector.resize(m_boxLayout.size(), NULL);
00132 
00133   for(DataIterator it(dataIterator()); it.ok(); ++it)
00134     {
00135       unsigned int index = m_boxLayout.index(it());
00136       if(m_vector[index] == NULL) 
00137         {
00138           m_vector[index] = new T();
00139           if(m_vector[index] == NULL)
00140           {
00141             MayDay::Error("OutOfMemory in boxlayoutdata::setVector");
00142           }
00143         }
00144  
00145     }
00146 }
00147 
00148 

Generated on Wed Jun 2 13:53:33 2004 for Chombo&INSwithParticles by doxygen 1.3.2