NCBI C++ ToolKit
filter.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS___FILTER__HPP
2 #define GUI_UTILS___FILTER__HPP
3 
4 /* $Id: filter.hpp 14562 2007-05-18 11:48:21Z dicuccio $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Mike DiCuccio
30  *
31  * File Description:
32  * CFilterSet -- container for a number of column filtering rules
33  * CFilter -- encapsulates a single filter rule
34  */
35 
36 
37 #include <corelib/ncbiobj.hpp>
38 #include <gui/gui.hpp>
39 
40 #include <vector>
41 #include <string>
42 
43 
44 /** @addtogroup GUI_UTILS
45  *
46  * @{
47  */
48 
49 
51 
52 
53 //
54 // class CFilter defines the interface for a single filter object.
55 // This class represents a single filter rule, where a rule is defined as a
56 // comparison operation performed on a single entry in a row of a table. The
57 // API assumes that a row can be expressed as a vector of strings, one string
58 // per column; comparisons are then done on those strings in a format defined
59 // by the caller. Formats supported include string and numeric comparisons.
60 //
62 {
63 public:
64 
65  // our modes of filtering
66  enum EMode {
75  eGreaterEquals
76  };
77 
78  // the type of comparison we perform (numeric vs. string)
79  enum ECompare {
81  eNumeric
82  };
83 
84  // default ctor
85  CFilter(const string& name,
86  int col, EMode mode,
87  const string& data);
88 
89  // apply our filter to a single row
90  bool Filter(const vector<string>& row,
91  ECompare comp) const;
92 
93  //
94  // accessors
95  //
96 
97  const string& GetName(void) const { return m_Name; }
98  void SetName(const string& s) { m_Name = s; }
99 
100  int GetColumn(void) const { return m_Col; }
101  void SetColumn(int col) { m_Col = col; }
102 
103  EMode GetMode(void) const { return m_Mode; }
104  void SetMode(EMode mode) { m_Mode = mode; }
105 
106  const string& GetData(void) const { return m_Data; }
107  void SetData(const string& s) { m_Data = s; }
108 
109 private:
110 
111  // a name for this filter
112  string m_Name;
113 
114  // the column we compare (-1 = unassigned)
115  int m_Col;
116 
117  // our comparison mode
119 
120  // what we match / don't match
121  string m_Data;
122 };
123 
124 
125 
126 //
127 // class CFilterSet is a container of filters that permits row-by-row
128 // application of all named filters.
129 //
130 // This is the main interface class for filtering tables. This class maintains
131 // a list of filters and applies each filter sequentially to a row as the row
132 // is supplied to it. Given its set of filters, this container will return
133 // 'true' to indicate a row matches all filters or 'false' to indicate that a
134 // row fails to match at least one filter.
135 //
137 {
138 public:
139  typedef list< CRef<CFilter> > TFilters;
140 
141  // filter a given row, returning true if a match exists for all filters in
142  // the set
143  bool Filter(const vector<string>& row) const;
144 
145  // add a filter to the list
146  void Add(CFilter* filter);
147 
148  // remove a named filter
149  void Remove(const string& name);
150 
151  // remove a filter by pointer
152  void Remove(CFilter* filter);
153 
154  // access the filters
155  const TFilters& GetFilters(void) const { return m_Filters; }
156 
157  // set the sorting mechanism for a numbered column
158  void SetColType(size_t col, CFilter::ECompare type);
159 
160 private:
161 
162  // a notion of how our columns are to be sorted and compared
163  vector<CFilter::ECompare> m_ColTypes;
164 
165  // our list of named filters
167 
168 };
169 
170 
172 
173 /* @} */
174 
175 #endif // GUI_UTILS___FILTER__HPP
CFilter –.
Definition: Filter.hpp:66
CObject –.
Definition: ncbiobj.hpp:180
char data[12]
Definition: iconv.c:80
const string & GetName(void) const
Definition: filter.hpp:97
string m_Data
Definition: filter.hpp:121
const TFilters & GetFilters(void) const
Definition: filter.hpp:155
const string & GetData(void) const
Definition: filter.hpp:106
void SetData(const string &s)
Definition: filter.hpp:107
EMode m_Mode
Definition: filter.hpp:118
vector< CFilter::ECompare > m_ColTypes
Definition: filter.hpp:163
void SetMode(EMode mode)
Definition: filter.hpp:104
void SetColumn(int col)
Definition: filter.hpp:101
int GetColumn(void) const
Definition: filter.hpp:100
string m_Name
Definition: filter.hpp:112
EMode GetMode(void) const
Definition: filter.hpp:103
ECompare
Definition: filter.hpp:79
void SetName(const string &s)
Definition: filter.hpp:98
TFilters m_Filters
Definition: filter.hpp:166
list< CRef< CFilter > > TFilters
Definition: filter.hpp:139
int m_Col
Definition: filter.hpp:115
@ eLessEquals
Definition: filter.hpp:73
@ eDoesntContain
Definition: filter.hpp:69
@ eLess
Definition: filter.hpp:72
@ ePass
Definition: filter.hpp:67
@ eGreater
Definition: filter.hpp:74
@ eContains
Definition: filter.hpp:68
@ eEquals
Definition: filter.hpp:70
@ eDoesntEqual
Definition: filter.hpp:71
@ eString
Definition: filter.hpp:80
ECompare
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIOBJUTILS_EXPORT
Definition: gui_export.h:512
mdb_mode_t mode
Definition: lmdb++.h:38
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
void Filter(TTimeline &timeline, TServers &servers)
#define row(bind, expected)
Definition: string_bind.c:73
Definition: type.c:6
@ eNumeric
Definition: text_util.cpp:53
Modified on Fri May 24 14:57:03 2024 by modify_doxy.py rev. 669887