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
38 int getNumSubRules() const { return d_rules.size(); }
39
40 int compare(const Edge *o1, const Edge *o2) const override {
41 // Try using each rules. The rules will expand the search exhaustively
42 // to all child substituents
43 for (const auto &rule : d_rules) {
44 // compare expands exhaustively across the whole graph
45 int value = rule->recursiveCompare(o1, o2);
46 if (value != 0) {
47 return value;
48 }
49 }
50 return 0;
51 }
52
53 int getComparision(const Edge *a, const Edge *b,
54 bool /* unused */) const override {
55 // Try using each rules. The rules will expand the search exhaustively
56 // to all child substituents
57 for (const auto &rule : d_rules) {
58 // compare expands exhaustively across the whole graph
59 int value = rule->recursiveCompare(a, b);
60
61 if (value != 0) {
62 return value;
63 }
64 }
65
66 return 0;
67 }
68
69 private:
70 void add(SequenceRule *rule) {
71 PRECONDITION(rule != nullptr, "null rule provided");
72 d_rules.push_back(rule);
73 rule->setSorter(new Sort(d_rules));
74 }
75
76 std::vector<const SequenceRule *> d_rules;
77};
78
79} // namespace CIPLabeler
80} // namespace RDKit
#define PRECONDITION(expr, mess)
Definition Invariant.h:108
~Rules() override
Definition Rules.h:32
int getComparision(const Edge *a, const Edge *b, bool) const override
Definition Rules.h:53
Rules(std::initializer_list< SequenceRule * > &&rules)
Definition Rules.h:26
int getNumSubRules() const
Definition Rules.h:38
int compare(const Edge *o1, const Edge *o2) const override
Definition Rules.h:40
void setSorter(const Sort *sorter)
Std stuff.