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

Go to the SVN repository for this file.

1 #ifndef GUI_OBJUTILS___MACRO_FN_BASE__HPP
2 #define GUI_OBJUTILS___MACRO_FN_BASE__HPP
3 /* $Id: macro_fn_base.hpp 47378 2023-02-27 20:09:44Z asztalos $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Anatoly Osipov, Andrea Asztalos, Robert Falk
29  *
30  * File Description: Interface class for macro function implementation
31  *
32  */
33 
34 /// @file macro_fn_base.hpp
35 /// Interface class for macro function implementation
36 
37 #include <corelib/ncbistd.hpp>
38 #include <gui/gui_export.h>
41 
42 /** @addtogroup GUI_MACRO_SCRIPTS_UTIL
43  *
44  * @{
45  */
46 
48 BEGIN_SCOPE(macro)
49 
50 //////////////////////////////////////////////////////////////////
51 /// Abstract base class for any user function which can be
52 /// called from either the WHERE or DO clauses
53 ///
54 template<typename TData>
56 {
57 public:
58  enum EScopeEnum {
60  eDo,
61  eBoth
62  };
63 
64  enum ENestedFunc {
66  eNested
67  };
68 
69  /// Constructor
71  : m_FuncScope (func_scope)
72  , m_Nested(eNotNested) {}
73 
74  /// Virtual destructor
75  virtual ~IMacroFunction() {};
76 
77  /// Function implementation
78  virtual void TheFunction() = 0;
79 
80  /// Function operator
81  virtual void operator()(CMacroCmdComposite& cmd_composite,
82  TData& data,
84  {
85  m_CmdComposite = Ref(&cmd_composite);
86  m_Report.resize(0);
87  m_Error.resize(0);
88 
89  x_SetUserObjects(qnode);
91 
92  TheFunction();
93  }
94 
97 
98  /// Function extracts statistic from the object
99  const string& GetFuncReport() const { return m_Report; }
100  const string& GetErrorReport() const { return m_Error; }
101 
103 
104 private:
106 
107 protected:
108  virtual void x_InitCall(TData& data) = 0;
109 
110  virtual void x_SetUserObjects(CQueryParseTree::TNode& qnode) = 0;
111 
113  {
114  if (!IsOssEmpty(logstr)) {
115  logstr << "\n";
116  m_Report.assign(CNcbiOstrstreamToString(logstr));
117  }
118  }
119 
121  {
122  if (!IsOssEmpty(logstr)) {
123  logstr << "\n";
124  m_Error.assign(CNcbiOstrstreamToString(logstr));
125  }
126  }
127 
129 
130  /// function activity report
131  string m_Report;
132  /// error report
133  string m_Error;
134  /// flag indicating whether the function is nested within another function
136 };
137 
138 
139 END_SCOPE(macro)
141 
142 /* @} */
143 
144 #endif // GUI_OBJUTILS___MACRO_FN_BASE__HPP
implements special composite command, which does not call to its internal commands when run the very ...
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
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.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static int type
Definition: getdata.c:31
char data[12]
Definition: iconv.c:80
virtual void TheFunction()=0
Function implementation.
string m_Error
error report
string m_Report
function activity report
EScopeEnum GetFuncScope()
EScopeEnum m_FuncScope
ENestedFunc m_Nested
flag indicating whether the function is nested within another function
CRef< CMacroCmdComposite > m_CmdComposite
ENestedFunc GetNestedState()
const string & GetErrorReport() const
IMacroFunction(EScopeEnum func_scope)
Constructor.
virtual void x_SetUserObjects(CQueryParseTree::TNode &qnode)=0
void x_LogError(CNcbiOstrstream &logstr)
void SetNestedState(ENestedFunc type)
const string & GetFuncReport() const
Function extracts statistic from the object.
virtual void x_InitCall(TData &data)=0
void x_LogFunction(CNcbiOstrstream &logstr)
virtual ~IMacroFunction()
Virtual destructor.
virtual void operator()(CMacroCmdComposite &cmd_composite, TData &data, CQueryParseTree::TNode &qnode)
Function operator.
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 END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
bool IsOssEmpty(CNcbiOstrstream &oss)
Definition: ncbistre.hpp:831
Defines to provide correct exporting from DLLs in Windows.
Query string parsing components.
Definition: type.c:6
Modified on Wed May 22 11:27:41 2024 by modify_doxy.py rev. 669887