PageRenderTime 88ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llconfirmationmanager.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 85 lines | 48 code | 11 blank | 26 comment | 0 complexity | 533dabca10f785ba7d8ca0cc0d2c6a01 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llconfirmationmanager.h
  3. * @brief LLConfirmationManager class definition
  4. *
  5. * $LicenseInfo:firstyear=2006&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLCONFIRMATIONMANAGER_H
  27. #define LL_LLCONFIRMATIONMANAGER_H
  28. class LLConfirmationManager
  29. {
  30. public:
  31. class ListenerBase
  32. {
  33. public:
  34. virtual ~ListenerBase();
  35. virtual void confirmed(const std::string& password) = 0;
  36. };
  37. enum Type { TYPE_NONE, TYPE_CLICK, TYPE_PASSWORD };
  38. static void confirm(Type type,
  39. const std::string& purchase, ListenerBase* listener);
  40. static void confirm(const std::string& type,
  41. const std::string& purchase, ListenerBase* listener);
  42. // note: these take control of, and delete the listener when done
  43. template <class T>
  44. class Listener : public ListenerBase
  45. {
  46. public:
  47. typedef void (T::*ConfirmationMemberFunction)(const std::string&);
  48. Listener(T& object, ConfirmationMemberFunction function)
  49. : mObject(object), mFunction(function)
  50. { }
  51. void confirmed(const std::string& password)
  52. {
  53. (mObject.*mFunction)(password);
  54. }
  55. private:
  56. T& mObject;
  57. ConfirmationMemberFunction mFunction;
  58. };
  59. template <class T>
  60. static void confirm(Type type,
  61. const std::string& action,
  62. T& obj, void(T::*func)(const std::string&))
  63. {
  64. confirm(type, action, new Listener<T>(obj, func));
  65. }
  66. template <class T>
  67. static void confirm(const std::string& type,
  68. const std::string& action,
  69. T& obj, void(T::*func)(const std::string&))
  70. {
  71. confirm(type, action, new Listener<T>(obj, func));
  72. }
  73. };
  74. #endif