localproduct.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 
00003 Copyright Rice University, 2004.
00004 All rights reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, provided that the above copyright notice(s) and this
00012 permission notice appear in all copies of the Software and that both the
00013 above copyright notice(s) and this permission notice appear in supporting
00014 documentation.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00024 THIS SOFTWARE.
00025 
00026 Except as contained in this notice, the name of a copyright holder shall
00027 not be used in advertising or otherwise to promote the sale, use or other
00028 dealings in this Software without prior written authorization of the
00029 copyright holder.
00030 
00031 **************************************************************************/
00032 
00033 #ifndef __RVL_PLDC
00034 #define __RVL_PLDC
00035 
00036 
00037 #include "localdata.hh"
00038 #include "productdata.hh"
00039 
00040 namespace RVL {
00041 
00054   template<class DataType>
00055   class ProductLocalDataContainer: public LocalDataContainer<DataType> {
00056 
00057   public:
00058 
00059     ProductLocalDataContainer() {}
00060     ProductLocalDataContainer( ProductLocalDataContainer<DataType> & ) {}
00061     ~ProductLocalDataContainer() {}
00062 
00065     virtual int getNumberOfComponents() const = 0;
00066   
00068     virtual LocalDataContainer<DataType> & operator[](int i) = 0;
00069     virtual LocalDataContainer<DataType> const & operator[](int i) const = 0;
00070 
00071   };
00072 
00076   template<class DataType>
00077   class ProductDataContainerLDC: public ProductDataContainer {
00078 
00079   private:
00080 
00081     ProductLocalDataContainer<DataType> & pldc;
00082 
00083     ProductDataContainerLDC();
00084 
00085   public:
00086 
00087     ProductDataContainerLDC( ProductLocalDataContainer<DataType> & _pldc)
00088       : pldc(_pldc) {}
00089     ProductDataContainerLDC( const ProductDataContainerLDC<DataType> & pdldc )
00090       : pldc(pdldc.pldc) {}
00091     virtual ~ProductDataContainerLDC() {}
00092 
00093     virtual int getSize() const { return pldc.getNumberOfComponents(); }
00094 
00095     virtual DataContainer & operator[](int i) { 
00096       try {
00097     return pldc[i];
00098       }
00099       catch (RVLException & e) {
00100     e<<"\ncalled from ProductDataContainerLDC::operator[]\n";
00101     throw e;
00102       }
00103     }
00104     virtual DataContainer const & operator[](int i) const { 
00105       try {
00106     return pldc[i];
00107       }
00108       catch (RVLException & e) {
00109     e<<"\ncalled from ProductDataContainerLDC::operator[]\n";
00110     throw e;
00111       }
00112     }
00113   };
00114 
00119   template<class DataType>
00120   class PartitionedLocalDataContainer
00121     : public ProductLocalDataContainer<DataType> {
00122 
00123   private:
00124 
00125     LocalDataContainer<DataType> & ldc;
00126     vector<int> k;
00127 
00128     vector<LocalDataContainerSection<DataType> *> comps;
00129 
00130     PartitionedLocalDataContainer() {}
00131 
00132   public:
00133 
00135     PartitionedLocalDataContainer(const PartitionedLocalDataContainer<DataType> & p)
00136       : ldc(p.ldc), k(p.k), comps(k.size()) {
00137       try {
00138     int nblk=k.size();
00139     int ndim=0;
00140     for (int i=0;i<nblk;i++) {
00141       comps[i]=new LocalDataContainerSection<DataType>(ldc,ndim,k[i]);
00142       ndim+=k[i];
00143     }
00144       }
00145       catch (RVLException & e) {
00146     e<<"\ncalled from PartitionedLocalDataContainer constructor\n";
00147     throw e;
00148       }
00149     }
00150 
00152     PartitionedLocalDataContainer( LocalDataContainer<DataType> & _ldc, 
00153                    vector<int> _k)
00154       : ldc(_ldc), k(_k), comps(k.size()) {
00155       try {
00156     int nblk = k.size();
00157     int ndim = 0;
00158     for (int i=0;i<nblk;i++) {
00159       ndim+=k[i];
00160     }
00161     if (ndim != ldc.getSize()) {
00162       RVLException e;
00163       e<<"Error: PartitionedLocalDataContainer constructor\n";
00164       e<<"block dimensions do not add up to overall dimensions\n";
00165       e<<"overall dimension = "<<ldc.getSize()<<"\n";
00166       for (int i=0; i<nblk; i++) {
00167         e<<"dimension of block "<<i<<" = "<<k[i]<<"\n";
00168       }
00169       throw e;
00170     }
00171     ndim=0;
00172     for (int i=0;i<nblk;i++) {
00173       comps[i]=new LocalDataContainerSection<DataType>(ldc,ndim,k[i]);
00174       ndim+=k[i];
00175     }
00176       }
00177       catch (RVLException & e) {
00178     e<<"\ncalled from PartitionedLocalDataContainer constructor\n";
00179     throw e;
00180       }
00181     }
00182 
00183     ~PartitionedLocalDataContainer() {
00184       for (int i=0;i<k.size();i++) {
00185     if (comps[i]) delete comps[i];
00186       }
00187     }
00188   
00190     int getSize() const { return ldc.getSize(); }
00191 
00193     DataType * getData() { return ldc.getData(); }
00194     DataType const * getData() const { return ldc.getData(); }
00195 
00196     int getNumberOfComponents() const { return k.size(); }
00197     LocalDataContainer<DataType> & operator[](int i) {
00198       if (i<0 || i>=(k.size())) {
00199     RVLException e;
00200     e<<"Error: PartitionedLocalDataContainer::getLocalComponent\n";
00201     e<<"input index "<<i<<" out of range [0, "<<(int)(k.size())-1<<"]\n";
00202     throw e;
00203       }
00204       return *(comps[i]);
00205     }
00206 
00207     LocalDataContainer<DataType> const & operator[](int i) const {
00208       if (i<0 || i>=(k.size())) {
00209     RVLException e;
00210     e<<"Error: PartitionedLocalDataContainer::getLocalComponent\n";
00211     e<<"input index "<<i<<" out of range [0, "<<(int)(k.size())-1<<"]\n";
00212     throw e;
00213       }
00214       return *(comps[i]);
00215     }
00216 
00217     ostream & write(ostream & str) const {
00218       str<<"Partitioned LocalDataContainer Object\n";
00219       str<<"   number of components = "<<getNumberOfComponents()<<"\n";
00220       for (int i=0;i<getNumberOfComponents();i++) {
00221     str<<"   *** component "<<i<<"\n";
00222     comps[i]->write(str);
00223       }
00224       return str;
00225     }
00226   };
00227 
00228 }
00229 
00230 #endif

Generated on 5 Jan 2017 for LocalRVL by  doxygen 1.4.7