PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 2ms 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
  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
 27#ifndef LL_LLVIEWQUERY_H
 28#define LL_LLVIEWQUERY_H
 29
 30#include <list>	
 31
 32#include "llsingleton.h"
 33#include "llui.h"
 34
 35class LLView;
 36
 37typedef std::list<LLView *>			viewList_t;
 38typedef std::pair<BOOL, BOOL>		filterResult_t;
 39
 40// Abstract base class for all query filters.
 41class LLQueryFilter
 42{
 43public:
 44	virtual ~LLQueryFilter() {};
 45	virtual filterResult_t operator() (const LLView* const view, const viewList_t & children) const = 0;
 46};
 47
 48class LLQuerySorter
 49{
 50public:
 51	virtual ~LLQuerySorter() {};
 52	virtual void operator() (LLView * parent, viewList_t &children) const;
 53};
 54
 55class LLLeavesFilter : public LLQueryFilter, public LLSingleton<LLLeavesFilter>
 56{
 57	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 58};
 59
 60class LLRootsFilter : public LLQueryFilter, public LLSingleton<LLRootsFilter>
 61{
 62	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 63};
 64
 65class LLVisibleFilter : public LLQueryFilter, public LLSingleton<LLVisibleFilter>
 66{
 67	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 68};
 69
 70class LLEnabledFilter : public LLQueryFilter, public LLSingleton<LLEnabledFilter>
 71{
 72	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 73};
 74
 75class LLTabStopFilter : public LLQueryFilter, public LLSingleton<LLTabStopFilter>
 76{
 77	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 78};
 79
 80class LLCtrlFilter : public LLQueryFilter, public LLSingleton<LLCtrlFilter>
 81{
 82	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const;
 83};
 84
 85template <class T>
 86class LLWidgetTypeFilter : public LLQueryFilter
 87{
 88	/*virtual*/ filterResult_t operator() (const LLView* const view, const viewList_t & children) const
 89	{
 90		return filterResult_t(dynamic_cast<const T*>(view) != NULL, TRUE);
 91	}
 92
 93};
 94
 95// Algorithm for flattening
 96class LLViewQuery
 97{
 98public:
 99	typedef std::list<const LLQueryFilter*>		filterList_t;
100	typedef filterList_t::iterator				filterList_iter_t;
101	typedef filterList_t::const_iterator		filterList_const_iter_t;
102
103	LLViewQuery() : mPreFilters(), mPostFilters(), mSorterp() {}
104	virtual ~LLViewQuery() {}
105
106	void addPreFilter(const LLQueryFilter* prefilter) { mPreFilters.push_back(prefilter); }
107	void addPostFilter(const LLQueryFilter* postfilter) { mPostFilters.push_back(postfilter); }
108	const filterList_t & getPreFilters() const { return mPreFilters; }
109	const filterList_t & getPostFilters() const { return mPostFilters; }
110
111	void setSorter(const LLQuerySorter* sorter) { mSorterp = sorter; }
112	const LLQuerySorter* getSorter() const { return mSorterp; }
113
114	viewList_t run(LLView * view) const;
115	// syntactic sugar
116	viewList_t operator () (LLView * view) const { return run(view); }
117
118	// override this method to provide iteration over other types of children
119	virtual void filterChildren(LLView * view, viewList_t& filtered_children) const;
120
121private:
122
123	filterResult_t runFilters(LLView * view, const viewList_t children, const filterList_t filters) const;
124
125	filterList_t mPreFilters;
126	filterList_t mPostFilters;
127	const LLQuerySorter* mSorterp;
128};
129
130class LLCtrlQuery : public LLViewQuery
131{
132public:
133	LLCtrlQuery();
134};
135
136#endif // LL_LLVIEWQUERY_H