00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://mrpt.sourceforge.net/ | 00005 | | 00006 | Copyright (C) 2005-2009 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CMatrixTemplateObjects_H 00029 #define CMatrixTemplateObjects_H 00030 00031 #include <mrpt/math/CMatrixTemplate.h> 00032 00033 namespace mrpt 00034 { 00035 namespace math 00036 { 00048 template <class T> 00049 class CMatrixTemplateObjects : public CMatrixTemplate<T*> 00050 { 00051 private: 00052 bool m_freeObjects; 00053 00054 public: 00057 CMatrixTemplateObjects(const CMatrixTemplate<T>& m) : CMatrixTemplate<T*>( m ), m_freeObjects(true) 00058 { 00059 } 00060 00063 CMatrixTemplateObjects(size_t row = 3, size_t col = 3) : CMatrixTemplate<T*>( row, col ), m_freeObjects(true) 00064 { 00065 for (size_t i=0; i < CMatrixTemplate<T*>::getRowCount(); i++) 00066 for (size_t j=0; j < CMatrixTemplate<T*>::getColCount(); j++) 00067 CMatrixTemplate<T*>::m_Val[i][j] = NULL; 00068 } 00069 00072 virtual void setSize(size_t row, size_t col) 00073 { 00074 CMatrixTemplate<T*>::realloc(row,col,true); 00075 } 00076 00079 virtual ~CMatrixTemplateObjects() 00080 { 00081 if (m_freeObjects) 00082 freeAllObjects(); 00083 } 00084 00087 void freeAllObjects() 00088 { 00089 for (size_t i=0; i < CMatrixTemplate<T*>::getRowCount(); i++) 00090 for (size_t j=0; j < CMatrixTemplate<T*>::getColCount(); j++) 00091 if (CMatrixTemplate<T*>::m_Val[i][j]!=NULL) 00092 { 00093 delete CMatrixTemplate<T*>::m_Val[i][j]; 00094 CMatrixTemplate<T*>::m_Val[i][j] = NULL; 00095 } 00096 } 00097 00100 CMatrixTemplateObjects& operator = (const CMatrixTemplateObjects& m) 00101 { 00102 CMatrixTemplate<T*>::realloc( m.getRowCount(), m.getColCount() ); 00103 00104 for (size_t i=0; i < CMatrixTemplate<T*>::getRowCount(); i++) 00105 for (size_t j=0; j < CMatrixTemplate<T*>::getColCount(); j++) 00106 CMatrixTemplate<T*>::m_Val[i][j] = m.m_Val[i][j]; 00107 return *this; 00108 } 00109 00113 void setDestroyBehavior(bool freeObjects = true) 00114 { 00115 m_freeObjects = freeObjects; 00116 } 00117 00121 void allocAllObjects() 00122 { 00123 for (size_t i=0; i < CMatrixTemplate<T*>::getRowCount(); i++) 00124 for (size_t j=0; j < CMatrixTemplate<T*>::getColCount(); j++) 00125 if (NULL==CMatrixTemplate<T*>::m_Val[i][j]) 00126 CMatrixTemplate<T*>::m_Val[i][j] = new T(); 00127 } 00128 00129 }; // end of class definition 00130 00131 00132 } // End of namespace 00133 } // End of namespace 00134 00135 #endif
Page generated by Doxygen 1.5.8 for MRPT 0.6.5 SVN: at Thu Feb 26 02:07:47 EST 2009 |