• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/threading/ThreadStartDelegate.h

00001 /* Ported to SPL from commonc++, original attribution below. */
00002 /* ---------------------------------------------------------------------------
00003    commonc++ - A C++ Common Class Library
00004    Copyright (C) 2005-2009  Mark A Lindner
00005 
00006    This file is part of commonc++.
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License as published by the Free Software Foundation; either
00011    version 2 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public
00019    License along with this library; if not, write to the Free
00020    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021    ---------------------------------------------------------------------------
00022 */
00023 #ifndef _threadstartdelegate_h
00024 #define _threadstartdelegate_h
00025 
00026 #include <spl/Memory.h>
00027 #include <spl/threading/Thread.h>
00028 
00057 template<class T> class ThreadStartDelegate : public Thread
00058 {
00059 private:
00060         T* m_object;
00061         void (T::*m_func)();
00062 
00063 public:
00064 
00072         inline ThreadStartDelegate(T *object, void (T::* func)())
00073         : m_object(object), m_func(func)
00074         {
00075         }
00076 
00077         inline ThreadStartDelegate()
00078         : m_object(NULL), m_func(NULL)
00079         {
00080         }
00081 
00082         virtual ~ThreadStartDelegate()
00083         {
00084         }
00085 
00086         inline void Set(T *object, void (T::* func)())
00087         {
00088                 m_object = object;
00089                 m_func = func;
00090         }
00091 
00092 #if defined(DEBUG)
00093         void CheckMem() const
00094         {
00095         }
00096 
00097         void ValidateMem() const
00098         {
00099         }
00100 #endif
00101 
00102 private:
00103         virtual void Run()
00104         {
00105                 (m_object->*m_func)();
00106         }
00107 };
00108 
00109 #endif