UObjDeletionThread.h
Go to the documentation of this file.
1 /*
2 * utilite is a cross-platform library with
3 * useful utilities for fast and small developing.
4 * Copyright (C) 2010 Mathieu Labbe
5 *
6 * utilite is free library: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * utilite is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef UOBJDELETIONTHREAD_H
21 #define UOBJDELETIONTHREAD_H
22 
24 #include "rtabmap/utilite/UEvent.h"
26 
31 class UObjDeletedEvent : public UEvent
32 {
33 public:
34  UObjDeletedEvent(int objDeletionThreadId) : UEvent(objDeletionThreadId) {}
35  virtual ~UObjDeletedEvent() {}
39  virtual std::string getClassName() const {return std::string("UObjDeletedEvent");}
40 };
41 
47 template<class T>
49 {
50 public:
56  UObjDeletionThread(T * obj, int id=0) :
57  obj_(obj),
58  id_(id),
59  waitMs_(0) {}
60 
69  {
70  join(true);
71  if(obj_)
72  {
73  delete obj_;
74  }
75  }
76 
81  void startDeletion(int waitMs = 0) {waitMs_ = waitMs; this->start();}
82 
87  int id() const {return id_;}
88 
93  void setObj(T * obj)
94  {
95  join();
96  if(obj_)
97  {
98  delete obj_;
99  obj_ = 0;
100  }
101  obj_ = obj;
102  }
103 
104 private:
108  virtual void mainLoop()
109  {
110  if(waitMs_)
111  {
112  uSleep(waitMs_);
113  }
114  if(obj_)
115  {
116  delete obj_;
117  obj_ = 0;
118  }
119  this->kill();
121  }
122 
123 private:
124  T * obj_;
125  int id_;
126  int waitMs_;
127 };
128 
129 #endif /* UOBJDELETIONTHREAD_H */
UObjDeletionThread::~UObjDeletionThread
virtual ~UObjDeletionThread()
Definition: UObjDeletionThread.h:68
UObjDeletedEvent::UObjDeletedEvent
UObjDeletedEvent(int objDeletionThreadId)
Definition: UObjDeletionThread.h:34
UThreadNode.h
UObjDeletionThread
Definition: UObjDeletionThread.h:48
UObjDeletedEvent
Definition: UObjDeletionThread.h:31
UThread::join
void join(bool killFirst=false)
Definition: UThread.cpp:85
UEvent
Definition: UEvent.h:57
UEvent.h
UObjDeletionThread::waitMs_
int waitMs_
Definition: UObjDeletionThread.h:126
UThread::kill
void kill()
Definition: UThread.cpp:48
UThread::start
void start()
Definition: UThread.cpp:122
Eigen::Triplet
UObjDeletionThread::id
int id() const
Definition: UObjDeletionThread.h:87
UObjDeletionThread::startDeletion
void startDeletion(int waitMs=0)
Definition: UObjDeletionThread.h:81
UObjDeletionThread::id_
int id_
Definition: UObjDeletionThread.h:125
UObjDeletedEvent::~UObjDeletedEvent
virtual ~UObjDeletedEvent()
Definition: UObjDeletionThread.h:35
UThread
Definition: UThread.h:86
UObjDeletionThread::UObjDeletionThread
UObjDeletionThread(T *obj, int id=0)
Definition: UObjDeletionThread.h:56
UObjDeletionThread::setObj
void setObj(T *obj)
Definition: UObjDeletionThread.h:93
UEventsManager::post
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
Definition: UEventsManager.cpp:54
uSleep
void uSleep(unsigned int ms)
Definition: Posix/UThreadC.h:23
UObjDeletedEvent::getClassName
virtual std::string getClassName() const
Definition: UObjDeletionThread.h:39
UEventsManager.h
UObjDeletionThread::mainLoop
virtual void mainLoop()
Definition: UObjDeletionThread.h:108
UObjDeletionThread::obj_
T * obj_
Definition: UObjDeletionThread.h:124


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:23