UDestroyer.h
Go to the documentation of this file.
00001 /*
00002 *  utilite is a cross-platform library with
00003 *  useful utilities for fast and small developing.
00004 *  Copyright (C) 2010  Mathieu Labbe
00005 *
00006 *  utilite is free library: you can redistribute it and/or modify
00007 *  it under the terms of the GNU Lesser General Public License as published by
00008 *  the Free Software Foundation, either version 3 of the License, or
00009 *  (at your option) any later version.
00010 *
00011 *  utilite is distributed in the hope that it will be useful,
00012 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 *  GNU Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public License
00017 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #ifndef UDESTROYER_H
00021 #define UDESTROYER_H
00022 
00023 #include "rtabmap/utilite/UtiLiteExp.h" // DLL export/import defines
00024 
00033 template <class T>
00034 class UDestroyer
00035 {
00036 public:
00041     UDestroyer(T* doomed = 0)  : doomed_(doomed) {}
00042     
00043     ~UDestroyer()
00044     {
00045         if(doomed_)
00046         {
00047             delete doomed_;
00048             doomed_ = 0;
00049         }
00050     }
00051 
00057     bool setDoomed(T* doomed)
00058         {
00059         if(doomed_ && doomed)
00060         {
00061                 return false;
00062         }
00063                 doomed_ = doomed;
00064                 return true;
00065         }
00066 
00067 private:
00068     // Prevent users from making copies of a 
00069     // Destroyer to avoid double deletion:
00070     UDestroyer(const UDestroyer<T>&);
00071     void operator=(const UDestroyer<T>&);
00072 
00073 private:
00074     T* doomed_;
00075 };
00076 
00077 #endif // UDESTROYER_H


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:32