Gemmi C++ API
Loading...
Searching...
No Matches
ddl.hpp
Go to the documentation of this file.
1// Copyright Global Phasing Ltd.
2//
3// Using DDL1/DDL2 dictionaries to validate CIF/mmCIF files.
4
5#ifndef GEMMI_DDL_HPP_
6#define GEMMI_DDL_HPP_
7
8#include <map>
9#include <memory> // for unique_ptr
10#include <regex>
11#include "cifdoc.hpp" // for cif::Document
12#include "logger.hpp" // for Logger
13
14namespace gemmi { namespace cif {
15
17struct GEMMI_DLL Ddl {
20 // configuration - some of these flag must be set before read_ddl()
21 bool print_unknown_tags = true;
22 // these flags below are relevant to DDL2 only
23 bool use_regex = true;
24 bool use_context = false;
25 bool use_parents = false;
26 bool use_mandatory = true;
27 bool use_unique_keys = true;
28 // instead of _item_type.code, _pdbx_item_enumeration.value, and _item_range
29 // use _pdbx-prefixed equivalents (_pdbx_item_type.code, etc).
30 bool use_deposition_checks = false;
31
32 // variables set when reading DLL; normally, no need to change them
33 int major_version = 0; // currently 1 and 2 are supported
34 std::string dict_name; // _dictionary_name or _dictionary.title
35 std::string dict_version; // _dictionary_version or _dictionary.version
36
37 Ddl() = default;
38 // MSVC with dllexport attempts to export all non-deleted member functions,
39 // failing with Error C2280 (because of ddl_docs_) if we don't delete these:
40 Ddl(Ddl const&) = delete;
41 Ddl& operator=(Ddl const&) = delete;
42
45
46 bool validate_cif(const cif::Document& doc) const;
47 bool validate_block(const cif::Block& b, const std::string& source) const;
48
50
51 const std::map<std::string, std::regex>& regexes() const { return regexes_; }
52
53private:
54 // items from DDL2 _pdbx_item_linked_group[_list]
55 struct ParentLink {
56 std::string group;
57 std::vector<std::string> child_tags;
58 std::vector<std::string> parent_tags;
59 };
60
61 std::vector<std::unique_ptr<cif::Document>> ddl_docs_;
62 std::map<std::string, cif::Block*> name_index_;
63 std::map<std::string, std::regex> regexes_;
64 std::vector<ParentLink> parents_;
65 // storage for DDL2 _item_linked.child_name -> _item_linked.parent_name
66 std::map<std::string, std::string> item_parents_;
67
68 cif::Block* find_rules(const std::string& name) const {
69 auto iter = name_index_.find(to_lower(name));
70 return iter != name_index_.end() ? iter->second : nullptr;
71 }
72 void check_mandatory_items(const cif::Block& b) const;
73 void check_unique_keys_in_loop(const cif::Loop& loop, const cif::Block& block) const;
74 void check_parents(const cif::Block& b) const;
75 void check_parent_link(const ParentLink& link, const cif::Block& b) const;
76 void read_ddl1_block(cif::Block& block);
77 void read_ddl2_block(cif::Block& block);
78
79 template<class... Args> void warn(const cif::Block& b, Args const&... args) const {
80 logger.level<3>('[', b.name, "] ", args...);
81 }
82};
83
84}} // namespace gemmi::cif
85#endif
struct Document that represents the CIF file (but can also be read from a different representation,...
#define GEMMI_DLL
Definition fail.hpp:53
Logger - a tiny utility for passing messages through a callback.
std::string to_lower(std::string str)
Definition util.hpp:63
Passes messages (including warnings/errors) to a callback function.
Definition logger.hpp:23
void level(Args const &... args) const
Send a message without any prefix on with a numeric threshold N.
Definition logger.hpp:36
Represents DDL1 or DDL2 dictionary (ontology).
Definition ddl.hpp:17
bool validate_block(const cif::Block &b, const std::string &source) const
bool validate_cif(const cif::Document &doc) const
Ddl & operator=(Ddl const &)=delete
void read_ddl(cif::Document &&doc)
it moves doc to ddl_docs_ to control lifetime and prevent modifications
Ddl(Ddl const &)=delete
std::string dict_version
Definition ddl.hpp:35
std::string dict_name
Definition ddl.hpp:34
void check_audit_conform(const cif::Document &doc) const
Logger logger
member functions use logger's callback and threshold for output
Definition ddl.hpp:19
const std::map< std::string, std::regex > & regexes() const
Definition ddl.hpp:51