Coverage Report

Created: 2026-06-23 06:55

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
1.55k
  RangeQuery() : d_upper(0), d_lower(0) { this->df_negate = false; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::RangeQuery()
Line
Count
Source
30
1.55k
  RangeQuery() : d_upper(0), d_lower(0) { this->df_negate = false; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::RangeQuery()
31
  //! construct and set the lower and upper bounds
32
  RangeQuery(MatchFuncArgType lower, MatchFuncArgType upper)
33
795
      : d_upper(upper), d_lower(lower), df_upperOpen(true), df_lowerOpen(true) {
34
795
    this->df_negate = false;
35
795
  }
36
37
  //! sets our upper bound
38
1.55k
  void setUpper(MatchFuncArgType what) { this->d_upper = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setUpper(int)
Line
Count
Source
38
1.55k
  void setUpper(MatchFuncArgType what) { this->d_upper = what; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::setUpper(int)
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
1.55k
  void setLower(MatchFuncArgType what) { this->d_lower = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setLower(int)
Line
Count
Source
42
1.55k
  void setLower(MatchFuncArgType what) { this->d_lower = what; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::setLower(int)
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
2.34k
  void setEndsOpen(bool lower, bool upper) {
48
2.34k
    this->df_lowerOpen = lower;
49
2.34k
    this->df_upperOpen = upper;
50
2.34k
  }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setEndsOpen(bool, bool)
Line
Count
Source
47
2.34k
  void setEndsOpen(bool lower, bool upper) {
48
2.34k
    this->df_lowerOpen = lower;
49
2.34k
    this->df_upperOpen = upper;
50
2.34k
  }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::setEndsOpen(bool, bool)
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
1.55k
  void setTol(MatchFuncArgType what) { this->d_tol = what; }
Queries::RangeQuery<int, RDKit::Atom const*, true>::setTol(int)
Line
Count
Source
57
1.55k
  void setTol(MatchFuncArgType what) { this->d_tol = what; }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::setTol(int)
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
1.55k
      const override {
88
1.55k
    RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
89
1.55k
        new RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
90
1.55k
    res->setUpper(this->d_upper);
91
1.55k
    res->setLower(this->d_lower);
92
1.55k
    res->setTol(this->d_tol);
93
1.55k
    res->setNegation(this->getNegation());
94
1.55k
    res->setEndsOpen(this->df_lowerOpen, this->df_upperOpen);
95
1.55k
    res->setDataFunc(this->d_dataFunc);
96
1.55k
    res->d_description = this->d_description;
97
1.55k
    res->d_queryType = this->d_queryType;
98
1.55k
    return res;
99
1.55k
  }
Queries::RangeQuery<int, RDKit::Atom const*, true>::copy() const
Line
Count
Source
87
1.55k
      const override {
88
1.55k
    RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion> *res =
89
1.55k
        new RangeQuery<MatchFuncArgType, DataFuncArgType, needsConversion>();
90
1.55k
    res->setUpper(this->d_upper);
91
1.55k
    res->setLower(this->d_lower);
92
1.55k
    res->setTol(this->d_tol);
93
1.55k
    res->setNegation(this->getNegation());
94
1.55k
    res->setEndsOpen(this->df_lowerOpen, this->df_upperOpen);
95
1.55k
    res->setDataFunc(this->d_dataFunc);
96
1.55k
    res->d_description = this->d_description;
97
1.55k
    res->d_queryType = this->d_queryType;
98
1.55k
    return res;
99
1.55k
  }
Unexecuted instantiation: Queries::RangeQuery<int, RDKit::Bond const*, true>::copy() const
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