CallbackHook.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /******************************************************************************
  19. *
  20. * FILE
  21. * $Archive: /Commando/Code/wwlib/CallbackHook.h $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * Steven Clinard
  27. * $Author: Denzil_l $
  28. *
  29. * VERSION INFO
  30. * $Modtime: 7/03/01 4:59p $
  31. * $Revision: 1 $
  32. *
  33. ******************************************************************************/
  34. #ifndef __CALLBACKHOOK_H__
  35. #define __CALLBACKHOOK_H__
  36. class CallbackHook
  37. {
  38. public:
  39. CallbackHook()
  40. {}
  41. virtual ~CallbackHook()
  42. {}
  43. virtual bool DoCallback(void)
  44. {return false;}
  45. protected:
  46. CallbackHook(const CallbackHook&);
  47. const CallbackHook& operator=(const CallbackHook&);
  48. };
  49. template<class T> class Callback :
  50. public CallbackHook
  51. {
  52. public:
  53. Callback(bool (*callback)(T), T userdata) :
  54. mCallback(callback),
  55. mUserData(userdata)
  56. {}
  57. virtual ~Callback()
  58. {}
  59. virtual bool DoCallback(void)
  60. {
  61. if (mCallback)
  62. {
  63. return mCallback(mUserData);
  64. }
  65. return false;
  66. }
  67. private:
  68. bool (*mCallback)(T);
  69. T mUserData;
  70. };
  71. #endif // __CALLBACKHOOK_H__