PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llui/llviewquery.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 136 lines | 81 code | 26 blank | 29 comment | 1 complexity | 738e360b922503bab5096d49ccd78749 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llviewquery.h
  3. * @brief Query algorithm for flattening and filtering the view hierarchy.
  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_LLVIEWQUERY_H
  27. #define LL_LLVIEWQUERY_H
  28. #include <list>
  29. #include "llsingleton.h"
  30. #include "llui.h"
  31. class LLView;
  32. typedef std::list<LLView *> viewList_t;
  33. typedef std::pair<BOOL, BOOL> filterResult_t;
  34. // Abstract base class for all query filters.
  35. class LLQueryFilter
  36. {
  37. public:
  38. virtual ~LLQueryFilter() {};
  39. virtual filterResult_t operator() (const LLView* const view, const viewList_t & children) const = 0;
  40. };
  41. class LLQuerySorter
  42. {
  43. public:
  44. virtual ~LLQuerySorter() {};
  45. virtual void operator() (LLView * parent, viewList_t &children) const;
  46. };
  47. class LLLeavesFilter : public LLQueryFilter, public LLSingleton<LLLeavesFilter>
  48. {
  49. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  50. };
  51. class LLRootsFilter : public LLQueryFilter, public LLSingleton<LLRootsFilter>
  52. {
  53. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  54. };
  55. class LLVisibleFilter : public LLQueryFilter, public LLSingleton<LLVisibleFilter>
  56. {
  57. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  58. };
  59. class LLEnabledFilter : public LLQueryFilter, public LLSingleton<LLEnabledFilter>
  60. {
  61. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  62. };
  63. class LLTabStopFilter : public LLQueryFilter, public LLSingleton<LLTabStopFilter>
  64. {
  65. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  66. };
  67. class LLCtrlFilter : public LLQueryFilter, public LLSingleton<LLCtrlFilter>
  68. {
  69. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
  70. };
  71. template <class T>
  72. class LLWidgetTypeFilter : public LLQueryFilter
  73. {
  74. /*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const
  75. {
  76. return filterResult_t(dynamic_cast<const T*>(view) != NULL, TRUE);
  77. }
  78. };
  79. // Algorithm for flattening
  80. class LLViewQuery
  81. {
  82. public:
  83. typedef std::list<const LLQueryFilter*> filterList_t;
  84. typedef filterList_t::iterator filterList_iter_t;
  85. typedef filterList_t::const_iterator filterList_const_iter_t;
  86. LLViewQuery() : mPreFilters(), mPostFilters(), mSorterp() {}
  87. virtual ~LLViewQuery() {}
  88. void addPreFilter(const LLQueryFilter* prefilter) { mPreFilters.push_back(prefilter); }
  89. void addPostFilter(const LLQueryFilter* postfilter) { mPostFilters.push_back(postfilter); }
  90. const filterList_t & getPreFilters() const { return mPreFilters; }
  91. const filterList_t & getPostFilters() const { return mPostFilters; }
  92. void setSorter(const LLQuerySorter* sorter) { mSorterp = sorter; }
  93. const LLQuerySorter* getSorter() const { return mSorterp; }
  94. viewList_t run(LLView * view) const;
  95. // syntactic sugar
  96. viewList_t operator () (LLView * view) const { return run(view); }
  97. // override this method to provide iteration over other types of children
  98. virtual void filterChildren(LLView * view, viewList_t& filtered_children) const;
  99. private:
  100. filterResult_t runFilters(LLView * view, const viewList_t children, const filterList_t filters) const;
  101. filterList_t mPreFilters;
  102. filterList_t mPostFilters;
  103. const LLQuerySorter* mSorterp;
  104. };
  105. class LLCtrlQuery : public LLViewQuery
  106. {
  107. public:
  108. LLCtrlQuery();
  109. };
  110. #endif // LL_LLVIEWQUERY_H