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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_PHYLO_TREE___PHYLO_TREE_QUERY_MACRO_FNS__HPP
2 #define GUI_WIDGETS_PHYLO_TREE___PHYLO_TREE_QUERY_MACRO_FNS__HPP
3 
4 /* $Id: phylo_tree_query_macro_fns.hpp 39133 2017-08-04 16:09:53Z asztalos $
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: Bob Falk
30  *
31  * File Description:
32  * Header file for classes needed to implement query execution.
33  *
34  */
35 
38 
43 
46 
48 
49 ///////////////////////////////////////////////////////////////////////////////
50 /// Base class for functions which can be called from the WHERE or DO
51 /// clauses of macros/queries using the CQueryFuncPromote classes
52 /// (phylogenetic tree, table query)
53 ///
54 class ITreeMacroFunction : public macro::IMacroFunction<CPhyloTreeNode>
55 {
56 public:
57 
58  /// Ctor
59  ITreeMacroFunction(EScopeEnum func_scope, CPhyloTree* tree)
60  : macro::IMacroFunction<CPhyloTreeNode>(func_scope)
61  , m_Tree(tree) {}
62 
63  /// Functions make the action and collect statistics
64  //bool SetQualStringValue(CObjectInfo& oi, const string& value);
65 
66 
67 protected:
69  {
70  m_Node = &data;
71  }
72 
74  {
75  m_Result = Ref(dynamic_cast<CQueryNodeValue*>(qnode->GetUserObject()));
76  if (!m_Result) {
77  NCBI_THROW(macro::CMacroExecException, eInternalError, "Error - non-initialized pointer");
78  }
79 
80  m_Args.resize(0);
83  for (; it != it_end; ++it) {
84  CRef<CQueryNodeValue> arg = Ref(dynamic_cast<CQueryNodeValue*>((*it)->GetValue().GetUserObject()));
85  if (!arg) {
86  NCBI_THROW(macro::CMacroExecException, eInternalError, "Error - non-initialized pointer");
87  }
88  m_Args.push_back(arg);
89  }
90  }
91 
92  /// Filter out java/javascript keywords that could possibly be used in
93  /// xss attacks, particularly event handler names and < and > symbols
94  static string JSFilter(const string& str);
95 
96  /// function useful mostly for functions in the WHERE clause
97  void x_AssignReturnValue(const CObjectInfo& oi, const string& field_name);
98 
101 
102  // since macros may come from client, we want to filter out javascript code
103  // that might get inserted into out tooltips (TV-525)
104  static string s_JSFilterdKeywords[];
105  static pair<string, string> s_JSSwapKeywords[];
106 
107  vector<CRef<CQueryNodeValue>> m_Args;
109 };
110 
111 ///////////////////////////////////////////////////////////////////////////////
112 /// CMacroFunction_SetColor
113 /// Takes one string parameter and uses it to sets the color for the node
114 /// to that value via the property $NODE_COLOR
115 ///
117 {
118 public:
119  CMacroFunction_SetColor(EScopeEnum func_scope, CPhyloTree* tree)
120  : ITreeMacroFunction(func_scope, tree) {}
122 
123  virtual void TheFunction();
124 
125 };
126 
127 ///////////////////////////////////////////////////////////////////////////////
128 /// CMacroFunction_SetSize
129 /// Takes one integer parameter and uses it to sets the radius for the node
130 /// to that value via the property $NODE_SIZE
131 ///
133 {
134 public:
135  CMacroFunction_SetSize(EScopeEnum func_scope, CPhyloTree* tree)
136  : ITreeMacroFunction(func_scope, tree) {}
137 
138  virtual void TheFunction();
139 };
140 
141 ///////////////////////////////////////////////////////////////////////////////
142 /// CMacroFunction_SetMarker
143 /// Takes one parameter (string) and sets that as the marker property
144 /// for the node to create a marker for the node. See 'marker' in the tutorial:
145 /// https://www.ncbi.nlm.nih.gov/tools/gbench/tutorial3/
146 /// for details.
147 ///
149 {
150 public:
151  CMacroFunction_SetMarker(EScopeEnum func_scope, CPhyloTree* tree)
152  : ITreeMacroFunction(func_scope, tree) {}
153 
154  virtual void TheFunction();
155 };
156 
157 ///////////////////////////////////////////////////////////////////////////////
158 /// CMacroFunction_SetBounding
159 /// Takes one parameter (string) and sets that as the $NODE_BOUNDED property
160 /// for the node to create a bounding area around the node and its children.
161 /// See $NODE_BOUNDED in the tutorial:
162 /// https://www.ncbi.nlm.nih.gov/tools/gbench/tutorial3/
163 /// for details.
164 ///
166 {
167 public:
168  CMacroFunction_SetBounding(EScopeEnum func_scope, CPhyloTree* tree)
169  : ITreeMacroFunction(func_scope, tree) {}
170 
171  virtual void TheFunction();
172 };
173 
174 ///////////////////////////////////////////////////////////////////////////////
175 /// CMacroFunction_SetProperty
176 /// Takes a property name (string) and property value (string) and sets or
177 /// updates the corresponding name to the specified value. Since the first
178 /// parameter name is a property name, not a property value, it should be in
179 /// quotes, e.g. SetProperty("creation_date", "10/12/2016")
180 ///
182 {
183 public:
184  CMacroFunction_SetProperty(EScopeEnum func_scope, CPhyloTree* tree)
185  : ITreeMacroFunction(func_scope, tree) {}
186 
187  virtual void TheFunction();
188 };
189 
190 ///////////////////////////////////////////////////////////////////////////////
191 /// CMacroFunction_SubtreeSum
192 /// Calculates the sum of node property (single parameter) of all the nodes that form the subtree
193 /// rooted at the specific node (including or excluding itself)
194 ///
196 {
197 public:
198  CMacroFunction_SubtreeSum(EScopeEnum func_scope, CPhyloTree* tree)
199  : ITreeMacroFunction(func_scope, tree) {}
200 
201  virtual void TheFunction();
202 };
203 
204 ///////////////////////////////////////////////////////////////////////////////
205 /// CMacroFunction_CollapseNode
206 /// Collapses the current node. This is equivalent to:
207 /// SetProperty("$NODE_COLLAPSED", 1);
208 ///
210 {
211 public:
212  CMacroFunction_CollapseNode(EScopeEnum func_scope, CPhyloTree* tree)
213  : ITreeMacroFunction(func_scope, tree) {}
214 
215  virtual void TheFunction();
216 };
217 
218 ///////////////////////////////////////////////////////////////////////////////
219 /// CMacroFunction_ExpandNode
220 /// Expands the current node. This is equivalent to:
221 /// SetProperty("$NODE_COLLAPSED", 0);
222 ///
224 {
225 public:
226  CMacroFunction_ExpandNode(EScopeEnum func_scope, CPhyloTree* tree)
227  : ITreeMacroFunction(func_scope, tree) {}
228 
229  virtual void TheFunction();
230 };
231 
232 
233 ///////////////////////////////////////////////////////////////////////////////
234 /// CMacroFunction_AddToSelectionSet
235 ///
236 ///
238 {
239 public:
241  : ITreeMacroFunction(func_scope, tree) {}
242 
243  virtual void TheFunction();
244 
245 protected:
246 
247  void x_AddSetInfo(CPhyloSelectionSet& s);
248 
249  /// Base cluster id for selection sets. Selection set and cluster-id ids
250  /// can't overlap.
252 };
253 
254 ///////////////////////////////////////////////////////////////////////////////
255 /// CMacroFunction_DeleteNode
256 /// Deletes the current node
257 ///
259 {
260 public:
261  CMacroFunction_DeleteNode(EScopeEnum func_scope, CPhyloTree* tree)
262  : ITreeMacroFunction(func_scope, tree) {}
263 
264  virtual void TheFunction();
265 };
266 
267 
268 ///////////////////////////////////////////////////////////////////////////////
269 /// CMacroFunction_IsLeaf
270 /// Returns true if child is a leaf, so you can do queries that exclude non-leaf
271 /// nodes, e.g. IsLeaf("") AND IsNull("host_disease") checks for any leaf nodes
272 /// that do not have a value (even blank) set for "host_disease"
273 ///
275 {
276 public:
277  CMacroFunction_IsLeaf(EScopeEnum func_scope, CPhyloTree* tree)
278  : ITreeMacroFunction(func_scope, tree) {}
279 
280  virtual void TheFunction();
281 };
282 
283 ///////////////////////////////////////////////////////////////////////////////
284 /// CMacroFunction_NumChildren
285 /// Returns the number of children of the current node so that you can search
286 /// for nodes based on that factor, e.g. NumChildren("") > 2
287 ///
289 {
290 public:
291  CMacroFunction_NumChildren(EScopeEnum func_scope, CPhyloTree* tree)
292  : ITreeMacroFunction(func_scope, tree) {}
293 
294  virtual void TheFunction();
295 };
296 
297 ///////////////////////////////////////////////////////////////////////////////
298 /// CMacroFunction_BranchDepth
299 /// Returns the number of branches between the current node and the root node.
300 /// 0=>Root node, 1=>immediate children of root node, etc.
301 ///
303 {
304 public:
305  CMacroFunction_BranchDepth(EScopeEnum func_scope, CPhyloTree* tree)
306  : ITreeMacroFunction(func_scope, tree) {}
307 
308  virtual void TheFunction();
309 };
310 
311 ///////////////////////////////////////////////////////////////////////////////
312 /// CMacroFunction_MaxChildBranchDepth
313 /// Returns the number of branches between the current node and its most
314 /// distant (with regards to number of edges) child.
315 /// 0=>Leaf node, 1=>node which only has leaf nodes as childrent, etc.
316 ///
318 {
319 public:
321  : ITreeMacroFunction(func_scope, tree) {}
322 
323  virtual void TheFunction();
324 };
325 
326 ///////////////////////////////////////////////////////////////////////////////
327 /// CMacroFunction_IsNull
328 /// Returns true of the passed in property is not set at all for the current
329 /// node. The name of the property being checked must be passed as a string
330 /// (in quotes), e.g. IsNull("host_disease") rather than the normal way of
331 /// passing a field value, e.g. IsNull(host_disease). The property name is
332 /// case sensitive!
333 ///
335 {
336 public:
337  CMacroFunction_IsNull(EScopeEnum func_scope, CPhyloTree* tree)
338  : ITreeMacroFunction(func_scope, tree) {}
339 
340  virtual void TheFunction();
341 };
342 
343 ///////////////////////////////////////////////////////////////////////////////
344 /// CMacroFunction_Date
345 /// Takes a date/time string as a parameter and returns it as an integer number
346 /// of seconds elapsed since midnight (00:00:00), January 1, 1970 UTC. Do not
347 /// use this function if the year is before 1970.
348 ///
349 /// This allows us to add date-based comparisons to queries, e.g.:
350 /// target_creation_date > "10/01/2015" where target_creation_date has a format
351 /// like: "2016-02-24" would use the following query:
352 /// Date(target_creation_date, "Y-M-D") > Date("10/01/2015")
353 ///
354 /// For valid date/time formats see CTimeFormat. Default format is M/D/Y h:m:s
355 /// and it's ok if trailing values are not provided, e.g. 06/04/91 is ok
356 ///
358 {
359 public:
360  CMacroFunction_Date(EScopeEnum func_scope, CPhyloTree* tree)
361  : ITreeMacroFunction(func_scope, tree) {}
362 
363  virtual void TheFunction();
364 };
365 
367 
368 
369 #endif // GUI_WIDGETS_PHYLO_TREE___PHYLO_TREE_QUERY_MACRO_FNS__HPP
CMacroFunction_AddToSelectionSet.
int m_SelectionSetClusterID
Base cluster id for selection sets.
CMacroFunction_AddToSelectionSet(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_BranchDepth Returns the number of branches between the current node and the root node.
CMacroFunction_BranchDepth(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_CollapseNode Collapses the current node.
CMacroFunction_CollapseNode(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_Date Takes a date/time string as a parameter and returns it as an integer number of se...
CMacroFunction_Date(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_DeleteNode Deletes the current node.
CMacroFunction_DeleteNode(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_ExpandNode Expands the current node.
CMacroFunction_ExpandNode(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_IsLeaf Returns true if child is a leaf, so you can do queries that exclude non-leaf no...
CMacroFunction_IsLeaf(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_IsNull Returns true of the passed in property is not set at all for the current node.
CMacroFunction_IsNull(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_MaxChildBranchDepth Returns the number of branches between the current node and its mo...
CMacroFunction_MaxChildBranchDepth(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_NumChildren Returns the number of children of the current node so that you can search ...
CMacroFunction_NumChildren(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SetBounding Takes one parameter (string) and sets that as the $NODE_BOUNDED property f...
CMacroFunction_SetBounding(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SetColor Takes one string parameter and uses it to sets the color for the node to that...
CMacroFunction_SetColor(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SetMarker Takes one parameter (string) and sets that as the marker property for the no...
CMacroFunction_SetMarker(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SetProperty Takes a property name (string) and property value (string) and sets or upd...
CMacroFunction_SetProperty(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SetSize Takes one integer parameter and uses it to sets the radius for the node to tha...
CMacroFunction_SetSize(EScopeEnum func_scope, CPhyloTree *tree)
CMacroFunction_SubtreeSum Calculates the sum of node property (single parameter) of all the nodes tha...
CMacroFunction_SubtreeSum(EScopeEnum func_scope, CPhyloTree *tree)
CObjectInfo –.
Definition: objectinfo.hpp:597
Tree subclass also has functions and data needed for rendering and selection.
Definition: phylo_tree.hpp:52
class CQueryNodeValue
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Abstract base class for any user function which can be called from either the WHERE or DO clauses.
Base class for functions which can be called from the WHERE or DO clauses of macros/queries using the...
ITreeMacroFunction(EScopeEnum func_scope, CPhyloTree *tree)
Ctor.
void x_AssignReturnValue(const CObjectInfo &oi, const string &field_name)
function useful mostly for functions in the WHERE clause
CRef< CQueryNodeValue > m_Result
static string JSFilter(const string &str)
Filter out java/javascript keywords that could possibly be used in xss attacks, particularly event ha...
static pair< string, string > s_JSSwapKeywords[]
vector< CRef< CQueryNodeValue > > m_Args
virtual void x_InitCall(CPhyloTreeNode &data)
Functions make the action and collect statistics.
virtual void x_SetUserObjects(CQueryParseTree::TNode &qnode)
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TNodeList::iterator TNodeList_I
Definition: ncbi_tree.hpp:109
TNodeList_CI SubNodeBegin(void) const
Return first const iterator on subnode list.
Definition: ncbi_tree.hpp:160
TNodeList_CI SubNodeEnd(void) const
Return last const iterator on subnode list.
Definition: ncbi_tree.hpp:166
#define NCBI_GUIWIDGETS_PHYLO_TREE_EXPORT
Definition: gui_export.h:535
Macro exceptions.
Interface class for macro function implementation.
Query parser execution implementations.
Modified on Sat May 25 14:17:00 2024 by modify_doxy.py rev. 669887