Coverage Report

Created: 2026-11-12 07:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rdkit/Code/Query/RangeQuery.h
Line
Count
Source
1
//
2
// Copyright (c) 2003-2020 Greg Landrum and Rational Discovery LLC
3
//
4
//   @@ All Rights Reserved @@
5
//  This file is part of the RDKit.
6
//  The contents are covered by the terms of the BSD license
7
//  which is included in the file license.txt, found at the root
8
//  of the RDKit source tree.
9
//
10
#include <RDGeneral/export.h>
11
#ifndef RD_RANGEQUERY_H
12
#define RD_RANGEQUERY_H
13
#include "Query.h"
14
#include <utility>
15
16
namespace Queries {
17
18
//! \brief a Query implementing a range: arguments must
19
//!  fall in a particular range of values.
20
//!
21
//!  The ends of the range default to be open, but they can
22
//!  individually set to be closed.
23
//!
24
//!  There is also an optional tolerance to be used in comparisons
25
template <class MatchFuncArgType, class DataFuncArgType = MatchFuncArgType,
26
          bool needsConversion = false>
27
class RDKIT_QUERY_EXPORT RangeQuery
28
    : public Query<MatchFuncArgType, DataFuncArgType, needsConversion> {
29
 public:
30
29.8k
  RangeQuery() : d_upper(0), d_lower(0) { this->df_negate = false; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::RangeQuery()
Line
Count
Source
30
3.02k
  RangeQuery() : d_upper(0), d_lower(0) { this->df_negate = false; }
Queries::RangeQuery<int, RDKit::Bond const*, true>::RangeQuery()
Line
Count
Source
30
26.8k
  RangeQuery() : d_upper(0), d_lower(0) { this->df_negate = false; }
31
  //! construct and set the lower and upper bounds
32
  RangeQuery(MatchFuncArgType lower, MatchFuncArgType upper)
33
1.58k
      : d_upper(upper), d_lower(lower), df_upperOpen(true), df_lowerOpen(true) {
34
1.58k
    this->df_negate = false;
35
1.58k
  }
Queries::RangeQuery<int, RDKit::Atom const*, true>::RangeQuery(int, int)
Line
Count
Source
33
1.29k
      : d_upper(upper), d_lower(lower), df_upperOpen(true), df_lowerOpen(true) {
34
1.29k
    this->df_negate = false;
35
1.29k
  }
Queries::RangeQuery<int, RDKit::Bond const*, true>::RangeQuery(int, int)
Line
Count
Source
33
286
      : d_upper(upper), d_lower(lower), df_upperOpen(true), df_lowerOpen(true) {
34
286
    this->df_negate = false;
35
286
  }
36
37
  //! sets our upper bound
38
29.8k
  void setUpper(MatchFuncArgType what) { this->d_upper = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setUpper(int)
Line
Count
Source
38
3.02k
  void setUpper(MatchFuncArgType what) { this->d_upper = what; }
Queries::RangeQuery<int, RDKit::Bond const*, true>::setUpper(int)
Line
Count
Source
38
26.8k
  void setUpper(MatchFuncArgType what) { this->d_upper = what; }
39
  //! returns our upper bound
40
0
  const MatchFuncArgType getUpper() const { return this->d_upper; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::getUpper() const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::getUpper() const
41
  //! sets our lower bound
42
29.8k
  void setLower(MatchFuncArgType what) { this->d_lower = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setLower(int)
Line
Count
Source
42
3.02k
  void setLower(MatchFuncArgType what) { this->d_lower = what; }
Queries::RangeQuery<int, RDKit::Bond const*, true>::setLower(int)
Line
Count
Source
42
26.8k
  void setLower(MatchFuncArgType what) { this->d_lower = what; }
43
  //! returns our lower bound
44
0
  const MatchFuncArgType getLower() const { return this->d_lower; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::getLower() const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::getLower() const
45
46
  //! sets whether or not the ends of the range are open
47
31.4k
  void setEndsOpen(bool lower, bool upper) {
48
31.4k
    this->df_lowerOpen = lower;
49
31.4k
    this->df_upperOpen = upper;
50
31.4k
  }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setEndsOpen(bool, bool)
Line
Count
Source
47
4.31k
  void setEndsOpen(bool lower, bool upper) {
48
4.31k
    this->df_lowerOpen = lower;
49
4.31k
    this->df_upperOpen = upper;
50
4.31k
  }
Queries::RangeQuery<int, RDKit::Bond const*, true>::setEndsOpen(bool, bool)
Line
Count
Source
47
27.1k
  void setEndsOpen(bool lower, bool upper) {
48
27.1k
    this->df_lowerOpen = lower;
49
27.1k
    this->df_upperOpen = upper;
50
27.1k
  }
51
  //! returns the state of our ends (open or not)
52
0
  std::pair<bool, bool> getEndsOpen() const {
53
0
    return std::make_pair(this->df_lowerOpen, this->df_upperOpen);
54
0
  }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::getEndsOpen() const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::getEndsOpen() const
55
56
  //! sets our tolerance
57
29.8k
  void setTol(MatchFuncArgType what) { this->d_tol = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setTol(int)
Line
Count
Source
57
3.02k
  void setTol(MatchFuncArgType what) { this->d_tol = what; }
Queries::RangeQuery<int, RDKit::Bond const*, true>::setTol(int)
Line
Count
Source
57
26.8k
  void setTol(MatchFuncArgType what) { this->d_tol = what; }
58
  //! returns our tolerance
59
0
  const MatchFuncArgType getTol() const { return this->d_tol; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::getTol() const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::getTol() const
60
61
0
  bool Match(const DataFuncArgType what) const override {
62
0
    MatchFuncArgType mfArg =
63
0
        this->TypeConvert(what, Int2Type<needsConversion>());
64
0
    int lCmp = queryCmp(this->d_lower, mfArg, this->d_tol);
65
0
    int uCmp = queryCmp(this->d_upper, mfArg, this->d_tol);
66
0
    bool lowerRes, upperRes;
67
0
    if (this->df_lowerOpen) {
68
0
      lowerRes = lCmp < 0;
69
0
    } else {
70
0
      lowerRes = lCmp <= 0;
71
0
    }
72
0
    if (this->df_upperOpen) {
73
0
      upperRes = uCmp > 0;
74
0
    } else {
75
0
      upperRes = uCmp >= 0;
76
0
    }
77
78
0
    bool tempR = !(lowerRes && upperRes);
79
0
    if (this->getNegation()) {
80
0
      return tempR;
81
0
    } else {
82
0
      return !tempR;
83
0
    }
84
0
  }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::Match(RDKit::Atom const*) const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::Match(RDKit::Bond const*) const
85
86
  Query<MatchFuncArgType, DataFuncArgType, needsConversion> *copy()
87
29.8k
      const override {
88
29.8k
    RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
89
29.8k
        new RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
90
29.8k
    res->setUpper(this->d_upper);
91
29.8k
    res->setLower(this->d_lower);
92
29.8k
    res->setTol(this->d_tol);
93
29.8k
    res->setNegation(this->getNegation());
94
29.8k
    res->setEndsOpen(this->df_lowerOpen, this->df_upperOpen);
95
29.8k
    res->setDataFunc(this->d_dataFunc);
96
29.8k
    res->d_description = this->d_description;
97
29.8k
    res->d_queryType = this->d_queryType;
98
29.8k
    return res;
99
29.8k
  }
Queries::RangeQuery<int, RDKit::Atom const*, true>::copy() const
Line
Count
Source
87
3.02k
      const override {
88
3.02k
    RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
89
3.02k
        new RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
90
3.02k
    res->setUpper(this->d_upper);
91
3.02k
    res->setLower(this->d_lower);
92
3.02k
    res->setTol(this->d_tol);
93
3.02k
    res->setNegation(this->getNegation());
94
3.02k
    res->setEndsOpen(this->df_lowerOpen, this->df_upperOpen);
95
3.02k
    res->setDataFunc(this->d_dataFunc);
96
3.02k
    res->d_description = this->d_description;
97
3.02k
    res->d_queryType = this->d_queryType;
98
3.02k
    return res;
99
3.02k
  }
Queries::RangeQuery<int, RDKit::Bond const*, true>::copy() const
Line
Count
Source
87
26.8k
      const override {
88
26.8k
    RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
89
26.8k
        new RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
90
26.8k
    res->setUpper(this->d_upper);
91
26.8k
    res->setLower(this->d_lower);
92
26.8k
    res->setTol(this->d_tol);
93
26.8k
    res->setNegation(this->getNegation());
94
26.8k
    res->setEndsOpen(this->df_lowerOpen, this->df_upperOpen);
95
26.8k
    res->setDataFunc(this->d_dataFunc);
96
26.8k
    res->d_description = this->d_description;
97
26.8k
    res->d_queryType = this->d_queryType;
98
26.8k
    return res;
99
26.8k
  }
100
101
0
  std::string getFullDescription() const override {
102
0
    std::ostringstream res;
103
0
    res << this->getDescription();
104
0
    if (this->getNegation()) {
105
0
      res << " ! ";
106
0
    }
107
0
    res << " " << this->d_lower << " val " << this->d_upper;
108
0
    return res.str();
109
0
  }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Atom const*, true>::getFullDescription() const
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::getFullDescription() const
110
111
 protected:
112
  MatchFuncArgType d_upper, d_lower;
113
  bool df_upperOpen{true}, df_lowerOpen{true};
114
};
115
}  // namespace Queries
116
#endif