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

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_EDIT___MACRO_INTERPRET__HPP
2 #define GUI_WIDGETS_EDIT___MACRO_INTERPRET__HPP
3 /* $Id: macro_interpret.hpp 47274 2022-12-06 16:17:02Z 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: Andrea Asztalos
29  */
30 
31 #include <corelib/ncbistd.hpp>
37 
39 
40 /// Class to store one function as it appears in the macro and its arguments (as GUI fieldnames)
42 {
43 public:
46  : m_FName(fnc.m_FuncName), m_Negate(fnc.m_Negate), m_ParentFnc(fnc.m_ParentFnc), m_ChildFnc(fnc.m_ChildFnc) {}
47 
49 
50  bool operator==(const CFuncWithArgs& other) const;
51 
52  /// Function name as it appears in the macro
53  string m_FName;
54  /// Map of control names and corresponding values. It may contain more 'arguments' than the function has
55  using TInterpretedArgs = unordered_map<string, string>;
57  bool m_Negate{ false };
58  string m_ParentFnc;
59  CRef<SMacroFuncWithArgs> m_ChildFnc{ nullptr }; // to describe nested functions (used in constraints)
60 
63 };
64 
66 
67 
68 class CMacroInterpreter;
69 
71 {
72 public:
75 
77  bool InterpretDoFunctions(const macro::CMacroRep& macro_rep);
78 
79  const vector<CFuncWithArgs>& GetInterpretedFunctions() const { return m_DoFuncInfo; }
80  vector<CFuncWithArgs>& SetInterpretedFunctions() { return m_DoFuncInfo; }
81 
82  const vector<CFuncWithArgs>& GetWhereFunctions() const { return m_WhereGUIFuncInfo; }
83 
84  bool PostProcess(EMActionType action_type);
85  bool ActionHasCdsGeneProtQuals();
87 
88  /// Prohibit copy constructor and assignment operator
91 
92 private:
93  void x_Reset();
94  bool x_AddToRTVar(const string& name, const TArgs& members);
95  bool x_InterpretWhereFunctions(const TMacroFuncList& do_constraints);
96  void x_CleanupWhereFunctions();
97  bool x_ConsolidateWhereFunctions();
98  void x_InsertFeatureType(const string& feat_type);
99  void x_InsertFeatureTypeToWhereClause();
100  bool x_ProcessNestedFunctions(CRef<SMacroFuncWithArgs>& child_fnc, TInterpretedArgs& mapped_args);
101 
102  CConstRef<macro::CMacroRep> m_MacroRep{ nullptr };
103  using TRTVarmap = unordered_map<string, TArgs>;
105 
106  string m_Target; ///< the FOR EACH selector of the edited macro
107  bool m_MightRemove{ false }; ///< when 'true', it signals that the action requires an additional 'remove' function
108 
109  // editing functions
110  bool x_AddStructVoucherPart(const TArgs&, TInterpretedArgs&);
111  bool x_SetStringQualValidateArgs(const TArgs&, TInterpretedArgs&);
112  bool x_SetModifierValidateArgs(const TArgs&, TInterpretedArgs&);
113  bool x_EditStringQualValidateArgs(const TArgs&, TInterpretedArgs&);
114  bool x_EditSubfieldValidateArgs(const TArgs&, TInterpretedArgs&);
115  bool x_ConvertStringQualValidateArgs(const TArgs&, TInterpretedArgs&);
116  bool x_RemoveModifierValidateArgs(const TArgs&, TInterpretedArgs&);
117  bool x_CopyStringQualValidateArgs(const TArgs&, TInterpretedArgs&);
118  bool x_SwapQualValidateArgs(const TArgs&, TInterpretedArgs&);
119  bool x_FixFormatValidateArgs(const TArgs&, TInterpretedArgs&);
120  bool x_FixSourceQualCapsValidateArgs(const TArgs&, TInterpretedArgs&);
121  bool x_RemoveQualValidateArgs(const TArgs&, TInterpretedArgs&);
122  bool x_RemoveSubfieldValidateArgs(const TArgs&, TInterpretedArgs&);
123  bool x_ParseStringQualValidateArgs(const TArgs&, TInterpretedArgs&);
124  bool x_AddParsedTextValidateArgs(const TArgs&, TInterpretedArgs&);
125  bool x_ParseToStructCommValidateArgs(const TArgs&, TInterpretedArgs&);
126  bool x_ParseToDBLinkValidateArgs(const TArgs&, TInterpretedArgs&);
127  bool x_RmvOrgnameValidateArgs(const TArgs&, TInterpretedArgs&);
128  bool x_RmvOutsideValidateArgs(const TArgs&, TInterpretedArgs&);
129  bool x_RmvOutsideRelFeatValidateArgs(const TArgs&, TInterpretedArgs&);
130  bool x_SetQualValidateArgs(const TArgs&, TInterpretedArgs&);
131  bool x_AddMultiAuthorsValidateArgs(const TArgs&, TInterpretedArgs&);
132  bool x_AddDBLinkValidateArgs(const TArgs&, TInterpretedArgs&);
133  bool x_SetStrCommFieldValidateArgs(const TArgs&, TInterpretedArgs&);
134  bool x_SetStrCommDbValidateArgs(const TArgs&, TInterpretedArgs&);
135  bool x_RmvDescrValidateArgs(const TArgs&, TInterpretedArgs&);
136  bool x_RetranslateCDSValidateArgs(const TArgs&, TInterpretedArgs&);
137  bool x_RestoreRNAEditValidateArgs(const TArgs&, TInterpretedArgs&);
138  bool x_UpdateReplECsValidateArgs(const TArgs&, TInterpretedArgs&);
139  bool x_SetRnaProdValidateArgs(const TArgs&, TInterpretedArgs&);
140  bool x_SetGBQualValidateArgs(const TArgs&, TInterpretedArgs&);
141  bool x_SetRelFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
142  bool x_EditRelFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
143  bool x_ConvertFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
144  bool x_CopyFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
145  bool x_RemoveRnaProdValidateArgs(const TArgs&, TInterpretedArgs&);
146  bool x_RmvRelFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
147  bool x_SetCodonRecognizedValidateArgs(const TArgs&, TInterpretedArgs&);
148  bool x_CopyRNARelQualValidateArgs(const TArgs&, TInterpretedArgs&);
149  bool x_ConvertRNARelQualValidateArgs(const TArgs&, TInterpretedArgs&);
150  bool x_ParseFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
151  bool x_AddParsedTextFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
152  bool x_SwapRelFeatQualValidateArgs(const TArgs&, TInterpretedArgs&);
153  bool x_ParseRNARelQualValidateArgs(const TArgs&, TInterpretedArgs&);
154  bool x_ApplyAutodefOptsValidateArgs(const TArgs&, TInterpretedArgs&);
155  bool x_ApplyUnverifiedValidateArgs(const TArgs&, TInterpretedArgs&);
156 
157  // modifying features' location
158  bool x_ExtendFeatValidateArgs(const TArgs&, TInterpretedArgs&);
159  bool x_Set5PartialValidateArgs(const TArgs&, TInterpretedArgs&);
160  bool x_Set3PartialValidateArgs(const TArgs&, TInterpretedArgs&);
161  bool x_SetBothPartialValidateArgs(const TArgs&, TInterpretedArgs&);
162  bool x_Clear5PartialValidateArgs(const TArgs&, TInterpretedArgs&);
163  bool x_Clear3PartialValidateArgs(const TArgs&, TInterpretedArgs&);
164  bool x_ClearBothPartialValidateArgs(const TArgs&, TInterpretedArgs&);
165  bool x_ConvertLocStrandValidateArgs(const TArgs&, TInterpretedArgs&);
166  bool x_ConvertLocTypeValidateArgs(const TArgs&, TInterpretedArgs&);
167 
168  // pubdesc functions
169  bool x_SetPubTitleValidateArgs(const TArgs&, TInterpretedArgs&);
170  bool x_SetPubAffilValidateArgs(const TArgs&, TInterpretedArgs&);
171  bool x_SetPubAuthorValidateArgs(const TArgs&, TInterpretedArgs&);
172  bool x_SetPubAuthMIValidateArgs(const TArgs&, TInterpretedArgs&);
173  bool x_AddAuthorsValidateArgs(const TArgs&, TInterpretedArgs&);
174  bool x_SetPubJournalValidateArgs(const TArgs&, TInterpretedArgs&);
175  bool x_SetPubVolumeValidateArgs(const TArgs&, TInterpretedArgs&);
176  bool x_SetPubIssueValidateArgs(const TArgs&, TInterpretedArgs&);
177  bool x_SetPubPagesValidateArgs(const TArgs&, TInterpretedArgs&);
178  bool x_SetSerialNumberValidateArgs(const TArgs&, TInterpretedArgs&);
179  bool x_SetPubCitValidateArgs(const TArgs&, TInterpretedArgs&);
180  bool x_SetPmidValidateArgs(const TArgs&, TInterpretedArgs&);
181  bool x_SetStatusValidateArgs(const TArgs&, TInterpretedArgs&);
182  bool x_SetDateFieldValidateArgs(const TArgs&, TInterpretedArgs&);
183  bool x_SetPubDateValidateArgs(const TArgs&, TInterpretedArgs&);
184  bool x_RemoveMInitialsValidateArgs(const TArgs&, TInterpretedArgs&);
185  bool x_RemoveAuthorsValidateArgs(const TArgs&, TInterpretedArgs&);
186  bool x_DOILookupValidateArgs(const TArgs&, TInterpretedArgs&);
187  bool x_GlobalDOIValidateArgs(const TArgs&, TInterpretedArgs&);
188  bool x_FixPubTitleValidateArgs(const TArgs&, TInterpretedArgs&);
189  bool x_FixPubAuthorsValidateArgs(const TArgs&, TInterpretedArgs&);
190  bool x_FixPubAffilValidateArgs(const TArgs&, TInterpretedArgs&);
191  bool x_FixPubAffilCountryValidateArgs(const TArgs&, TInterpretedArgs&);
192  bool x_FixPubAffilFieldsValidateArgs(const TArgs&, TInterpretedArgs&);
193 
194  bool x_ConvertFeatureValidateArgs(const TArgs&, TInterpretedArgs&);
195  bool x_ConvertCDSValidateArgs(const TArgs&, TInterpretedArgs&);
196  bool x_RemoveFeatValidateArgs(const TArgs&, TInterpretedArgs&);
197  bool x_RemoveAllFeatsValidateArgs(const TArgs&, TInterpretedArgs&);
198  bool x_AddGeneXrefValidateArgs(const TArgs&, TInterpretedArgs&);
199  bool x_RmvGeneXrefValidateArgs(const TArgs&, TInterpretedArgs&);
200 
201  bool x_ApplyCDSValidateArgs(const TArgs&, TInterpretedArgs&);
202  bool x_ApplyGeneValidateArgs(const TArgs&, TInterpretedArgs&);
203  bool x_ApplyRNAValidateArgs(const TArgs&, TInterpretedArgs&);
204  bool x_ApplyFeatureValidateArgs(const TArgs&, TInterpretedArgs&);
205  bool x_MakeWholeSeqIntValidateArgs(const TArgs&, TInterpretedArgs&);
206  bool x_MakeIntervalValidateArgs(const TArgs&, TInterpretedArgs&);
207  bool x_RmvDuplFeatsValidateArgs(const TArgs&, TInterpretedArgs&);
208  bool x_ConvertGapsValidateArgs(const TArgs&, TInterpretedArgs&);
209 
210  bool x_DiscrAutofixValidateArgs(const TArgs&, TInterpretedArgs&);
211  bool x_ApplyPMIDValidateArgs(const TArgs&, TInterpretedArgs&);
212  bool x_ApplyDOIValidateArgs(const TArgs&, TInterpretedArgs&);
213  bool x_AutodefValidateArgs(const TArgs&, TInterpretedArgs&);
214  bool x_AutodefCompleteValidateArgs(const TArgs&, TInterpretedArgs&);
215  bool x_ConvertRawToDeltabyNsValidateArgs(const TArgs&, TInterpretedArgs&);
216  bool x_AddGapFeatsbyNsValidateArgs(const TArgs&, TInterpretedArgs&);
217  bool x_UpdateProteinsValidateArgs(const TArgs&, TInterpretedArgs&);
218 
219  // auxiliary functions
220  bool x_ParseFieldFromRTVar(TInterpretedArgs&, const string& name, const string& value);
221  bool x_StoreParsingArguments(TInterpretedArgs&, TRTVarmap::const_iterator& iter);
222  bool x_ParseArgsForApplyTable(const TArgs&, size_t, TArgs::const_iterator&, TArgumentsVector::const_iterator&, const TArgumentsVector::const_iterator&, TInterpretedArgs&);
223  bool x_ValidateMultiArgs(const TArgs&, TInterpretedArgs& mapped_args, CPubFieldType::EPubFieldType type);
224 
225  // functions used in constraints
226  bool x_StringConstraintValidateArgs(const TArgs&, TInterpretedArgs&);
227  bool x_CaseConstraintValidateArgs(const TArgs&, TInterpretedArgs&);
228  bool x_ChoiceTypeValidateArgs(const TArgs&, TInterpretedArgs&);
229  bool x_IsPresentValidateArgs(const TArgs&, TInterpretedArgs&);
230  bool x_InterpretFieldValidateArgs(const TArgs&, TInterpretedArgs&);
231  bool x_InterpretRNATypeValidateArgs(const TArgs&, TInterpretedArgs&);
232  bool x_InterpretncRNAclassValidateArgs(const TArgs&, TInterpretedArgs&);
233  bool x_InterpretFeatTypeValidateArgs(const TArgs&, TInterpretedArgs&);
234  bool x_ComparisonOpValidateArgs(const TArgs&, TInterpretedArgs&);
235  bool x_InconsTaxaValidateArgs(const TArgs&, TInterpretedArgs&);
236  bool x_InTableValidateArgs(const TArgs&, TInterpretedArgs&);
237  bool x_SeqIdValidateArgs(const TArgs&, TInterpretedArgs&);
238  bool x_IllegalDbXrefValidateArgs(const TArgs&, TInterpretedArgs&);
239  bool x_SatelliteNameValidateArgs(const TArgs&, TInterpretedArgs&);
240  bool x_SatelliteTypeValidateArgs(const TArgs&, TInterpretedArgs&);
241  bool x_MobileElemNameValidateArgs(const TArgs&, TInterpretedArgs&);
242  bool x_MobileElemTypeValidateArgs(const TArgs&, TInterpretedArgs&);
243 
244  bool x_PubTitleConstrValidateArgs(const TArgs&, TInterpretedArgs&);
245  bool x_PubAffilConstrValidateArgs(const TArgs&, TInterpretedArgs&);
246  bool x_PubAuthorConstrValidateArgs(const TArgs&, TInterpretedArgs&);
247  bool x_PubCitConstrValidateArgs(const TArgs&, TInterpretedArgs&);
248  bool x_PubPMIDConstrValidateArgs(const TArgs&, TInterpretedArgs&);
249  bool x_PubSerialNrConstrValidateArgs(const TArgs&, TInterpretedArgs&);
250  bool x_PubStatusConstrValidateArgs(const TArgs&, TInterpretedArgs&);
251  bool x_PubDateConstrValidateArgs(const TArgs&, TInterpretedArgs&);
252  bool x_PubIssueConstrValidateArgs(const TArgs&, TInterpretedArgs&);
253  bool x_PubJournalConstrValidateArgs(const TArgs&, TInterpretedArgs&);
254  bool x_PubPagesConstrValidateArgs(const TArgs&, TInterpretedArgs&);
255  bool x_PubVolConstrValidateArgs(const TArgs&, TInterpretedArgs&);
256 
257  bool x_GetFeatureValidateArgs(const TArgs&, TInterpretedArgs&);
258  bool x_GetSeqdescValidateArgs(const TArgs&, TInterpretedArgs&);
259  bool x_GetDBLinkValidateArgs(const TArgs&, TInterpretedArgs&);
260  bool x_GetSequenceValidateArgs(const TArgs&, TInterpretedArgs&);
261  bool x_StructVoucherPartValidateArgs(const TArgs&, TInterpretedArgs&);
262  bool x_StructCommFieldValidateArgs(const TArgs&, TInterpretedArgs&);
263  bool x_StructCommDbValidateArgs(const TArgs&, TInterpretedArgs&);
264  bool x_StructCommFieldNameValidateArgs(const TArgs&, TInterpretedArgs&);
265  bool x_GetDBxrefValidateArgs(const TArgs&, TInterpretedArgs&);
266  bool x_GetRnaProdValidateArgs(const TArgs&, TInterpretedArgs&);
267  bool x_NumberofFeatsValidateArgs(const TArgs&, TInterpretedArgs&);
268  bool x_GetFirstItemValidateArgs(const TArgs&, TInterpretedArgs&);
269 
270  // feature locations constraints
271  bool x_StrandValidateArgs(const TArgs&, TInterpretedArgs&);
272  bool x_PartialStartValidateArgs(const TArgs&, TInterpretedArgs&);
273  bool x_PartialStopValidateArgs(const TArgs&, TInterpretedArgs&);
274  bool x_LocationTypeValidateArgs(const TArgs&, TInterpretedArgs&);
275  bool x_SeqTypeValidateArgs(const TArgs&, TInterpretedArgs&);
276  bool x_DistanceValidateArgs(const TArgs&, TInterpretedArgs&);
277 
278  // functions used in conjunction with the assignment operator
279  bool x_ResolveValidateArgs(const TArgs&);
280  bool x_LocalIdValidateArgs(const TArgs&);
281  bool x_SeqForDescValidateArgs(const TArgs&);
282  bool x_ParsedTextValidateArgs(const TArgs&);
283  bool x_ParsedTextFromValidateArgs(const TArgs&);
284  bool x_PubTitleValidateArgs(const TArgs&);
285  bool x_PubAffilValidateArgs(const TArgs&);
286  bool x_PubAuthorValidateArgs(const TArgs&);
287  bool x_PubJournalValidateArgs(const TArgs&);
288  bool x_PubIssueValidateArgs(const TArgs&);
289  bool x_PubPagesValidateArgs(const TArgs&);
290  bool x_PubVolValidateArgs(const TArgs&);
291  bool x_PubStatusValidateArgs(const TArgs&);
292  bool x_PubDateValidateArgs(const TArgs&);
293  bool x_PubCitValidateArgs(const TArgs&);
294  bool x_PubPMIDValidateArgs(const TArgs&);
295  bool x_PubSerialNrValidateArgs(const TArgs&);
296  bool x_SetStrCommDbAssignValidateArgs(const TArgs&);
297  bool x_MakeWholeSeqIntAssignValidateArgs(const TArgs&);
298  bool x_MakeIntervalAssignValidateArgs(const TArgs&);
299  bool x_GeneQualValidateArgs(const TArgs&);
300  bool x_ValueFromTblValidateArgs(const TArgs&);
301 
302  // postprocessing function arguments to be displayed in the macro editor
303  bool x_PostProcessEditMolinfo();
304  bool x_PostProcessApplyAuthors();
305  bool x_PostProcessDiscrAutofix();
306  bool x_PostProcessSetException();
307  bool x_PostProcessRmvDbxref();
308  bool x_PostProcessAddStructComment();
309  bool x_PostProcessConvertSetClass();
310  bool x_PostProcessAddFeature(const string& fn_name);
311  bool x_PostProcessApplyQualifierTable();
312 
313  bool x_UpdateTargetFieldForSeqdesc();
314  bool x_UpdateTargetFieldForRNA();
315  bool x_UpdateFieldsForMatPeptide();
316  string x_FindFeatureType();
317 
318  vector<CFuncWithArgs> m_DoFuncInfo; ///< interpreted functions that appear in the DO section
319  vector<CFuncWithArgs> m_WhereFuncInfo; ///< function information about the functions from the WHERE clause
320  vector<CFuncWithArgs> m_WhereGUIFuncInfo; ///< the same as m_WhereFuncInfo, but here the fields are interpreted
321  using TFncValidatorMap = map<string, function<bool(CMacroInterpreter& interpreter, const TArgs&, TInterpretedArgs&)>, PNocase>;
322  static const TFncValidatorMap& x_GetFncValidatorMap();
323 
324  static const TFncValidatorMap& x_GetWhereFncValidatorMap();
325 
326  using TAssignFncValidatorMap = map<string, function<bool(CMacroInterpreter& interpreter, const TArgs&)>, PNocase>;
327  static const TAssignFncValidatorMap& x_GetAssignFncValidatorMap();
328 };
329 
330 
332 
333 #endif
334  // GUI_WIDGETS_EDIT___MACRO_INTERPRET__HPP
Class to store one function as it appears in the macro and its arguments (as GUI fieldnames)
unordered_map< string, string > TInterpretedArgs
Map of control names and corresponding values. It may contain more 'arguments' than the function has.
CFuncWithArgs(const SMacroFuncWithArgs &fnc)
TInterpretedArgs m_FArgs
string m_FName
Function name as it appears in the macro.
CMacroInterpreter & operator=(const CMacroInterpreter &)=delete
vector< CFuncWithArgs > m_WhereGUIFuncInfo
the same as m_WhereFuncInfo, but here the fields are interpreted
CFuncWithArgs::TInterpretedArgs TInterpretedArgs
CMacroInterpreter(const CMacroInterpreter &)=delete
Prohibit copy constructor and assignment operator.
const vector< CFuncWithArgs > & GetWhereFunctions() const
unordered_map< string, TArgs > TRTVarmap
string m_Target
the FOR EACH selector of the edited macro
const vector< CFuncWithArgs > & GetInterpretedFunctions() const
vector< CFuncWithArgs > m_WhereFuncInfo
function information about the functions from the WHERE clause
vector< CFuncWithArgs > m_DoFuncInfo
interpreted functions that appear in the DO section
SMacroFuncWithArgs::TArgs TArgs
vector< CFuncWithArgs > & SetInterpretedFunctions()
CObject –.
Definition: ncbiobj.hpp:180
Definition: map.hpp:338
Include a standard set of the NCBI C++ Toolkit most basic headers.
bool operator==(const CEquivRange &A, const CEquivRange &B)
#define bool
Definition: bool.h:34
string
Definition: cgiapp.hpp:687
CObject & operator=(const CObject &src) THROWS_NONE
Assignment operator.
Definition: ncbiobj.hpp:482
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
Definition: ncbistre.hpp:149
#define NCBI_GUIWIDGETS_EDIT_EXPORT
Definition: gui_export.h:526
EMActionType
CNcbiOstream & operator<<(CNcbiOstream &ostrm, const CFuncWithArgs &f_args)
vector< SMacroFuncWithArgs > TMacroFuncList
void NormalizeFieldForFeatPanel(string &field)
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Structure to store parsed function name and its arguments - as it appears in the macro It is used whe...
Definition: type.c:6
Modified on Tue May 21 10:57:58 2024 by modify_doxy.py rev. 669887