llmemberlistener.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @file llmemberlistener.h
  3. * @brief Listener class which registers itself with its parent view
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewergpl$
  6. *
  7. * Copyright (c) 2006-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLMEMBERLISTENER_H
  33. #define LL_LLMEMBERLISTENER_H
  34. #include "llevent.h"
  35. // Example usage:
  36. //
  37. // In header:
  38. //
  39. // class T
  40. // {
  41. // class LLDoTest : public LLMemberListener<LLInventoryView>
  42. // {
  43. // bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  44. // const LLSD& userdata);
  45. // };
  46. // LLDoTest mDoTest;
  47. // }
  48. //
  49. // In cpp module:
  50. //
  51. // T::T()
  52. // {
  53. // mDoTest.registerListener(this, "T.Test");
  54. // }
  55. //
  56. // T::LLDoTest::handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  57. // const LLSD& userdata)
  58. // {
  59. // T *self = mPtr;
  60. // ...
  61. // }
  62. template <class T>
  63. class LLMemberListener : public LLOldEvents::LLSimpleListener
  64. {
  65. public:
  66. LLMemberListener()
  67. : mPtr(NULL)
  68. {
  69. }
  70. void registerListener(T* pointer, const std::string& register_name)
  71. {
  72. mPtr = pointer;
  73. mRegisteredName = register_name;
  74. pointer->registerEventListener(register_name, this);
  75. }
  76. // This is what you have to override to handle this event
  77. virtual bool handleEvent(LLPointer<LLOldEvents::LLEvent> event,
  78. const LLSD& userdata) = 0;
  79. protected:
  80. T* mPtr; // The object that this listener manipulates
  81. std::string mRegisteredName;
  82. };
  83. #endif // LL_LLMEMBERLISTENER_H