RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
Rules.h
Go to the documentation of this file.
1//
2//
3// Copyright (C) 2020 Schrödinger, LLC
4//
5// @@ All Rights Reserved @@
6// This file is part of the RDKit.
7// The contents are covered by the terms of the BSD license
8// which is included in the file license.txt, found at the root
9// of the RDKit source tree.
10//
11#pragma once
12
13#include <initializer_list>
14#include <vector>
15
16#include "Rule5.h"
17#include "SequenceRule.h"
18
19namespace RDKit {
20namespace CIPLabeler {
21
22class Rules : public SequenceRule {
23 public:
24 Rules() = delete;
25
26 Rules(std::initializer_list<SequenceRule *> rules) {
27 for (auto &rule : rules) {
28 add(rule);
29 }
30 }
31
32 ~Rules() override {
33 for (auto &rule : d_rules) {
34 delete rule;
35 }
36 }
37
39 if (rule == nullptr) {
40 throw std::runtime_error("No sequence rule provided");
41 }
42 d_rules.push_back(rule);
43 rule->setSorter(new Sort(d_rules));
44 }
45
46 int getNumSubRules() const { return d_rules.size(); }
47
48 const Sort *getSorter() const override {
49 if (dp_sorter == nullptr) {
50 const_cast<Rules *>(this)->setSorter(new Sort(this));
51 }
52 return dp_sorter.get();
53 }
54
55 int compare(const Edge *o1, const Edge *o2) const override {
56 // Try using each rules. The rules will expand the search exhaustively
57 // to all child substituents
58 for (const auto &rule : d_rules) {
59 // compare expands exhaustively across the whole graph
60 int value = rule->recursiveCompare(o1, o2);
61 if (value != 0) {
62 return value;
63 }
64 }
65 return 0;
66 }
67
68 int getComparision(const Edge *a, const Edge *b, bool deep) const override {
69 (void)deep;
70
71 // Try using each rules. The rules will expand the search exhaustively
72 // to all child substituents
73 for (const auto &rule : d_rules) {
74 // compare expands exhaustively across the whole graph
75 int value = rule->recursiveCompare(a, b);
76
77 if (value != 0) {
78 return value;
79 }
80 }
81
82 return 0;
83 }
84
85 private:
86 std::vector<const SequenceRule *> d_rules;
87};
88
89} // namespace CIPLabeler
90} // namespace RDKit
~Rules() override
Definition Rules.h:32
Rules(std::initializer_list< SequenceRule * > rules)
Definition Rules.h:26
int getComparision(const Edge *a, const Edge *b, bool deep) const override
Definition Rules.h:68
const Sort * getSorter() const override
Definition Rules.h:48
void add(SequenceRule *rule)
Definition Rules.h:38
int getNumSubRules() const
Definition Rules.h:46
int compare(const Edge *o1, const Edge *o2) const override
Definition Rules.h:55
std::unique_ptr< const Sort > dp_sorter
void setSorter(const Sort *sorter)
Std stuff.
bool rdvalue_is(const RDValue_cast_t)