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

Go to the SVN repository for this file.

1 /* $Id: mod_reader.hpp 100616 2023-08-17 19:44:16Z stakhovv $
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: Justin Foley
27  *
28  */
29 #ifndef _MOD_READER_HPP_
30 #define _MOD_READER_HPP_
31 #include <corelib/ncbistd.hpp>
32 #include <map>
33 #include <unordered_map>
34 #include <unordered_set>
36 
39 
40 
42 {
43 public:
44  CModData() = default;
45 
46  template<typename _T1, typename _T2>
47  CModData(_T1&& name, _T2&& value) : m_name{ std::forward<_T1>(name) }, m_value{ std::forward<_T2>(value) }
48  {
49  }
50 
51  template<typename _T>
52  void SetName(_T&& name)
53  {
54  m_name = std::forward<_T>(name);
55  }
56 
57  template<typename _T>
58  void SetValue(_T&& value)
59  {
60  m_value = std::forward<_T>(value);
61  }
62  template<typename _T>
63  void SetAttrib(_T&& attrib)
64  {
65  m_attrib = std::forward<_T>(attrib);
66  }
67  bool IsSetAttrib(void) const
68  {
69  return !m_attrib.empty();
70  }
71 
72  const string& GetName(void) const
73  {
74  return m_name;
75  }
76  const string& GetValue(void) const
77  {
78  return m_value;
79  }
80  const string& GetAttrib(void) const
81  {
82  return m_attrib;
83  }
84 
85  string m_name, m_value, m_attrib;
86 };
87 
88 
89 
91 {
92 public:
93 
94  using TModList = list<CModData>;
95 
97  eReplace = 0,
98  ePreserve = 1,
99  eAppendReplace = 2,
100  eAppendPreserve = 3
101  };
102 
105  using FReportError = function<void(const CModData& mod, const string& message, EDiagSev severity, EModSubcode subcode)>;
106 
107  CModHandler();
108  void SetExcludedMods(const vector<string>& excluded_mods);
109  void SetIgnoredMods(const list<string>& ignored_mods);
110 
111  void AddMods(const TModList& mods,
112  EHandleExisting handle_existing,
113  TModList& rejected_mods,
114  FReportError fReportError=nullptr);
115 
116  void SetMods(const TMods& mods);
117 
118  const TMods& GetMods(void) const;
119 
120  void Clear(void);
121 
122  static const string& GetCanonicalName(const TModEntry& mod_entry);
123  static const string& AssertReturnSingleValue(const TModEntry& mod_entry);
124  static string GetCanonicalName(const string& name);
125 
126 private:
127  static string x_GetNormalizedString(const string& name);
128  static bool x_MultipleValuesAllowed(const string& canonical_name);
129  static bool x_IsDeprecated(const string& canonical_name);
130  void x_SaveMods(TMods&& mods, EHandleExisting handle_existing, TMods& dest);
131 
133 
134  using TNameMap = unordered_map<string, string>;
135  using TNameSet = unordered_set<string>;
136  static const TNameMap sm_NameMap;
141 };
142 
143 
144 class CBioseq;
145 class CSeq_inst;
146 class CSeq_loc;
147 class CModReaderException;
148 
149 
151 {
152 public:
155  using TSkippedMods = list<CModData>;
158 
159  static void Apply(const CModHandler& mod_handler,
160  CBioseq& bioseq,
161  TSkippedMods& skipped_mods,
162  FPostMessage fPostMessage=nullptr);
163 
164  static void Apply(const CModHandler& mod_handler,
165  CBioseq& bioseq,
166  TSkippedMods& skipped_mods,
167  bool logInfo,
168  FPostMessage fPostMessage=nullptr);
169 private:
170 
171  static const string& x_GetModName(const TModEntry& mod_entry);
172  static const string& x_GetModValue(const TModEntry& mod_entry);
173 
174  static bool x_TrySeqInstMod(const TModEntry& mod_entry,
175  CSeq_inst& seq_inst,
176  TSkippedMods& skipped_mods,
177  FPostMessage fPostMessage);
178 
179  static void x_SetStrand(const TModEntry& mod_entry,
180  CSeq_inst& seq_inst,
181  TSkippedMods& skipped_mods,
182  FPostMessage fPostMessage);
183 
184  static void x_SetMolecule(const TModEntry& mod_entry,
185  CSeq_inst& seq_inst,
186  TSkippedMods& skipped_mods,
187  FPostMessage fPostMessage);
188 
189  static void x_SetMoleculeFromMolType(const TModEntry& mod_entry,
190  CSeq_inst& seq_inst);
191 
192  static void x_SetTopology(const TModEntry& mod_entry,
193  CSeq_inst& seq_inst,
194  TSkippedMods& skipped_mods,
195  FPostMessage fPostMessage);
196 
197  static void x_SetHist(const TModEntry& mod_entry,
198  CSeq_inst& seq_inst);
199 
200  static void x_ReportInvalidValue(const CModData& mod_data,
201  TSkippedMods& skipped_mods,
202  FPostMessage fPostMessage);
203 };
204 
205 
206 class IObjtoolsListener;
208 {
209 public:
210  using TModList = list<CModData>;
211 
213  const string& seqId,
214  int lineNum,
215  IObjtoolsListener* pMessageListener);
216 
217  void operator()(
218  const CModData& mod,
219  const string& msg,
220  EDiagSev sev,
221  EModSubcode subcode);
222 
223 private:
224  string m_SeqId;
227 };
228 
229 
231 {
232 public:
234  static void Apply(const CTempString& title, TModList& mods, string& remainder);
235  static bool HasMods(const CTempString& title);
236 private:
237  static bool x_FindBrackets(const CTempString& line, size_t& start, size_t& stop, size_t& eq_pos);
238 };
239 
242 
243 #endif // _MOD_READER_HPP_
IObjtoolsListener * m_pMessageListener
Definition: mod_reader.hpp:226
list< CModData > TModList
Definition: mod_reader.hpp:210
FReportError FPostMessage
Definition: mod_reader.hpp:157
list< CModData > TSkippedMods
Definition: mod_reader.hpp:155
CModHandler::FReportError FReportError
Definition: mod_reader.hpp:156
CModHandler::TModEntry TModEntry
Definition: mod_reader.hpp:154
string m_value
Definition: mod_reader.hpp:85
bool IsSetAttrib(void) const
Definition: mod_reader.hpp:67
void SetName(_T &&name)
Definition: mod_reader.hpp:52
CModData(_T1 &&name, _T2 &&value)
Definition: mod_reader.hpp:47
void SetAttrib(_T &&attrib)
Definition: mod_reader.hpp:63
CModData()=default
const string & GetValue(void) const
Definition: mod_reader.hpp:76
void SetValue(_T &&value)
Definition: mod_reader.hpp:58
const string & GetName(void) const
Definition: mod_reader.hpp:72
const string & GetAttrib(void) const
Definition: mod_reader.hpp:80
function< void(const CModData &mod, const string &message, EDiagSev severity, EModSubcode subcode)> FReportError
Definition: mod_reader.hpp:105
map< string, list< CModData > > TMods
Definition: mod_reader.hpp:103
TNameSet m_IgnoredModifiers
Definition: mod_reader.hpp:140
list< CModData > TModList
Definition: mod_reader.hpp:94
unordered_map< string, string > TNameMap
Definition: mod_reader.hpp:134
TNameSet m_ExcludedModifiers
Definition: mod_reader.hpp:139
static const TNameMap sm_NameMap
Definition: mod_reader.hpp:136
static const TNameSet sm_MultipleValuesForbidden
Definition: mod_reader.hpp:137
static const TNameSet sm_DeprecatedModifiers
Definition: mod_reader.hpp:138
unordered_set< string > TNameSet
Definition: mod_reader.hpp:135
TMods::value_type TModEntry
Definition: mod_reader.hpp:104
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
Definition: tempstr.hpp:65
CModHandler::TModList TModList
Definition: mod_reader.hpp:233
Include a standard set of the NCBI C++ Toolkit most basic headers.
EDiagSev
Severity level for the posted diagnostics.
Definition: ncbidiag.hpp:650
#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
#define NCBI_XOBJREAD_EXPORT
Definition: ncbi_export.h:1315
double value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:228
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Int mod(Int i, Int j)
Definition: njn_integer.hpp:67
Modified on Wed Apr 17 13:09:46 2024 by modify_doxy.py rev. 669887