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_LOCSP 00034 #define __RVL_LOCSP 00035 00036 #include "localdata.hh" 00037 #include "space.hh" 00038 00039 namespace RVL { 00040 00045 template<class Scalar, class DataType = Scalar> 00046 class LocalSpace: public StdSpace<Scalar, DataType> { 00047 00048 protected: 00049 00050 virtual LocalDataContainerFactory<DataType> & getLDCF() const = 0; 00051 DataContainerFactory & getDCF() const { return getLDCF(); } 00052 00053 public: 00054 00055 LocalSpace() {} 00056 LocalSpace(const LocalSpace<Scalar, DataType> & sp) {} 00057 virtual ~LocalSpace() {} 00058 00060 LocalDataContainer<DataType> * buildLocalDataContainer() const { 00061 return getLDCF().buildLocal(); 00062 } 00063 00064 DataContainer * buildDataContainer() const { 00065 return buildLocalDataContainer(); 00066 } 00067 00068 bool isCompatible(DataContainer const & dc) const { 00069 try { 00070 return getLDCF().isCompatible(dc); 00071 } 00072 catch (RVLException & e) { 00073 e<<"\ncalled from RnSpace::isCompatible\n"; 00074 throw e; 00075 } 00076 } 00077 }; 00078 00084 template<class Scalar, class DataType = Scalar> 00085 class LocalVector: public Vector<Scalar> { 00086 00087 private: 00088 00089 LocalDataContainer<DataType> * ldc; 00090 00091 LocalVector() {} 00092 00093 public: 00094 00097 LocalVector( const Vector<Scalar> & v ) 00098 : Vector<Scalar>(v) { 00099 if (!(ldc = 00100 dynamic_cast<LocalDataContainer<DataType> *>(Vector<Scalar>::getDataContainer()))) { 00101 RVLException e; 00102 e<<"Error: LocalVector copy constructor\n"; 00103 e<<"input not a local vector somehow\n"; 00104 throw e; 00105 } 00106 } 00107 00110 LocalVector(const Space<Scalar> & sp ) 00111 : Vector<Scalar>(sp) { 00112 if (!(ldc = 00113 dynamic_cast<LocalDataContainer<DataType> *>(Vector<Scalar>::getDataContainer()))) { 00114 RVLException e; 00115 e<<"Error: LocalVector constructor\n"; 00116 e<<"input space does not generate LocalDataContainers\n"; 00117 throw e; 00118 } 00119 } 00120 00121 ~LocalVector() {} 00122 00124 size_t getSize() const { return ldc->getSize(); } 00136 DataType * getData() { this->Vector<Scalar>::incrementVersion(); return ldc->getData(); } 00137 DataType const * getData() const { return ldc->getData(); } 00138 00139 }; 00140 } 00141 #endif