/************************************************************************* Copyright Rice University, 2004. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, provided that the above copyright notice(s) and this permission notice appear in all copies of the Software and that both the above copyright notice(s) and this permission notice appear in supporting documentation. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization of the copyright holder. **************************************************************************/ #ifndef __RVL_PLDC #define __RVL_PLDC #include "localdata.hh" #include "productdata.hh" namespace RVL { /** Specialization of ProductDataContainer to case where all factors are local data containers. In designing such a class, it is imperative to decide what its primary identity shall be, in order to attach the class to the correct branch of the inheritance tree. Generally, the right decision is probably to attach it as "low down" as possible, i.e. with as many properties. I have followed that rule here: rather than deriving this class from ProductDataContainer, which simply implements virtual PDC properties, I have derived it from LocalDC, to which it adds properties. It's easy enough to write a wrapper class to create a PDC out of one of these: */ template class ProductLocalDataContainer: public LocalDataContainer { public: ProductLocalDataContainer() {} ProductLocalDataContainer( ProductLocalDataContainer & ) {} ~ProductLocalDataContainer() {} /** return number of components - note that this cannot be getSize(), which means something else! */ virtual int getNumberOfComponents() const = 0; /** return reference to ith component as LocalDataContainer */ virtual LocalDataContainer & operator[](int i) = 0; virtual LocalDataContainer const & operator[](int i) const = 0; }; /** wrapper class which turns a ProductLocalDataContainer into a ProductDataContainer */ template class ProductDataContainerLDC: public ProductDataContainer { private: ProductLocalDataContainer & pldc; ProductDataContainerLDC(); public: ProductDataContainerLDC( ProductLocalDataContainer & _pldc) : pldc(_pldc) {} ProductDataContainerLDC( const ProductDataContainerLDC & pdldc ) : pldc(pdldc.pldc) {} virtual ~ProductDataContainerLDC() {} virtual int getSize() const { return pldc.getNumberOfComponents(); } virtual DataContainer & operator[](int i) { try { return pldc[i]; } catch (RVLException & e) { e<<"\ncalled from ProductDataContainerLDC::operator[]\n"; throw e; } } virtual DataContainer const & operator[](int i) const { try { return pldc[i]; } catch (RVLException & e) { e<<"\ncalled from ProductDataContainerLDC::operator[]\n"; throw e; } } }; /** ProductLocalDataContainer made by dicing up a LocalDataContainer. It is possible to treat the data as either a single array or as a block structured array. */ template class PartitionedLocalDataContainer : public ProductLocalDataContainer { private: LocalDataContainer & ldc; vector k; vector *> comps; PartitionedLocalDataContainer() {} public: /** Copy constructor. Makes new vector of pointers to the components. */ PartitionedLocalDataContainer(const PartitionedLocalDataContainer & p) : ldc(p.ldc), k(p.k), comps(k.size()) { try { int nblk=k.size(); int ndim=0; for (int i=0;i(ldc,ndim,k[i]); ndim+=k[i]; } } catch (RVLException & e) { e<<"\ncalled from PartitionedLocalDataContainer constructor\n"; throw e; } } /** Main constructor. Creates STL vector of LocalDataContainerSection *'s. */ PartitionedLocalDataContainer( LocalDataContainer & _ldc, vector _k) : ldc(_ldc), k(_k), comps(k.size()) { try { int nblk = k.size(); int ndim = 0; for (int i=0;i(ldc,ndim,k[i]); ndim+=k[i]; } } catch (RVLException & e) { e<<"\ncalled from PartitionedLocalDataContainer constructor\n"; throw e; } } ~PartitionedLocalDataContainer() { for (int i=0;i & operator[](int i) { if (i<0 || i>=(k.size())) { RVLException e; e<<"Error: PartitionedLocalDataContainer::getLocalComponent\n"; e<<"input index "< const & operator[](int i) const { if (i<0 || i>=(k.size())) { RVLException e; e<<"Error: PartitionedLocalDataContainer::getLocalComponent\n"; e<<"input index "<write(str); } return str; } }; } #endif