PageRenderTime 2651ms CodeModel.GetById 2634ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llcallbacklist.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 66 lines | 26 code | 12 blank | 28 comment | 0 complexity | c41a1c62692bfdac51fae4c63162a648 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llcallbacklist.h
  3. * @brief A simple list of callback functions to call.
  4. *
  5. * $LicenseInfo:firstyear=2001&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_LLCALLBACKLIST_H
  27. #define LL_LLCALLBACKLIST_H
  28. #include "llstl.h"
  29. class LLCallbackList
  30. {
  31. public:
  32. typedef void (*callback_t)(void*);
  33. LLCallbackList();
  34. ~LLCallbackList();
  35. void addFunction( callback_t func, void *data = NULL ); // register a callback, which will be called as func(data)
  36. BOOL containsFunction( callback_t func, void *data = NULL ); // true if list already contains the function/data pair
  37. BOOL deleteFunction( callback_t func, void *data = NULL ); // removes the first instance of this function/data pair from the list, false if not found
  38. void callFunctions(); // calls all functions
  39. void deleteAllFunctions();
  40. static void test();
  41. protected:
  42. // Use a list so that the callbacks are ordered in case that matters
  43. typedef std::pair<callback_t,void*> callback_pair_t;
  44. typedef std::list<callback_pair_t > callback_list_t;
  45. callback_list_t mCallbackList;
  46. };
  47. typedef boost::function<void ()> nullary_func_t;
  48. typedef boost::function<bool ()> bool_func_t;
  49. // Call a given callable once in idle loop.
  50. void doOnIdleOneTime(nullary_func_t callable);
  51. // Repeatedly call a callable in idle loop until it returns true.
  52. void doOnIdleRepeating(bool_func_t callable);
  53. extern LLCallbackList gIdleCallbacks;
  54. #endif