00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef FSF_FILTER_H
00030 #define FSF_FILTER_H
00031
00032
00033
00034 #include <list>
00035
00036 #include "FsfNode.h"
00037 #include "FsfPulse.h"
00038 #include "FsfHandle.h"
00039
00040 namespace fsf{
00041
00056
00070 class CFilter{
00071 private:
00072 std::string m_strName;
00073 bool m_bWildcard;
00074 long m_nFilterID;
00075 bool m_bOptional;
00076
00078 void setWildcardFlag() { m_bWildcard=(m_strName.find_first_of("*?[]")!=std::string::npos); }
00079
00080 protected:
00081
00084
00085
00086 const std::string &getName() const { return m_strName; }
00088 bool hasWildcard() const { return m_bWildcard; }
00090
00091 public:
00093
00094
00095 CFilter() : m_bWildcard(false), m_nFilterID(-1), m_bOptional(false) {}
00097 CFilter(const std::string &strName, long nFilterID=-1, bool bOptional=false)
00098 : m_strName(strName), m_nFilterID(nFilterID), m_bOptional(bOptional) { setWildcardFlag(); }
00100 CFilter(const CFilter &f);
00102 virtual ~CFilter() {}
00104
00106
00107
00108 void getName(std::string &strName) const { strName.assign(m_strName); }
00110 long getFilterID() const { return m_nFilterID; }
00112 bool isOptional() const { return m_bOptional; }
00114
00116
00117
00118 void setName(const std::string &strName) { m_strName.assign(strName); setWildcardFlag(); }
00120 void setFilterID(long nFilterID) { m_nFilterID=nFilterID; }
00122 bool setOptional(bool bOptional=true) { return (m_bOptional=bOptional); }
00124 };
00125
00127 typedef std::list<CPassiveHandle*> PassiveHandleList;
00128 class CPassiveFilterBase;
00130 typedef std::list<CPassiveFilterBase*> PassiveFilterList;
00131
00132
00135 class CPassiveFilterBase : public CFilter {
00136 private:
00137 PassiveFilterList m_listChildren;
00138 public:
00140
00141
00142 CPassiveFilterBase() : CFilter() {}
00144 CPassiveFilterBase(const std::string &strName, long nFilterID=-1, bool bOptional=false)
00145 : CFilter(strName,nFilterID,bOptional) {}
00147 CPassiveFilterBase(const CPassiveFilterBase &f);
00149 virtual ~CPassiveFilterBase();
00152 virtual CPassiveFilterBase *clone() const =0;
00154
00156
00157
00158 bool hasChildren() { return (!m_listChildren.empty()); }
00160 void getChildren(std::list<CPassiveFilterBase*> &listFilters) { if(!m_listChildren.empty()) listFilters.insert(listFilters.end(),m_listChildren.begin(),m_listChildren.end()); }
00162
00164
00165
00166 void addChild(CPassiveFilterBase *pFilter) { m_listChildren.push_back(pFilter); }
00168
00170
00171
00172
00173 virtual bool testType(CNode *pNode) { return false; }
00175 virtual bool testExact(CNode *pNode) { return (testType(pNode) && (pNode->testNameExact(getName()))); }
00177 virtual bool testWildcard(CNode *pNode) { return (testType(pNode) && (pNode->testNameWildcard(getName()))); }
00180 virtual bool test(CNode *pNode) { return (hasWildcard())?(testWildcard(pNode)):(testExact(pNode)); }
00182
00185
00189
00190
00191 bool filter(PassiveHandleList &listHandles, CPassiveHandle *pRootHandle);
00193 bool matchNode(CPassiveHandle *pNHandle);
00195 static bool matchListList(PassiveHandleList &listHandles, PassiveFilterList &listFilter, PassiveHandleList &listRHandles, PassiveHandleList &listNHandles);
00197 bool matchList(PassiveHandleList &listHandles, PassiveHandleList &listRHandles, PassiveHandleList &listNHandles);
00199
00200 };
00201
00204 template <class N> class CPassiveFilter : public CPassiveFilterBase {
00205 public:
00207
00208
00209 CPassiveFilter() : CPassiveFilterBase() {}
00211 CPassiveFilter(const std::string &strName, long nFilterID=-1, bool bOptional=false)
00212 : CPassiveFilterBase(strName,nFilterID,bOptional) {}
00214 CPassiveFilter(const CPassiveFilter &f) : CPassiveFilterBase(f) {}
00215
00217 virtual CPassiveFilterBase *clone() const { return new CPassiveFilter<N>(*this); }
00219
00221
00222
00223 virtual bool testType(CNode *pNode) { return (dynamic_cast<N*>(pNode)!=NULL); }
00225 };
00226
00227 typedef std::list<CActiveHandle*> ActiveHandleList;
00228 class CActiveFilterBase;
00229 typedef std::list<CActiveFilterBase*> ActiveFilterList;
00230
00233 class CActiveFilterBase : public CFilter {
00234 private:
00235 std::list<CActiveFilterBase*> m_listChildren;
00236
00237 public:
00239
00240
00241 CActiveFilterBase() : CFilter() {}
00243 CActiveFilterBase(const std::string &strName, long nFilterID=-1, bool bOptional=false)
00244 : CFilter(strName,nFilterID,bOptional) {}
00246 CActiveFilterBase(const CActiveFilterBase &f);
00248 virtual ~CActiveFilterBase();
00251 virtual CActiveFilterBase *clone() const =0;
00253
00255
00256
00257 void getChildren(std::list<CActiveFilterBase*> &listFilters) { listFilters.insert(listFilters.end(),m_listChildren.begin(),m_listChildren.end()); }
00258
00260
00262
00263
00264 void addChild(CActiveFilterBase *pFilter) { m_listChildren.push_back(pFilter); }
00266
00268
00269
00270 virtual bool testType(CNode *pNode) { return false; }
00272
00280
00281
00282 bool filter(ActiveHandleList &listHandles, CNode *pRoot);
00284 bool filterExact(ActiveHandleList &listHandles, CNode *pRoot);
00286 bool filterWildcard(ActiveHandleList &listHandles, CNode *pRoot);
00287
00289 bool matchInRootListExact(ActiveHandleList &listHandles, std::list<CNode*> &listNodes);
00291 bool matchInRootListWildcard(ActiveHandleList &listHandles, std::list<CNode*> &listNodes);
00293 bool matchInRootList(ActiveHandleList &listHandles, std::list<CNode*> &listNodes) { return (hasWildcard())?(matchInRootListWildcard(listHandles,listNodes)):(matchInRootListExact(listHandles,listNodes)); }
00294
00296 bool matchInListExact(ActiveHandleList &listHandles, std::list<CNode*> &listNodes, std::list<CNode*>::iterator &it);
00298 bool matchInListWildcard(ActiveHandleList &listHandles, std::list<CNode*> &listNodes, std::list<CNode*>::iterator &it);
00300 bool matchInList(ActiveHandleList &listHandles, std::list<CNode*> &listNodes, std::list<CNode*>::iterator &it) { return (hasWildcard())?(matchInListWildcard(listHandles,listNodes,it)):(matchInListExact(listHandles,listNodes,it)); }
00302 bool matchInListExact(ActiveHandleList &listHandles, std::list<CNode*> &listNodes);
00304 bool matchInListWildcard(ActiveHandleList &listHandles, std::list<CNode*> &listNodes);
00306 bool matchInList(ActiveHandleList &listHandles, std::list<CNode*> &listNodes) { return (hasWildcard())?(matchInListWildcard(listHandles,listNodes)):(matchInListExact(listHandles,listNodes)); }
00307
00309 bool matchNodeExact(ActiveHandleList &listHandles, CNode *pNode);
00311 bool matchNodeWildcard(ActiveHandleList &listHandles, CNode *pNode);
00313 bool matchSubnodes(std::list<CActiveFilterBase*> &listFilters, std::list<CNode*> &listNodes, ActiveHandleList &listHandles);
00315 bool matchNode(ActiveHandleList &listHandles, CNode *pNode) { return (hasWildcard())?(matchNodeWildcard(listHandles,pNode)):(matchNodeExact(listHandles,pNode)); }
00316
00318
00319 };
00320
00323 template <class N> class CActiveFilter : public CActiveFilterBase {
00324 public:
00326
00327
00328 CActiveFilter() : CActiveFilterBase() {}
00330 CActiveFilter(const std::string &strName, long nFilterID=-1, bool bOptional=false)
00331 : CActiveFilterBase(strName,nFilterID,bOptional) {}
00333 CActiveFilter(const CActiveFilter &f) : CActiveFilterBase(f) {}
00334
00336 virtual CActiveFilterBase *clone() const { return new CActiveFilter<N>(*this); }
00338
00340
00341
00342 virtual bool testType(CNode *pNode) { return (dynamic_cast<N*>(pNode)!=NULL); }
00344 };
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00362
00363
00364 }
00365
00366 #endif // FSF_FILTER_H
00367