~ubuntu-branches/ubuntu/trusty/3depict/trusty

« back to all changes in this revision

Viewing changes to src/filtertree.h

  • Committer: Package Import Robot
  • Author(s): D Haley
  • Date: 2013-05-17 00:52:39 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20130517005239-7bl4mnhkvrhc2ba6
Tags: 0.0.13-1
Upload to unstable 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *      filtertree.h - Filter tree topology and data propagation handling
3
 
 *      Copyright (C) 2011, D Haley 
4
 
 
5
 
 *      This program is free software: you can redistribute it and/or modify
6
 
 *      it under the terms of the GNU General Public License as published by
7
 
 *      the Free Software Foundation, either version 3 of the License, or
8
 
 *      (at your option) any later version.
9
 
 
10
 
 *      This program is distributed in the hope that it will be useful,
11
 
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *      GNU General Public License for more details.
14
 
 
15
 
 *      You should have received a copy of the GNU General Public License
16
 
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
*/
18
 
 
19
 
#ifndef FILTERTREE_H
20
 
#define FILTERTREE_H
21
 
 
22
 
#include "tree.hh"
23
 
#include "select.h"
24
 
#include "filter.h"
25
 
 
26
 
 
27
 
class FilterTree
28
 
{
29
 
        private:
30
 
 
31
 
                
32
 
                //!Caching strategy
33
 
                unsigned int cacheStrategy;
34
 
                
35
 
                //!Maximum size for cache (percent of available ram).
36
 
                float maxCachePercent;
37
 
                
38
 
                //!Filters that provide and act upon datastreams. 
39
 
                tree<Filter *> filters;
40
 
        
41
 
                        
42
 
                //!Get the filter refresh seed points in tree, by examination of tree caches, block/emit of filters
43
 
                //and tree topology
44
 
                void getFilterRefreshStarts(vector<tree<Filter *>::iterator > &propStarts) const;
45
 
                
46
 
                        
47
 
                //Retrieve the filter's pointer from its ID value       
48
 
                Filter* getFilterByIdNonConst(unsigned long long filterId) const;
49
 
                
50
 
#ifdef DEBUG
51
 
                //!Check that the output of filter refresh functions
52
 
                void checkRefreshValidity(const vector< const FilterStreamData *> curData, 
53
 
                                        const Filter *refreshFilter) const;
54
 
#endif
55
 
                
56
 
                
57
 
                //TODO: Move me to tree.hh      
58
 
                //!Returns true if the testChild is a child of testParent.
59
 
                // returns false if testchild == testParent, or if the testParent
60
 
                // is not a parent of testChild.
61
 
                bool isChild(const tree<Filter *> &treeInst,
62
 
                                tree<Filter *>::iterator testParent,
63
 
                                tree<Filter *>::iterator testChild) const;
64
 
 
65
 
 
66
 
                size_t countChildFilters(const tree<Filter *> &treeInst,
67
 
                                        const vector<tree<Filter *>::iterator> &nodes) const;
68
 
        public:
69
 
                FilterTree();
70
 
                ~FilterTree();
71
 
 
72
 
                FilterTree(const FilterTree &orig);
73
 
 
74
 
                void swap(FilterTree &);
75
 
                //Note that the = operator creates a *CLONE* of the orignal tree,
76
 
                // not an exact duplicate. underlying pointers will not be the same
77
 
                const FilterTree &operator=(const FilterTree &orig);
78
 
        
79
 
                //Return iterator to tree contents begin.       
80
 
                tree<Filter *>::pre_order_iterator depthBegin() const { return filters.begin();};
81
 
                //Return iterator to tree contents end
82
 
                tree<Filter *>::pre_order_iterator depthEnd() const { return filters.end();}
83
 
                //Return depth of a given iterator
84
 
                size_t maxDepth() const;
85
 
 
86
 
                size_t depth(const tree<Filter*>::pre_order_iterator &it) const 
87
 
                        { ASSERT(std::find(filters.begin(),filters.end(),*it)!=filters.end()); return filters.depth(it);};
88
 
 
89
 
                //FIXME: REFACTOR: REMOVE ME
90
 
                // We should NOT be granting this kind of access...
91
 
                tree<Filter*> &getTree() { return filters;}
92
 
 
93
 
                //!Return the number of filters
94
 
                size_t size() const {return filters.size();};
95
 
        
96
 
                //!Remove all tree contents
97
 
                void clear(); 
98
 
 
99
 
                bool contains(const Filter *f) const;
100
 
        
101
 
                //Refresh functions     
102
 
                //---   
103
 
                //!Run the initialisation stage of the filter processing
104
 
                void initFilterTree() const;
105
 
 
106
 
                bool setFilterProperty(Filter *f, unsigned int set, 
107
 
                                                unsigned int key, const std::string &value, bool &needUpdate);
108
 
                
109
 
                //!Refresh the entire filter tree. Whilst this is public, great care must be taken in
110
 
                // deleting the filterstream data correctly. To do this, use the "safeDeleteFilterList" function.
111
 
                unsigned int refreshFilterTree( 
112
 
                        std::list<std::pair<Filter *, std::vector<const FilterStreamData * > > > &outData,
113
 
                        std::vector<SelectionDevice<Filter> *> &devices,std::vector<string> &consoleMessages,
114
 
                                                ProgressData &curProg, bool (*callback)(bool));
115
 
                
116
 
                //!Safely delete data generated by refreshFilterTree(...). 
117
 
                //a mask can be used to *prevent* STREAM_TYPE_blah from being deleted. Deleted items are removed from the list.
118
 
                void safeDeleteFilterList(std::list<std::pair<Filter *, std::vector<const FilterStreamData * > > > &outData, 
119
 
                                                                size_t typeMask, bool maskPrevents) const;
120
 
                //---
121
 
 
122
 
 
123
 
                //!function for the loading of a filter tree from its XML representation
124
 
                unsigned int loadXML(const xmlNodePtr &treeParent, 
125
 
                                std::ostream &errStream, const std::string &stateDir);
126
 
 
127
 
 
128
 
                //Write out the filters into their XML representation
129
 
                bool saveXML(std::ofstream &f, std::map<string,string> &fileMapping,
130
 
                                        bool writePackage, bool useRelativePaths, unsigned int minTabDepth=0) const;
131
 
 
132
 
 
133
 
                //Topological alteration  & examination functions
134
 
                //----------    
135
 
                //!Remove an element and all sub elements from the tree, 
136
 
                void removeSubtree(Filter *f);
137
 
                
138
 
                //!Add a new filter to the tree. Note that pointer will be released
139
 
                // by filter destructor
140
 
                void addFilter(Filter *f, const Filter *parent);
141
 
                
142
 
                //!Add a new tree as a subtree to a node 
143
 
                void addFilterTree(FilterTree &f, const Filter *parent);
144
 
 
145
 
                //!Move a branch of the tree to a new position
146
 
                bool reparentFilter(Filter *f, const Filter *newParent);
147
 
                //!Duplicate a branch of the tree to a new position. Do not copy cache,
148
 
                bool copyFilter(Filter *id, const Filter *newParent);
149
 
 
150
 
                //Obtain a copy of the filters in the specified subtree 
151
 
                void cloneSubtree(FilterTree &f,Filter *targetFilt) const;
152
 
                //---------
153
 
        
154
 
 
155
 
                //Filter alteration functions
156
 
                //---------     
157
 
                //!Set the filter user text
158
 
                bool setFilterString(Filter *, const std::string &s);
159
 
                
160
 
                //!Invalidate the cache of a given Filter and all its children. set to 0 to clear all.
161
 
                void clearCache(const Filter *filt);
162
 
                
163
 
                
164
 
                //!Invalidate the cache of a given type of filter
165
 
                //      and all their children.
166
 
                void clearCacheByType(unsigned int type);
167
 
                
168
 
                //!Return all of a given type of filter from the filter tree
169
 
                void getFiltersByType(std::vector<const Filter *> &filters, unsigned int type) const;
170
 
                
171
 
                //!Make the filter system safe (non-hazardous)
172
 
                void removeHazardousContents();
173
 
 
174
 
                
175
 
                //!Used to remove potentially hazardous filters 
176
 
                //(filters that can do nasty things to computers, like executing commands)
177
 
                //which may have come from unsafe sources
178
 
                void stripHazardousContents();
179
 
                
180
 
                //!return true if the tree contains hazardous filters
181
 
                bool hasHazardousContents() const ;
182
 
                
183
 
                //!Force a wipe of all caches in the filter tree
184
 
                void purgeCache();
185
 
        
186
 
 
187
 
                //!Returns true if any of the filters (incl. stash)
188
 
                //return a state override (i.e. refer to external entities, such as files)
189
 
                bool hasStateOverrides() const ;
190
 
 
191
 
                bool hasUpdates() const ;
192
 
 
193
 
                //---------     
194
 
                
195
 
                void setCachePercent(unsigned int newCache);
196
 
};
197
 
 
198
 
#endif