NCBI C++ ToolKit
macro_engine.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: macro_engine.cpp 47411 2023-03-20 19:18:06Z asztalos $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Anatoly Osipov, Dmitry Rudnev, Andrea Asztalos
27  *
28  * File Description: Macro engine for macro processing
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
49 
50 #include <util/line_reader.hpp>
51 
52 #undef _TRACE
53 #define _TRACE(arg) ((void)0)
54 
55 /** @addtogroup GUI_MACRO_SCRIPTS_UTIL
56  *
57  * @{
58  */
59 
61 BEGIN_SCOPE(macro)
63 
64 ///////////////////////////////////////////////////////////////////////////////
65 /// class CMacroEngine
66 ///
67 
70 
71  for (; it != m_BuiltInFunctions.end(); ++it)
72  delete it->second;
73 }
74 
75 bool CMacroEngine::AppendToLibrary(const string& filename, CMacroLib::TMacroLibrary& lib)
76 {
77  // library is not cleared
78  return x_AppendToLibrary(filename, lib);
79 }
80 
82 {
83  return m_MacroRep->GetAssignmentWhereClause( index );
84 }
85 
86 bool CMacroEngine::ReadAndParseMacros(const string& filename, vector<CRef<CMacroRep>>& macro_list)
87 {
88  x_ResetStatus();
89 
90  string filetext;
91  try {
92  CRef<ILineReader> line_reader(ILineReader::New(filename));
93  while (!line_reader->AtEOF()) {
94  line_reader->ReadLine();
95  filetext += line_reader->GetCurrentLine();
96  filetext += "\n";
97  }
98  }
99  catch (const CException& ex) {
100  ERR_POST(ex.ReportAll());
101  x_SetError(string("Problem with reading file:") + filename);
102  return m_Status;
103  }
104 
105  CMacroParser parser;
106  macro_list.resize(0);
107  try {
108  x_SetFunctions(parser);
109  parser.SetSource(filetext.c_str());
110  while (parser.Parse(false)) {
111  CRef<CMacroRep> mr(parser.DetachMacroRep());
112  macro_list.push_back(mr);
113  }
114 
115  m_Status = true;
116  }
117  catch (const CMacroParseException& ex) {
118  m_Status = false;
119 
120  // if there is an error, none of the macros will be read
121  macro_list.resize(0);
122 
123  m_ErrorMessage = ex.GetMsg();
124  if (!m_ErrorMessage.empty()) {
125  //m_Line = parser.GetErrorLocation().m_Line;
126  //m_Column = parser.GetErrorLocation().m_Column;
127  }
128  else
129  m_ErrorMessage = ex.what();
130  return m_Status;
131  }
132 
133  return m_Status;
134 }
135 
136 namespace {
137 
138  class CSynFileReader
139  {
140  public:
141  CSynFileReader(vector<string>& syn_fnames, const CMacroRep& macro_rep, const CMacroEngine* engine)
142  : m_SynFiles(&syn_fnames), m_MacroRep(ConstRef(&macro_rep)), m_Engine(engine) {}
143 
144  ETreeTraverseCode operator()(const CTreeNode<CQueryParseNode>& node, int delta)
145  {
146  m_Level += delta;
147  if (delta < 0)
148  return eTreeTraverse;
149 
150  const CQueryParseNode& qnode = node.GetValue();
151  if (qnode.GetType() == CQueryParseNode::eFunction &&
153  auto subnode = node.SubNodeBegin();
154  auto endnode = node.SubNodeEnd();
155 
156  bool found = false;
157  bool found_boolargs = false;
158  short index = 0;
159  while (subnode != endnode && !found) {
160  ++index;
161  auto arg = (*subnode)->GetValue();
163  m_MacroRep->GetNodeValue(arg.GetStrValue(), value);
164 
165  if (value.IsString() || (value.IsNotSet() && arg.GetType() == CQueryParseNode::eString)) {
166  string tmp;
167  if (arg.GetType() == CQueryParseNode::eString) {
168  tmp = arg.GetStrValue();
169  }
170  else if (value.IsString()) {
171  tmp = value.GetString();
172  }
173 
175  m_SynFiles->push_back(tmp);
176  found = true;
177  }
179  m_SynFiles->push_back(tmp);
180  found = true;
181  }
182  }
183  else if (value.IsBool()) {
184  found_boolargs = true;
185  }
186  ++subnode;
187  }
188  return eTreeTraverseStepOver;
189  }
190  return eTreeTraverse;
191  }
192  private:
193  vector<string>* m_SynFiles{ nullptr };
194  int m_Level{ 0 };
195  CConstRef<CMacroRep> m_MacroRep{ nullptr };
196  const CMacroEngine* m_Engine{ nullptr };
197  };
198 
199  void SearchForSynonymFile(const CQueryParseTree& tree, const CMacroRep& macro_rep, vector<string>& fnames, const CMacroEngine* engine)
200  {
201  const CQueryParseTree::TNode* root = tree.GetQueryTree();
202  CQueryParseTree::TNode& nc_root = const_cast<CQueryParseTree::TNode&>(*root);
203 
204  CSynFileReader fnc(fnames, macro_rep, engine);
205  TreeDepthFirstTraverse(nc_root, fnc);
206  }
207 }
208 
209 vector<string> CMacroEngine::GetSynonymFilenames(const vector<CRef<CMacroRep>>& macro_list) const
210 {
211  set<string> syn_files;
212  unsigned count = 0;
213  bool has_synonym = false;
214  bool found = false;
215  for (const auto& macro_it : macro_list) {
216  has_synonym = false;
217  found = false;
218  if (NStr::FindNoCase(macro_it->GetSource(), "synonyms.txt") != NPOS) {
219  has_synonym = true;
220  }
221 
222  auto where_tree = macro_it->GetWhereClause();
223  if (where_tree) {
224  vector<string> fnames;
225  SearchForSynonymFile(*where_tree, *macro_it, fnames, this);
226  for (const auto& f_it : fnames) {
227  syn_files.insert(f_it);
228  count++;
229  found = true;
230  }
231  }
232 
233  auto do_where_trees = macro_it->GetAssignmentWhereClauses();
234  for (const auto& wh_it : do_where_trees) {
235  vector<string> fnames;
236  SearchForSynonymFile(*wh_it, *macro_it, fnames, this);
237  for (const auto& f_it : fnames) {
238  syn_files.insert(f_it);
239  count++;
240  found = true;
241  }
242  }
243 
244  if (!found && has_synonym) {
245  LOG_POST(Info << "Synonym file not found for:\n" << macro_it->GetSource());
246  }
247  }
248  LOG_POST(Info << "Found " << count << " instances of word substitution files");
249  vector<string> file_names(syn_files.begin(), syn_files.end());
250  return file_names;
251 }
252 
254 {
255  x_ResetStatus();
256 
257  string filetext;
258  try {
259  CRef<ILineReader> line_reader(ILineReader::New(filename));
260  while (!line_reader->AtEOF()) {
261  line_reader->ReadLine();
262  filetext += line_reader->GetCurrentLine();
263  filetext += "\n";
264  }
265  }
266  catch (const CException& ex) {
267  ERR_POST(ex.ReportAll());
268  x_SetError(string("Problem with reading file:") + filename);
269  return m_Status;
270  }
271 
272  CMacroParser parser;
273  vector<CRef<CMacroRep>> parsed_vec;
274  try {
275  x_SetFunctions(parser);
276  parser.SetSource(filetext.c_str());
277 
278  while (parser.Parse(false)) {
279  CRef<CMacroRep> mr(parser.DetachMacroRep());
280  parsed_vec.push_back(mr);
281  }
282  m_Status = true;
283  }
284  catch (const CMacroParseException& ex) {
285  m_Status = false;
286  m_ErrorMessage = ex.GetMsg();
287  if (!m_ErrorMessage.empty()) {
288  //m_Line = parser.GetErrorLocation().m_Line;
289  //m_Column = parser.GetErrorLocation().m_Column;
290  }
291  else
292  m_ErrorMessage = ex.what();
293  return m_Status;
294  }
295 
296  if (m_Status) {
297  // save the macro in the library only when all steps have been successfully parsed
298  lib.reserve(lib.size() + parsed_vec.size());
299  lib.insert(lib.end(), parsed_vec.begin(), parsed_vec.end());
300  }
301 
302  return m_Status;
303 }
304 
305 void CMacroEngine::x_SetError(const string& message, Uint4 line, Uint4 column)
306 {
307  m_ErrorMessage = message;
308  m_Line = line;
309  m_Column = column;
310 
311  m_Status = false;
312 }
313 
315 {
316  m_Status = true;
317  m_ErrorMessage.resize(0);
318  m_Line = m_Column = 0;
319 
320  m_MacroStat.Reset();
321  // clearing the run time variables takes place in Exec() member
322 }
323 
324 CMacroRep* CMacroEngine::Parse(const string& macro_text)
325 {
326  x_ResetStatus();
327 
328  if (macro_text.empty()) {
329  m_Status = false;
330  m_ErrorMessage = "The macro is empty.";
331  return nullptr;
332  }
333 
334  CMacroParser parser;
335  try {
336  x_SetFunctions(parser);
337  parser.SetSource(macro_text.c_str());
338  parser.Parse();
339  return parser.DetachMacroRep();
340  }
341  catch (const CMacroParseException& ex) {
342  m_Status = false;
343  m_ErrorMessage = ex.GetMsg(); // this contains the error location
344  if (m_ErrorMessage.empty()) {
345  m_ErrorMessage = ex.what();
346  }
347  }
348 
349  return nullptr;
350 }
351 
352 bool CMacroEngine::Exec(const CMacroRep& macro_rep, const CMacroBioData& data, CRef<CMacroCmdComposite> CmdComposite, bool throw_on_error, CNcbiOstream* ostream)
353 {
354 /*
355 #ifdef _DEBUG
356  macro_rep.Print(NcbiCout);
357 #endif
358 */
359  x_ResetStatus();
360  m_MacroStat.LogStart(macro_rep.GetName());
361 
362  m_RTVars.clear();
364  m_MacroRep = &macro_rep;
365 
366  m_CmdComposite.Reset(CmdComposite);
367 
368  m_DataIter.Reset(data.CreateIterator(
372  ostream));
373 
374  m_DataIter->SetHugeDataMode(m_HugeFileMode);
375  if (m_HugeFileMode) {
376  m_DataIter->SetHugeContext(m_MacroContext);
377  }
378  m_DataIter->RemoteUpdater() = m_RemoteUpdater;
379  m_DataIter->DOIUpdater() = m_DOIUpdater;
380  m_DataIter->ISOJTAUpdater() = m_ISOJTAUpdater;
381 
382  if (!m_DataIter) {
383  m_Status = false;
384  m_ErrorMessage = "Missing FOR EACH statement or incorrect selector specified or incorrect NA provided";
385  m_Line = 0; // TBD: implement error location
386  m_Column = 0; // TBD: implement error location
387  if (throw_on_error) {
388  string msg;
389  if (m_MacroRep->GetNamedAnnot().empty()) {
390  msg = "Missing FOR EACH statement, or unsupported selector";
391  }
392  else {
393  msg = "Incorrect NA provided or missing FOR EACH statement or unsupported selector specified";
394  }
396  }
397  return m_Status;
398  }
399 
400  CMacroExec macro_exec;
401  try {
402  m_DataIter->Begin();
403 // m_MacroStat.AddToReport("Processing features count: " + NStr::NumericToString(m_DataIter->GetCount()) + "\n");
404 // m_MacroStat.AddToReport("Best description: " + m_DataIter->GetBestDescr() + "\n");
405  while (!m_DataIter->IsEnd()) {
406  m_EvalDo = true;
407 
409  if (tree) {
410  m_EvalDo = false;
411 
412  macro_exec.EvaluateTree(*tree, *this, true);
413  if (!macro_exec.IsBoolType() && !macro_exec.IsNotSetType())
415  "Wrong type of computed WHERE clause", tree->GetQueryTree());
416 
417  if (macro_exec.IsBoolType() && macro_exec.GetBoolValue()) {
418  m_EvalDo = true;
419  } else {
420  m_DataIter->Next();
421  }
422  }
423 
424  if (m_EvalDo) {
426  _ASSERT(tree);
427  m_DataIter->BuildEditedObject();
428  // make all the necessary changes to the asn selector object and
429  // execute commands on the dependent objects
430  macro_exec.EvaluateTree(*tree, *this, false);
431 
432  if (m_DataIter->IntendToDelete()) {
433  m_DataIter->RunDeleteCommand(m_CmdComposite);
434  }
435  else {
436  if (m_DataIter->IsModified()) {
437  m_DataIter->RunEditCommand(m_CmdComposite);
438  }
439  m_DataIter->Next();
440  }
441  }
442  }
443  m_Status = true;
444 
445  int nr_nonmatched = 0;
446  const string msg = m_DataIter->GetUnMatchedTableEntries(nr_nonmatched);
447  m_MacroStat.GatherUnMatchedTableEntries(msg, nr_nonmatched);
448  }
449  catch (const CMacroExecException& ex) {
450  m_Status = false;
451 
452  m_Line = ex.GetLineNo();
453  m_Column = ex.GetColumnNo();
454  m_ErrorMessage = ex.GetMsg();
455  if (m_ErrorMessage.empty()) {
456  m_ErrorMessage = ex.what();
457  }
458 
459  CNcbiOstrstream oss;
460  oss << "[Error] Line " << m_Line << ", Pos " << m_Column;
461  oss << ": " << m_ErrorMessage;
463 
464  if (throw_on_error)
465  throw;
466  }
467 /*
468 #ifdef _DEBUG
469  m_MacroStat.LogStop(m_Status, m_ErrorMessage);
470 #endif
471 */
472  return m_Status;
473 }
474 
475 bool CMacroEngine::ResolveIdentifier(const string& identifier, CMQueryNodeValue& v, const CQueryParseTree::TNode* parent)
476 {
477  _TRACE("<<<<");
478  _TRACE("Resolving identifier: " << identifier);
479  bool res = false;
480 
481  _TRACE("Trying to get it as node value (IMacroVar) from m_MacroRep: " << m_MacroRep);
482  if (!res && m_MacroRep) {
483  res = m_MacroRep->GetNodeValue(identifier, v);
484  }
485 
486  if (!res) {
487  _TRACE("Trying to get it as an RT Var");
488  res = x_ResolveRTVar(identifier, v, parent);
489  } else
490  _TRACE("Successfully resolved as node value");
491 
492  if (!res) {
493  // resolving variables like WHERE biomol = "peptide", example Autofix_008
494  _TRACE("Trying to get it via ResolveIdentToSimple() from m_DataIter: " << m_DataIter);
495  if(m_DataIter) {
496  CObjectInfo obj = m_DataIter->GetEditedObject();
497  res = ResolveIdentToSimple(obj, identifier, v);
498  }
499  if(res)
500  _TRACE("Successfully resolved via ResolveIdentToSimple() from m_DataIter");
501  }
502 
503  if (!res) {
504  _TRACE("All attempts to resolve failed");
506  }
507 
508  _TRACE("Identifier resolved successfully: " << res);
509  _TRACE(">>>>");
510  return res;
511 }
512 
514 {
515  IEditMacroFunction* func = 0;
516 
517  auto it(m_BuiltInFunctions.find(name));
518  if ( it != m_BuiltInFunctions.end() )
519  func = it->second;
520 
521  return func;
522 }
523 
524 void CMacroEngine::CallFunction(const string& name, CQueryParseTree::TNode& qnode)
525 {
527  if (!func)
529  "Function '" + name + "' not implemented", &qnode);
530 
531  auto func_scope = func->GetFuncScope();
532  if ((m_EvalDo && func_scope == IEditMacroFunction::eWhere) ||
533  (!m_EvalDo && func_scope == IEditMacroFunction::eDo))
535  "Function '" + name + "' used in the wrong DO/WHERE clause scope", &qnode);
536 
539 
540  const CQueryParseTree::TNode* parent = qnode.GetParent();
541  if (parent
542  && (parent->GetValue().GetType() == CQueryParseNode::eFunction // used in the Where clause
543  || parent->GetValue().GetType() == CQueryParseNode::eFrom)) { // used in the rhs of the assignment operator
545  } else {
547  }
548 
549  try {
550  (*func)(m_CmdComposite.GetNCObject(), m_DataIter, qnode);
551  }
552  catch (const CMacroDataException &err) {
553  string message("Function ");
554  message += name;
555  message += " failed";
557  }
558  catch (CMacroExecException &error) {
559  // Set the macro position information
560  const CQueryParseNode::SSrcLoc &loc = qnode.GetValue().GetLoc();
561  // SSrcLoc positions are 0 based
562  error.SetLineNo(loc.line + 1);
563  error.SetColumnNo(loc.pos + 1);
564  throw;
565  }
566  catch (const CException& e) {
567  LOG_POST(Info << "Error in calling function " << name << ": " << e.GetMsg());
569  }
570  catch (const std::exception& e) {
571  LOG_POST(Info << "Error in calling function " << name << ": " << e.what());
573  }
574 
575  // log the activities of this function
578  if (func->GetFuncScope() == IEditMacroFunction::eDo) {
582  }
583 }
584 
586 {
587  CMacroParser::TFunctionNamesList where_funcs, do_funcs;
588 
589  for (auto& iter : m_BuiltInFunctions) {
590  string name = iter.first;
591  IEditMacroFunction* func = iter.second;
592  if ( func ) {
593  switch (func->GetFuncScope()) {
595  do_funcs.push_back(name);
596  break;
598  where_funcs.push_back(name);
599  break;
601  do_funcs.push_back(name);
602  where_funcs.push_back(name);
603  break;
604  default:
605  ; // unknown case
606  }
607  }
608  }
609 
610  parser.SetFunctionNames(where_funcs, do_funcs);
611 }
612 
614 {
615  _TRACE("<<<<");
616  _TRACE("Looking for: " << name);
617  if ( name.empty() )
618  return CRef<CMQueryNodeValue>();
619 
620  auto rt_var = x_LocateRTVar( name );
621  if ( rt_var ) {
622  _TRACE("found!");
623  _TRACE(">>>>");
624  return rt_var;
625  }
626 
628  m_RTVars[name] = node;
629  _TRACE("created as node: " << node.GetPointerOrNull());
630  _TRACE(">>>>");
631  return node;
632 }
633 
634 bool CMacroEngine::ExistRTVar(const string& name)
635 {
636  _TRACE("<<<<");
637  _TRACE("Looking for (whether it exists) :" << name);
638  auto it = m_RTVars.find(name);
639  if (it != m_RTVars.end()) {
640  _TRACE("found!");
641  return true;
642  }
643 
644  _TRACE("not found!");
645  return false;
646 }
647 
649 {
650  _TRACE("<<<<");
651  _TRACE("Looking for: " << name);
652 /*
653 #ifdef _DEBUG
654  _TRACE("Current m_RTVars snapshot:");
655  ITERATE(TRTVarsMap, iRTVars, m_RTVars) {
656  _TRACE(iRTVars->first);
657  }
658 #endif
659 */
660  auto it = m_RTVars.find(name);
661  if (it != m_RTVars.end()) {
662  _TRACE("found!");
663  _TRACE(">>>>");
664  return (*it).second;
665  } else {
666  _TRACE("not found!");
667  _TRACE(">>>>");
668  return CRef<CMQueryNodeValue>();
669  }
670 }
671 
672 bool CMacroEngine::x_ResolveRTVar(const string& identifier, CMQueryNodeValue& v, const CQueryParseTree::TNode* parent)
673 {
674  _TRACE("<<<<");
675  _TRACE("Looking for: " << identifier);
676  bool isOK(false);
677 
678  // check for a "." inside the RTVar name --
679  // it may mean that a field of the var is required
680  string sRTVarRoot, sRTVarFields;
681  NStr::SplitInTwo(identifier, ".", sRTVarRoot, sRTVarFields);
682  CRef<CMQueryNodeValue> rt_var = x_LocateRTVar(sRTVarRoot);
683 
684  if ( rt_var ) {
685  CObjectInfo tmpObj;
686  if(!GetTmpRTVarObject(sRTVarRoot, tmpObj)) {
687  _TRACE("datatype of rt_var: " << rt_var->GetDataType());
688  if (NStr::IsBlank(sRTVarFields)) { // EditStringQual(o, find_text, ...) where o = Resolve("org.taxname");
689  v.SetRef( rt_var );
690  _TRACE("set reference from node: " << rt_var << " to node: " << &v);
691  isOK = true;
692  } else { // EditStringQual("o.taxname", find_text, ...), where o = Resolve("org");
693  if (rt_var->GetDataType() == CMQueryNodeValue::eObjects) {
694  const CMQueryNodeValue::TObs& objs = rt_var->GetObjects();
695  if (!objs.empty()) {
696  ITERATE (CMQueryNodeValue::TObs, obj_it, objs) {
697  isOK |= ResolveIdentToObjects(obj_it->field, sRTVarFields, v);
698  }
699  _TRACE("resolved subfields of run-time vars");
700  } else { // if there are no resolved objects
701  v.SetRef( rt_var );
702  _TRACE("set reference from node: " << rt_var << " to node: " << &v);
703  isOK = true;
704  }
705  } else if (rt_var->GetDataType() == CMQueryNodeValue::eNotSet) { // when the run-time variable is not set
706  v.SetRef(rt_var);
707  _TRACE("set reference from node: " << rt_var << " to node: " << &v);
708  isOK = true;
709  }
710  }
711  } else if (m_DataIter){ // used in the WHERE clause
712  if (parent && parent->GetValue().GetType() == CQueryParseNode::eFunction) { // EQUALS(o, match_text)
713  isOK = ResolveIdentToObjects(tmpObj, sRTVarFields, v);
714  _TRACE("got value using iterator in form of objects (from tmpObj)");
715  } else { // o.subtype (= "isolate")
716  isOK = GetSimpleTypeValue(tmpObj, sRTVarFields, v);
717  _TRACE("got simple value using iterator");
718  }
719  }
720  _TRACE(">>>> " << isOK);
721  return isOK;
722  }
723  _TRACE("RT Var not found");
724  _TRACE(">>>> false");
725  return false;
726 }
727 
728 void CMacroEngine::AddTmpRTVarObject(const string& name, CObjectInfo& oi)
729 {
730  m_TempRTVars[name] = oi;
731 }
732 
733 bool CMacroEngine::GetTmpRTVarObject(const string& name, CObjectInfo& oi)
734 {
735  auto it = m_TempRTVars.find(name);
736  if (it != m_TempRTVars.end()) {
737  _TRACE("found!");
738  _TRACE(">>>> true");
739  oi = it->second;
740  return true;
741  } else {
742  _TRACE("not found!");
743  _TRACE(">>>> false");
744  return false;
745  }
746 }
747 
749 {
751 }
752 
753 ///////////////////////////////////////////////////////////////////////////////
754 /// Setting up the functions
755 ///
757 {
758  // Regarding Function Names: where clause function names have to be in uppercase! (limitation of qparse lib)
768  m_BuiltInFunctions.emplace(CMacroFunction_SwapRelatedFeaturesQual_Depr::GetFuncName(), new CMacroFunction_SwapRelatedFeaturesQual_Depr(IEditMacroFunction::eDo));
775  m_BuiltInFunctions.emplace(CMacroFunction_ParseToDBLink::GetFuncName(), new CMacroFunction_ParseToDBLink(IEditMacroFunction::eDo));
778  m_BuiltInFunctions.emplace(CMacroFunction_AddUnverified::GetFuncName(), new CMacroFunction_AddUnverified(IEditMacroFunction::eDo));
779 
781  m_BuiltInFunctions.emplace("AECRParseStringQual", new CMacroFunction_AddParsedText(IEditMacroFunction::eDo)); //deprecated
788  m_BuiltInFunctions.emplace(CMacroFunction_Resolve::GetFuncName(), new CMacroFunction_Resolve(IEditMacroFunction::eDo));
789  m_BuiltInFunctions.emplace(CMacroFunction_ResolveBioSourceQuals::GetFuncName(), new CMacroFunction_ResolveBioSourceQuals(IEditMacroFunction::eDo));
790  m_BuiltInFunctions.emplace(CMacroFunction_ResolveNASeq::GetFuncName(), new CMacroFunction_ResolveNASeq(IEditMacroFunction::eDo));
791  m_BuiltInFunctions.emplace(CMacroFunction_LocalID::GetFuncName(), new CMacroFunction_LocalID(IEditMacroFunction::eDo));
793  m_BuiltInFunctions.emplace(CMacroFunction_SetRnaProduct::GetFuncName(), new CMacroFunction_SetRnaProduct(IEditMacroFunction::eDo));
794  m_BuiltInFunctions.emplace(CMacroFunction_RemoveRnaProduct::GetFuncName(), new CMacroFunction_RemoveRnaProduct(IEditMacroFunction::eDo));
795  m_BuiltInFunctions.emplace(CMacroFunction_TrimStringQual::GetFuncName(), new CMacroFunction_TrimStringQual(IEditMacroFunction::eDo));
797  m_BuiltInFunctions.emplace(CMacroFunction_SetStructCommField::GetFuncName(), new CMacroFunction_SetStructCommField(IEditMacroFunction::eDo));
801  m_BuiltInFunctions.emplace(CMacroFunction_RmvRelFeatQual::GetFuncName(), new CMacroFunction_RmvRelFeatQual(IEditMacroFunction::eDo));
802  m_BuiltInFunctions.emplace(CMacroFunction_SetAutodefOption::GetFuncName(), new CMacroFunction_SetAutodefOption(IEditMacroFunction::eDo));
803 
804  m_BuiltInFunctions.emplace(CMacroFunction_FixSourceQualCaps::GetFuncName(), new CMacroFunction_FixSourceQualCaps(IEditMacroFunction::eDo));
807  m_BuiltInFunctions.emplace(CMacroFunction_FixMouseStrain::GetFuncName(), new CMacroFunction_FixMouseStrain(IEditMacroFunction::eDo));
808  m_BuiltInFunctions.emplace(CMacroFunction_EditSubfield::GetFuncName(), new CMacroFunction_EditSubfield(IEditMacroFunction::eDo));
809  m_BuiltInFunctions.emplace(CMacroFunction_RemoveSubfield::GetFuncName(), new CMacroFunction_RemoveSubfield(IEditMacroFunction::eDo));
810 
811  m_BuiltInFunctions.emplace(CMacroFunction_RemoveDescriptor::GetFuncName(), new CMacroFunction_RemoveDescriptor(IEditMacroFunction::eDo));
812  m_BuiltInFunctions.emplace(CMacroFunction_RemoveSequence::GetFuncName(), new CMacroFunction_RemoveSequence(IEditMacroFunction::eDo));
813  m_BuiltInFunctions.emplace(CMacroFunction_RemoveAlignment::GetFuncName(), new CMacroFunction_RemoveAlignment(IEditMacroFunction::eDo));
814  m_BuiltInFunctions.emplace(CMacroFunction_UnculturedTaxLookup::GetFuncName(), new CMacroFunction_UnculturedTaxLookup(IEditMacroFunction::eDo));
815  m_BuiltInFunctions.emplace(CMacroFunction_CulturedTaxLookup::GetFuncName(), new CMacroFunction_CulturedTaxLookup(IEditMacroFunction::eDo));
816  m_BuiltInFunctions.emplace(CMacroFunction_CorrectGeneticCodes::GetFuncName(), new CMacroFunction_CorrectGeneticCodes(IEditMacroFunction::eDo));
817 
818  m_BuiltInFunctions.emplace(CMacroFunction_RemoveModifier::GetFuncName(), new CMacroFunction_RemoveModifier(IEditMacroFunction::eDo));
821  m_BuiltInFunctions.emplace(CMacroFunction_FixUSAandStatesAbbrev::GetFuncName(), new CMacroFunction_FixUSAandStatesAbbrev(IEditMacroFunction::eDo));
823  m_BuiltInFunctions.emplace(CMacroFunction_RemoveLineageSourceNotes::GetFuncName(), new CMacroFunction_RemoveLineageSourceNotes(IEditMacroFunction::eDo));
824 
825  m_BuiltInFunctions.emplace(CMacroFunction_ChangeSeqInst::GetFuncName(), new CMacroFunction_ChangeSeqInst(IEditMacroFunction::eDo));
826 
827  m_BuiltInFunctions.emplace(CMacroFunction_FixAuthorCaps::GetFuncName(), new CMacroFunction_FixAuthorCaps(IEditMacroFunction::eDo));
833 
835  m_BuiltInFunctions.emplace(CMacroFunction_RmvDuplStructComments::GetFuncName(), new CMacroFunction_RmvDuplStructComments(IEditMacroFunction::eDo));
836  m_BuiltInFunctions.emplace(CMacroFunction_ReorderStructComment::GetFuncName(), new CMacroFunction_ReorderStructComment(IEditMacroFunction::eDo));
838  m_BuiltInFunctions.emplace(CMacroFunction_AddProteinTitles::GetFuncName(), new CMacroFunction_AddProteinTitles(IEditMacroFunction::eDo));
839  m_BuiltInFunctions.emplace(CMacroFunction_SetCodonsRecognized::GetFuncName(), new CMacroFunction_SetCodonsRecognized(IEditMacroFunction::eDo));
841  m_BuiltInFunctions.emplace(CMacroFunction_ToUnknownLengthGap::GetFuncName(), new CMacroFunction_ToUnknownLengthGap(IEditMacroFunction::eDo));
842 
845  m_BuiltInFunctions.emplace(CMacroFunction_DOILookup::GetFuncName(), new CMacroFunction_DOILookup(IEditMacroFunction::eDo));
846  m_BuiltInFunctions.emplace(CMacroFunction_GlobalDOILookup::GetFuncName(), new CMacroFunction_GlobalDOILookup(IEditMacroFunction::eDo));
847  m_BuiltInFunctions.emplace(CMacroFunction_ApplyPmidToEntry::GetFuncName(), new CMacroFunction_ApplyPmidToEntry(IEditMacroFunction::eDo));
848  m_BuiltInFunctions.emplace(CMacroFunction_ApplyDOIToEntry::GetFuncName(), new CMacroFunction_ApplyDOIToEntry(IEditMacroFunction::eDo));
853 
854  m_BuiltInFunctions.emplace(CMacroFunction_AddGeneXref::GetFuncName(), new CMacroFunction_AddGeneXref(IEditMacroFunction::eDo));
856  m_BuiltInFunctions.emplace(CMacroFunction_JoinShorttRNAs::GetFuncName(), new CMacroFunction_JoinShorttRNAs(IEditMacroFunction::eDo));
857  m_BuiltInFunctions.emplace(CMacroFunction_TrimStopFromCompleteCDS::GetFuncName(), new CMacroFunction_TrimStopFromCompleteCDS(IEditMacroFunction::eDo));
858  m_BuiltInFunctions.emplace(CMacroFunction_SynchronizeCDSPartials::GetFuncName(), new CMacroFunction_SynchronizeCDSPartials(IEditMacroFunction::eDo));
859  m_BuiltInFunctions.emplace(CMacroFunction_AdjustConsensusSpliceSites::GetFuncName(), new CMacroFunction_AdjustConsensusSpliceSites(IEditMacroFunction::eDo));
860  m_BuiltInFunctions.emplace(CMacroFunction_RetranslateCDS::GetFuncName(), new CMacroFunction_RetranslateCDS(IEditMacroFunction::eDo));
865  m_BuiltInFunctions.emplace(CMacroFunction_RestoreRNAEditing::GetFuncName(), new CMacroFunction_RestoreRNAEditing(IEditMacroFunction::eDo));
866 
868  m_BuiltInFunctions.emplace(CMacroFunction_RemoveInvalidECNumbers::GetFuncName(), new CMacroFunction_RemoveInvalidECNumbers(IEditMacroFunction::eDo));
869  m_BuiltInFunctions.emplace(CMacroFunction_UpdateReplacedECNumbers::GetFuncName(), new CMacroFunction_UpdateReplacedECNumbers(IEditMacroFunction::eDo));
870  m_BuiltInFunctions.emplace(CMacroFunction_UpdatemRNAProduct::GetFuncName(), new CMacroFunction_UpdatemRNAProduct(IEditMacroFunction::eDo));
871  m_BuiltInFunctions.emplace(CMacroFunction_CopyNameToCDSNote::GetFuncName(), new CMacroFunction_CopyNameToCDSNote(IEditMacroFunction::eDo));
872  m_BuiltInFunctions.emplace(CMacroFunction_RemoveFeature::GetFuncName(), new CMacroFunction_RemoveFeature(IEditMacroFunction::eDo));
874  m_BuiltInFunctions.emplace(CMacroFunction_RemoveDuplFeatures::GetFuncName(), new CMacroFunction_RemoveDuplFeatures(IEditMacroFunction::eDo));
875 
880 
884  m_BuiltInFunctions.emplace(CMacroFunction_DiscrepancyAutofix::GetFuncName(), new CMacroFunction_DiscrepancyAutofix(IEditMacroFunction::eDo));
885  m_BuiltInFunctions.emplace(CMacroFunction_TaxLookup::GetFuncName(), new CMacroFunction_TaxLookup(IEditMacroFunction::eDo));
887  m_BuiltInFunctions.emplace(CMacroFunction_ConvertRawToDeltabyNs::GetFuncName(), new CMacroFunction_ConvertRawToDeltabyNs(IEditMacroFunction::eDo));
888  m_BuiltInFunctions.emplace(CMacroFunction_AddGapFeaturesByNs::GetFuncName(), new CMacroFunction_AddGapFeaturesByNs(IEditMacroFunction::eDo));
890 
901 
909 
913 
923  m_BuiltInFunctions.emplace(CMacroFunction_SetPubCitation::GetFuncName(), new CMacroFunction_SetPubCitation(IEditMacroFunction::eDo));
924  m_BuiltInFunctions.emplace(CMacroFunction_SetSerialNumber::GetFuncName(), new CMacroFunction_SetSerialNumber(IEditMacroFunction::eDo));
928  m_BuiltInFunctions.emplace(CMacroFunction_SetPubPMID::GetFuncName(), new CMacroFunction_SetPubPMID(IEditMacroFunction::eDo));
929  m_BuiltInFunctions.emplace(CMacroFunction_SetPubAuthorMI::GetFuncName(), new CMacroFunction_SetPubAuthorMI(IEditMacroFunction::eDo));
930  m_BuiltInFunctions.emplace(CMacroFunction_RemovePubAuthorMI::GetFuncName(), new CMacroFunction_RemovePubAuthorMI(IEditMacroFunction::eDo));
931  m_BuiltInFunctions.emplace(CMacroFunction_RemovePubAuthors::GetFuncName(), new CMacroFunction_RemovePubAuthors(IEditMacroFunction::eDo));
932  m_BuiltInFunctions.emplace(CMacroFunction_ValueFromTable::GetFuncName(), new CMacroFunction_ValueFromTable(IEditMacroFunction::eDo));
934 
935  // printing functions
936  m_BuiltInFunctions.emplace(CMacroFunction_PrintCSV::GetFuncName(), new CMacroFunction_PrintCSV(IEditMacroFunction::eDo));
937  m_BuiltInFunctions.emplace(CMacroFunction_PrintTSV::GetFuncName(), new CMacroFunction_PrintTSV(IEditMacroFunction::eDo));
938  m_BuiltInFunctions.emplace(CMacroFunction_PrintVerbatim::GetFuncName(), new CMacroFunction_PrintVerbatim(IEditMacroFunction::eDo));
939  m_BuiltInFunctions.emplace(CMacroFunction_PrintBankit::GetFuncName(), new CMacroFunction_PrintBankit(IEditMacroFunction::eDo));
940  m_BuiltInFunctions.emplace(CMacroFunction_PrintLiteral::GetFuncName(), new CMacroFunction_PrintLiteral(IEditMacroFunction::eDo));
941 
944  m_BuiltInFunctions.emplace(CMacroFunction_GeneQual::GetFuncName(), new CMacroFunction_GeneQual(IEditMacroFunction::eBoth));
945  m_BuiltInFunctions.emplace(CMacroFunction_StructVoucherPart::GetFuncName(), new CMacroFunction_StructVoucherPart(IEditMacroFunction::eBoth));
948  m_BuiltInFunctions.emplace(CMacroFunction_GetRnaProduct::GetFuncName(), new CMacroFunction_GetRnaProduct(IEditMacroFunction::eBoth));
949 
950  // SNP related functions
951  m_BuiltInFunctions.emplace(CMacroFunction_VariationType::GetFuncName(), new CMacroFunction_VariationType(IEditMacroFunction::eBoth));
952  m_BuiltInFunctions.emplace(CMacroFunction_RefAllele::GetFuncName(), new CMacroFunction_RefAllele(IEditMacroFunction::eBoth));
953  m_BuiltInFunctions.emplace(CMacroFunction_AltAlleles::GetFuncName(), new CMacroFunction_AltAlleles(IEditMacroFunction::eBoth));
954  m_BuiltInFunctions.emplace(CMacroFunction_Consequence::GetFuncName(), new CMacroFunction_Consequence(IEditMacroFunction::eBoth));
955  m_BuiltInFunctions.emplace(CMacroFunction_SnpID::GetFuncName(), new CMacroFunction_SnpID(IEditMacroFunction::eBoth));
956  m_BuiltInFunctions.emplace(CMacroFunction_VcfSevenCol::GetFuncName(), new CMacroFunction_VcfSevenCol(IEditMacroFunction::eBoth));
957 
958  m_BuiltInFunctions.emplace(CMacroFunction_ChoiceType::GetFuncName(), new CMacroFunction_ChoiceType(IEditMacroFunction::eWhere));
959  m_BuiltInFunctions.emplace(CMacroFunction_Features_For_Object::GetFuncName(), new CMacroFunction_Features_For_Object(IEditMacroFunction::eWhere));
960  m_BuiltInFunctions.emplace(CMacroFunction_CDSTranslation::GetFuncName(), new CMacroFunction_CDSTranslation(IEditMacroFunction::eWhere));
961  m_BuiltInFunctions.emplace(CMacroFunction_SeqID::GetFuncName(), new CMacroFunction_SeqID(IEditMacroFunction::eWhere));
962  m_BuiltInFunctions.emplace(CMacroFunction_Accession::GetFuncName(), new CMacroFunction_Accession(IEditMacroFunction::eBoth));
963  m_BuiltInFunctions.emplace(CMacroFunction_InconsistentTaxa::GetFuncName(), new CMacroFunction_InconsistentTaxa(IEditMacroFunction::eWhere));
964  m_BuiltInFunctions.emplace(CMacroFunction_InTable::GetFuncName(), new CMacroFunction_InTable(IEditMacroFunction::eWhere));
965 
972  m_BuiltInFunctions.emplace(CMacroFunction_GetDBLink::GetFuncName(), new CMacroFunction_GetDBLink(IEditMacroFunction::eBoth));
975  m_BuiltInFunctions.emplace(CMacroFunction_GetDBXref::GetFuncName(), new CMacroFunction_GetDBXref(IEditMacroFunction::eBoth));
976 
977  // Location constraints
982  m_BuiltInFunctions.emplace(CMacroFunction_LocationStrand::GetFuncName(), new CMacroFunction_LocationStrand(IEditMacroFunction::eBoth));
983  m_BuiltInFunctions.emplace(CMacroFunction_LocationStrandSymbol::GetFuncName(), new CMacroFunction_LocationStrandSymbol(IEditMacroFunction::eBoth));
989 
992  m_BuiltInFunctions.emplace(CMacroFunction_Contained::GetFuncName(), new CMacroFunction_Contained(IEditMacroFunction::eWhere));
993  m_BuiltInFunctions.emplace(CMacroFunction_GeneType::GetFuncName(), new CMacroFunction_GeneType(IEditMacroFunction::eBoth));
994  m_BuiltInFunctions.emplace(CMacroFunction_Label::GetFuncName(), new CMacroFunction_Label(IEditMacroFunction::eBoth));
995 
996  // Both WHERE and DO clause functions:
997 
998  m_BuiltInFunctions.emplace(CMacroFunction_StringLength::GetFuncName(), new CMacroFunction_StringLength(IEditMacroFunction::eBoth));
1000  m_BuiltInFunctions.emplace(CMacroFunction_RelatedFeatures::GetFuncName(), new CMacroFunction_RelatedFeatures(IEditMacroFunction::eBoth));
1001  m_BuiltInFunctions.emplace(CMacroFunction_StructCommField::GetFuncName(), new CMacroFunction_StructCommField(IEditMacroFunction::eBoth));
1002  m_BuiltInFunctions.emplace(CMacroFunction_StructCommDatabase::GetFuncName(), new CMacroFunction_StructCommDatabase(IEditMacroFunction::eBoth));
1003  m_BuiltInFunctions.emplace(CMacroFunction_StructCommFieldname::GetFuncName(), new CMacroFunction_StructCommFieldname(IEditMacroFunction::eBoth));
1006  m_BuiltInFunctions.emplace(CMacroFunction_IllegalDbXref::GetFuncName(), new CMacroFunction_IllegalDbXref(IEditMacroFunction::eBoth));
1007 
1008 
1009  // Publication fields
1023 
1024  x_InitStringConstraints(lookup_synfile);
1025 }
1026 
1027 void CMacroEngine::x_InitStringConstraints(bool lookup_synonym_file)
1028 {
1038 
1039  if (lookup_synonym_file) {
1045  }
1046  else {
1052  }
1053 }
1054 
1055 ///////////////////////////////////////////////////////////////////////////////
1056 /// class CMacroStat
1057 ///
1058 
1060 {
1061  m_MacroReport.Reset();
1062  m_StartTime = 0;
1063  m_StopTime = 0;
1064  m_counter = 0;
1065  m_FunctionsLog.clear();
1066  m_DataUpdated = false;
1067  m_FuncNames.clear();
1068  m_UnmatchedList.clear();
1069 }
1070 
1071 void CMacroStat::AddToReport(const string& report)
1072 {
1073  if (!report.empty()) {
1074  m_MacroReport.BuildReport(report);
1075  m_counter++;
1076  }
1077 }
1078 
1080 {
1082 }
1083 
1084 void CMacroStat::GatherUnMatchedTableEntries(const string& report, const int count)
1085 {
1086  if (!report.empty() && count > 0) {
1087  m_UnmatchedList.emplace_back(report, count);
1088  }
1089 }
1090 
1092 {
1093  m_DataUpdated |= change;
1094 }
1095 
1096 void CMacroStat::AddFunctionName(const string& func_name)
1097 {
1098  m_FuncNames.insert(func_name);
1099 }
1100 
1102 {
1103  if (log) {
1104  if (m_FunctionsLog.empty()) {
1105  CRef<IFunctionLog> fnclog = log;
1106  m_FunctionsLog.push_back(fnclog);
1107  }
1108  else {
1109  auto it = m_FunctionsLog.begin();
1110  bool found = false;
1111  while (!found && it != m_FunctionsLog.end()) {
1112  found = (*it)->Merge(*log);
1113  ++it;
1114  }
1115  }
1116  }
1117 }
1118 
1119 void CMacroStat::LogStart(const string& macro_name)
1120 {
1121  m_MacroReport.SetName(macro_name);
1122 
1123 #ifdef _DEBUG
1125  string s = "Macro (";
1126  s += m_MacroReport.GetName();
1127  s += ") execution started.";
1128  LOG_POST(Info << s);
1129 #endif
1130 }
1131 
1132 void CMacroStat::LogStop(bool status, const string& err_message)
1133 {
1135 
1136  string s = "Macro (";
1137  s += m_MacroReport.GetName();
1138  s += ") execution ";
1139  s += ((status) ? "was successful" : "failed");
1140  s += ". Elapsed time - ";
1141  s += NStr::LongToString(static_cast<long>(m_StopTime - m_StartTime));
1142  s += " seconds.";
1143 
1144  if (status)
1145  LOG_POST(Info << s);
1146  else {
1147  LOG_POST(s);
1148 
1149  s = "Macro (";
1150  s += m_MacroReport.GetName();
1151  s += ") error message: '";
1152  s += err_message;
1153  s += "'";
1154  LOG_POST(s);
1155  }
1156 }
1157 
1158 END_SCOPE(macro)
1160 
1161 /* @} */
Subclass of the IQueryParseUserObject which is held as the user-defined object in each CQueryParseNod...
Definition: macro_exec.hpp:71
The following asn-selectors are defined to be used in the FOR EACH statement:
class CMacroExecException
Definition: macro_ex.hpp:146
CMacroEngine.
class CMacroExecException
Definition: macro_ex.hpp:196
Subclass of CQueryExec that adds: 1) Macro identifiers resolution 2) Where clause evaluation.
Definition: macro_exec.hpp:319
Macro exception.
Definition: macro_ex.hpp:55
Class provides macro language interface for bulk bio-editing.
Class for parsed macro representation.
Definition: macro_rep.hpp:254
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Definition: ncbistre.hpp:802
CObjectInfo –.
Definition: objectinfo.hpp:597
Query node class.
Definition: query_parse.hpp:79
Query tree and associated utility methods.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
definition of a Culling tree
Definition: ncbi_tree.hpp:100
Base class for any user function that performs editing operations on ASN.1 data.
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
void clear()
Definition: set.hpp:153
const_iterator end() const
Definition: set.hpp:136
static const char * column
Definition: stats.c:23
static char tmp[3200]
Definition: utf8.c:42
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define DIAG_COMPILE_INFO
Make compile time diagnostic information object to use in CNcbiDiag and CException.
Definition: ncbidiag.hpp:170
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
Definition: ncbidiag.hpp:186
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
#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
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
string ReportAll(TDiagPostFlags flags=eDPF_Exception) const
Report all exceptions.
Definition: ncbiexpt.cpp:370
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
void Info(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1185
static const char * sm_BsrcForSeq
static CTempString GetFuncName()
static const char * sm_Stop
vector< CRef< CMacroRep > > TMacroLibrary
Definition: macro_lib.hpp:58
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
size_t m_counter
bool Parse(bool bSingleMacroMode=true, CQueryExec *exec=NULL)
Parse the macro and build its representation Function throws CMacroException if parsing is unsuccessf...
static const char * sm_BsrcForSeqdesc
void SetName(const string &name)
static const char * sm_PubIssue
static const char * sm_SeqNa
class CMacroFunction_LocationSeqType IS_SEQ_AA(["location"]) - returns true if the sequence identifie...
static CTempString GetFuncName()
EScopeEnum GetFuncScope()
bool GetNodeValue(const string &name, IQueryMacroUserObject &v) const
Function fills in IQueryMacroUserObject-derived node out of stored variable.
Definition: macro_rep.cpp:497
void AddToReport(const string &report)
function gradually builds the log report
void GatherUnMatchedTableEntries(const string &report, const int count)
Used when applying a table to the entry: it stores the values and number of table entries that were n...
static CTempString GetFuncName()
static const char * sm_SeqForFeat
static CTempString GetFuncName()
shared_ptr< CISOJTALookupWithCache > m_ISOJTAUpdater
void ThrowCMacroExecException(const CDiagCompileInfo &info, CMacroExecException::EErrCode code, const string &message, const CQueryParseTree::TNode *treeNode, const CException *previous=nullptr)
Throws CMacroExecException with the specified message and error location from the TNode.
Definition: macro_ex.hpp:279
void SetSource(const char *sMacroText)
Reset the parser and sets macro text to be parsed.
void x_ResetStatus(void)
Reset status and error related private data.
static CTempString GetFuncName()
CIRef< IMacroBioDataIter > m_DataIter
static const char * sm_FunctionName
class CMacroFunction_SetPubField SetPub_Date(year, month, day, season, hour, minute,...
static CTempString GetFuncName()
static CTempString GetFuncName()
const string & GetForEachString() const
Return "for each" string.
Definition: macro_rep.hpp:359
static CTempString GetFuncName()
static const char * sm_FunctionName
class CMacroFunction_ApplyPublication SetPub_Sub(author_field_name, author_field_value) Apply new pub...
void EvaluateTree(CQueryParseTree &Qtree, IResolver &resolver, bool query_tree, bool case_sensitive=false)
Evaluates tree.
Definition: macro_exec.cpp:519
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubJournal
void AddDataChanged(bool change)
function to collect whether any data was changed during the execution of the macro
const string & GetErrorReport() const
static const char * sm_SeqForDescr
class CMacroFunction_Sequence_For_Seqdesc SEQUENCE_FOR_SEQDESC(field_name) SEQUENCE_FOR_SEQFEAT(field...
bool m_Status
execution status of most recent command
static CTempString GetFuncName()
virtual CRef< CMQueryNodeValue > GetOrCreateRTVar(const string &name)
Gets or creates run-time vars (used in assignment in Do clause)
static CTempString GetFuncName()
TRTVarsMap m_RTVars
static CTempString GetFuncName()
static CTempString GetFuncName()
CMacroRep * DetachMacroRep()
Detach macro representation for futher processing Caller is responsible for deletion of returned obje...
static const char * sm_PartialStart
class CMacroFunction_LocPartialTest - tests whether the location is 5'/3' partial ISPARTIALSTART() - ...
bool IsBoolType() const
Definition: macro_exec.hpp:339
list< SResolvedField > TObs
Definition: macro_exec.hpp:92
static CTempString GetFuncName()
bool x_AppendToLibrary(const string &filename, CMacroLib::TMacroLibrary &lib)
virtual bool GetTmpRTVarObject(const string &name, CObjectInfo &oi)
static CTempString GetFuncName()
static const char * sm_PubSerialNumber
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_MolinfoForFeat
bool GetSimpleTypeValue(CObjectInfo &oi, const string &field_name, CMQueryNodeValue &value)
Get single node data from the node specified by parameter of type CObjectInfo and additionally field ...
static const char * sm_FuncVolume
class CMacroFunction_SetPubVolIssuePages SetPubVolume(newValue, existing_text, delimiter,...
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
const TObs & GetObjects() const
Definition: macro_exec.hpp:144
static const char * sm_PubAuthors
void AppendError(const string &errmsg)
void LogStart(const string &macro_name)
log start of macro execution
bool ResolveIdentToObjects(const CObjectInfo &oi, const string &identifier, CMQueryNodeValue &v)
Resolve name to the list of objects.
static CTempString GetFuncName()
shared_ptr< objects::edit::CRemoteUpdater > m_RemoteUpdater
static CTempString GetFuncName()
string m_ErrorMessage
error message
void x_SetFunctions(CMacroParser &parser)
Initializes do/where lists of functions in parser.
static CTempString GetFuncName()
TBuiltInFunctionsMap m_BuiltInFunctions
Do section functions.
static const char * sm_FromStart
class CMacroFunction_LocationDistConstraint DISTFROMSTART() [>][=][<] distance DISTFROMSTOP()
static CTempString GetFuncName()
void SetDataType(EType dt)
Definition: macro_exec.hpp:121
const string & GetName() const
shared_ptr< CHugeMacroContext > m_MacroContext
virtual ~CMacroEngine()
class CMacroEngine
unsigned GetColumnNo(void) const
Returns the column number where error occurred.
Definition: macro_ex.hpp:253
static CTempString GetFuncName()
static CTempString GetFuncName()
CRef< CMacroCmdComposite > m_CmdComposite
const CMacroRep * m_MacroRep
temporary data available while Exec is working. It is used by resolver.
static CTempString GetFuncName()
IEditMacroFunction * x_ResolveFunctionName(const string &name) const
Locates function by name.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
void LogStop(bool status, const string &err_message)
log end of macro execution this includes time of execution, status, count of changed qualifiers and a...
CQueryParseTree * GetAssignmentWhereClause(int index) const
Definition: macro_rep.cpp:280
vector< CRef< IFunctionLog > > m_FunctionsLog
static CTempString GetFuncName()
static CTempString GetFuncName()
EType GetDataType() const
Definition: macro_exec.hpp:122
Uint4 m_Column
location of problem in macro text
static CTempString GetFuncName()
static const char * sm_First
CMacroFunction_FirstItem FIRSTOF(objects) - returns the first item from the list of objects LASTOF(ob...
void x_InitStringConstraints(bool lookup_synfile)
Define the list of functions used in string constraints.
CQueryParseTree::TFunctionNames TFunctionNamesList
Type for the list of functions in Where/Do clauses.
void SetFunctionNames(const TFunctionNamesList &wh_funcs, const TFunctionNamesList &do_funcs)
initializes lists of known functions that should be recognized by the parser when going through WHERE...
void BuildReport(const string &rep)
static CTempString GetFuncName()
static CTempString GetFuncName()
time_t m_StopTime
const TSeqRange & GetSeqRange() const
Return sequence range.
Definition: macro_rep.hpp:363
CMacroLog m_MacroReport
static const char * sm_BsrcForFeat
const string & GetNamedAnnot() const
Return "from" named annotation.
Definition: macro_rep.hpp:361
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubVolume
static CTempString GetFuncName()
static CTempString GetFuncName()
const string & GetName() const
Return macro name.
Definition: macro_rep.hpp:354
static CTempString GetFuncName()
virtual void ResetTmpRTVarObjects()
static CTempString GetFuncName()
shared_ptr< CDoiLookupWithCache > m_DOIUpdater
void SetRef(CRef< CMQueryNodeValue > node)
Definition: macro_exec.hpp:130
bool IsNotSetType() const
Check/get functions result from the top node after calculation.
Definition: macro_exec.hpp:338
virtual bool ResolveIdentifier(const string &identifier, CMQueryNodeValue &v, const CQueryParseTree::TNode *parent)
Function resolves identifiers.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool ResolveIdentToSimple(const CObjectInfo &oi, const string &identifier, CMQueryNodeValue &v)
Resolve name to simple types value.
static CTempString GetFuncName()
static CTempString GetFuncName()
bool x_ResolveRTVar(const string &identifier, CMQueryNodeValue &v, const CQueryParseTree::TNode *parent)
Gets the value of RT variable.
static CTempString GetFuncName()
static const char * sm_PubStatus
static CTempString GetFuncName()
void SetNestedState(ENestedFunc type)
const string & GetFuncReport() const
Function extracts statistic from the object.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
void x_InitSetOfBuiltInFunctions(bool lookup_synfile)
Define the list of functions that is recognized by the engine.
static CTempString GetFuncName()
static const char * sm_PubTitle
class CMacroFunction_PubFields PUB_TITLE(), PUB_ISSUE(), PUB_AFFIL(subfield) - returns a list of CObj...
static CTempString GetFuncName()
static CTempString GetFuncName()
virtual void AddTmpRTVarObject(const string &name, CObjectInfo &oi)
Temporary run-time variables used in evaluating subqueries in the DO section, used together with the ...
static CTempString GetFuncName()
static CTempString GetFuncName()
void x_SetError(const string &message, Uint4 line=0, Uint4 column=0)
Sets m_Status, error_message and its location.
TTempRTVarsMap m_TempRTVars
static CTempString GetFuncName()
unsigned GetLineNo(void) const
Returns the line number where error occurred.
Definition: macro_ex.hpp:247
static CTempString GetFuncName()
static const char * sm_PubPMID
static CTempString GetFuncName()
static CTempString GetFuncName()
static const char * sm_PubDate
virtual bool ExistRTVar(const string &name)
Returns true if the run-time variable, identified by its name, was defined.
bool m_DataUpdated
static const char * sm_PubAffil
static CTempString GetFuncName()
bool m_EvalDo
Flag indicates if the work should be performed on the Do clause.
CQueryParseTree * GetDoTree() const
Return "do" clause.
Definition: macro_rep.hpp:367
static CTempString GetFuncName()
void AddFunctionName(const string &func_name)
function to collect DO function names to be used for processing reporting in huge file mode
static const char * sm_BsrcForMolinfo
class CMacroFunction_GetSeqdesc BIOSOURCE_FOR_MOLINFO(field_name) or BIOSOURCE_FOR_MOLINFO(container,...
static const char * sm_PubCit
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool ReadAndParseMacros(const string &filename, vector< CRef< CMacroRep >> &macro_list)
Parses a file containing macros and stores them in a list.
vector< pair< string, int > > m_UnmatchedList
static CTempString GetFuncName()
void Reset()
reset the macro name, qualifier and iteration counts
virtual void CallFunction(const string &name, CQueryParseTree::TNode &qnode)
Function call the function specified by name, passing args as parameters and it can update nv as a re...
static CTempString GetFuncName()
static CTempString GetFuncName()
const CRef< IFunctionLog > & GetFunctionLog() const
static CTempString GetFuncName()
static CTempString GetFuncName()
CRef< CMQueryNodeValue > x_LocateRTVar(const string &identifier)
Gets the pointer to RT variable.
static CTempString GetFuncName()
static const char * sm_FunctionName
EditRelatedFeatureQual(feat_type, field_name, find_text, repl_text, location, case_sensitive,...
bool GetBoolValue() const
Definition: macro_exec.hpp:340
static CTempString GetFuncName()
static const char * sm_PubPages
vector< string > GetSynonymFilenames(const vector< CRef< CMacroRep >> &macro_list) const
Extracts synonym files present in the list of macros.
time_t m_StartTime
bool m_HugeFileMode
execution will take place in 'huge file mode'
bool AppendToLibrary(const string &filename, CMacroLib::TMacroLibrary &lib)
Parses a file containing macros and appends the results to a map.
static CTempString GetFuncName()
virtual CQueryParseTree * GetAssignmentWhereClause(int index) const
get one of the "where" sub-clauses which are indentified by an index in the main parsed tree
set< string > m_FuncNames
CQueryParseTree * GetWhereClause() const
Return "where" clause.
Definition: macro_rep.hpp:365
static bool s_IsStringMatching(const string &fn_name)
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
bool Exec(const CMacroRep &macro_rep, const CMacroBioData &data, CRef< CMacroCmdComposite > CmdComposite, bool throw_on_error=false, CNcbiOstream *ostream=nullptr)
Executes a macro.
void AddToErrorReport(const string &error)
store encountered errors
void AddFunctionLog(const CRef< IFunctionLog > &log)
static CTempString GetFuncName()
static const char * sm_PubClass
static bool s_IsSynonymFile(const string &str)
static const char * sm_Start
class CMacroFunction_LocEnd Start() and Stop() - return the positional extremes of a location
static CTempString GetFuncName()
CMacroStat m_MacroStat
Most recent executed macro statistics.
static CTempString GetFuncName()
static CTempString GetFuncName()
static CTempString GetFuncName()
CMacroRep * Parse(const string &macro_text)
Parses macro script into its binary representation.
static const char * sm_MolinfoForBsrc
CTempString GetCurrentLine(void) const
static CRef< ILineReader > New(const string &filename)
Return a new ILineReader object corresponding to the given filename, taking "-" (but not "....
Definition: line_reader.cpp:49
void ReadLine(void)
Definition: line_reader.hpp:88
virtual bool AtEOF(void) const =0
Indicates (negatively) whether there is any more input.
TObjectType * GetNCPointerOrNull(void) const THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:1162
CConstRef< C > ConstRef(const C *object)
Template function for conversion of const object pointer to CConstRef.
Definition: ncbiobj.hpp:2024
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
TObjectType * GetPointerOrNull(void) THROWS_NONE
Get pointer value.
Definition: ncbiobj.hpp:986
TObjectType & GetNCObject(void) const
Get object.
Definition: ncbiobj.hpp:1187
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
unsigned pos
Position in the src line.
unsigned line
Src line number.
const string & GetStrValue() const
EType GetType() const
@ eFunction
Function.
Definition: query_parse.hpp:91
@ eString
String ("free text")
Definition: query_parse.hpp:90
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define USING_SCOPE(ns)
Use the specified namespace.
Definition: ncbistl.hpp:78
#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
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define kEmptyStr
Definition: ncbistr.hpp:123
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2993
static string LongToString(long value, TNumToStringFlags flags=0, int base=10)
Convert Int to string.
Definition: ncbistr.hpp:5141
static bool IsBlank(const CTempString str, SIZE_TYPE pos=0)
Check if a string is blank (has no text).
Definition: ncbistr.cpp:106
#define NPOS
Definition: ncbistr.hpp:133
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3554
static void GetCurrentTimeT(time_t *sec, long *nanosec=0)
Get current UTC time in time_t format (with nanoseconds).
Definition: ncbitime.cpp:1672
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
Definition: ncbi_tree.hpp:504
ETreeTraverseCode
Tree traverse code returned by the traverse predicate function.
Definition: ncbi_tree.hpp:51
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
const TValue & GetValue(void) const
Return node's value.
Definition: ncbi_tree.hpp:184
const TTreeType * GetParent(void) const
Get node's parent.
Definition: ncbi_tree.hpp:139
@ eTreeTraverse
Keep traversal.
Definition: ncbi_tree.hpp:52
@ eTreeTraverseStepOver
Do not traverse current node (pick the next one)
Definition: ncbi_tree.hpp:54
@ ePublication_field_affiliation
@ ePublication_field_cit
@ ePublication_field_pages
@ ePublication_field_pmid
@ ePublication_field_pub_class
@ ePublication_field_issue
@ ePublication_field_date
@ ePublication_field_title
@ ePublication_field_serial_number
@ ePublication_field_authors
@ ePublication_field_volume
@ ePublication_field_journal
@ eSeqtype_constraint_prot
@ eSeqtype_constraint_nuc
@ e_Sub
submission
Definition: Pub_.hpp:103
@ e_Molinfo
info on the molecule and techniques
Definition: Seqdesc_.hpp:134
@ e_Source
source of materials, includes Org-ref
Definition: Seqdesc_.hpp:133
Lightweight interface for getting lines of data with minimal memory copying.
#define _TRACE(arg)
Macro engine for macro execution.
Macro exceptions.
Functions that resolve field names described in asn format.
Interface class for macro function implementation.
Functions used in the DO/DONE section affecting the top seq-entry.
Macro parser components.
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Int4 delta(size_t dimension_, const Int4 *score_)
Source location (points to the position in the original src) All positions are 0 based.
#define _ASSERT
Modified on Tue May 28 05:53:01 2024 by modify_doxy.py rev. 669887