CallbackHook.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. ** Command & Conquer Generals(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: /Renegade Setup/Autorun/CallbackHook.h $
  22. *
  23. * DESCRIPTION
  24. *
  25. * PROGRAMMER
  26. * Steven Clinard
  27. * $Author: Maria_l $
  28. *
  29. * VERSION INFO
  30. * $Modtime: 8/14/00 7:52p $
  31. * $Revision: 2 $
  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 : public CallbackHook
  50. {
  51. public:
  52. Callback(bool (*callback)(T), T userdata)
  53. : mCallback(callback),
  54. mUserData(userdata)
  55. {
  56. }
  57. virtual ~Callback()
  58. {
  59. }
  60. virtual bool DoCallback(void)
  61. {
  62. if (mCallback != NULL)
  63. {
  64. return mCallback(mUserData);
  65. }
  66. return false;
  67. }
  68. private:
  69. bool (*mCallback)(T);
  70. T mUserData;
  71. };
  72. #endif // CALLBACKHOOK_H