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 T& LayoutData<T>::operator[](const DataIndex& index)
00045 {
00046   assert(m_boxLayout.check(index));
00047   assert(m_boxLayout.procID(index) == procID());// using a DataIndex for data on another processor
00048                                        //if you are reading this error in a debugger, then
00049                                        // you haven't used addBox(Box, int) correctly, or
00050                                        // you are using a LayoutIterator to access a data holder.
00051 
00052   return *(m_vector[m_boxLayout.index(index)]);
00053 }
00054 
00055 template<class T>
00056 inline Box LayoutData<T>::box(const DataIndex& index) const
00057 {
00058   return m_boxLayout.get(index);
00059 }
00060 
00061 template<class T>
00062 inline DataIterator LayoutData<T>::dataIterator() const
00063 {
00064   return m_boxLayout.dataIterator();
00065 }
00066 
00067 template<class T>
00068 inline LayoutData<T>::LayoutData()
00069 {
00070   m_boxLayout.close();
00071 }
00072 
00073 template<class T>
00074 inline LayoutData<T>::LayoutData(const BoxLayout& dp)
00075   : m_boxLayout(dp)
00076 {
00077   assert(dp.isClosed());
00078   allocate();
00079 }
00080 
00081 template<class T>
00082 inline void LayoutData<T>::define(const BoxLayout& dp)
00083 {
00084   assert(dp.isClosed());
00085   m_boxLayout = dp;
00086   allocate();
00087 }
00088 
00089 template<class T>
00090 inline LayoutData<T>::~LayoutData()
00091 {
00092   for(DataIterator it(dataIterator()); it.ok(); ++it)
00093     {
00094       delete m_vector[m_boxLayout.index(it())];
00095     }
00096 }
00097 
00098 
00099 template<class T>
00100 inline void LayoutData<T>::allocate()
00101 {
00102 
00103   for(unsigned int i=0; i<m_vector.size(); ++i)
00104     {
00105       delete m_vector[i];
00106       m_vector[i] = NULL;
00107     }
00108 
00109   m_vector.resize(m_boxLayout.size(), NULL);
00110 
00111   for(DataIterator it(dataIterator()); it.ok(); ++it)
00112     {
00113       unsigned int index = m_boxLayout.index(it());
00114       if(m_vector[index] == NULL) 
00115         {
00116           m_vector[index] = new T();
00117           if(m_vector[index] == NULL)
00118           {
00119             MayDay::Error("OutOfMemory in boxlayoutdata::setVector");
00120           }
00121         }
00122  
00123     }
00124 }
00125 
00126 

Generated on Thu Aug 29 11:05:45 2002 for Chombo&INS by doxygen1.2.16