00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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