Coverage Report

Created: 2026-06-23 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rdkit/Code/GraphMol/SanitException.h
Line
Count
Source
1
//
2
//  Copyright (C) 2002-2019 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
11
#include <RDGeneral/export.h>
12
#ifndef RD_SANITEXCEPTION_H
13
#define RD_SANITEXCEPTION_H
14
15
#include <RDGeneral/types.h>
16
#include <GraphMol/GraphMol.h>
17
#include <GraphMol/Atom.h>
18
#include <GraphMol/Bond.h>
19
20
#include <string>
21
#include <utility>
22
#include <vector>
23
#include <exception>
24
25
namespace RDKit {
26
27
//! class for flagging sanitization errors
28
class RDKIT_GRAPHMOL_EXPORT MolSanitizeException : public std::exception {
29
 public:
30
0
  MolSanitizeException(const char *msg) : d_msg(msg) {}
31
5.99k
  MolSanitizeException(std::string msg) : d_msg(std::move(msg)) {}
32
  MolSanitizeException(const MolSanitizeException &other)
33
0
      : d_msg(other.d_msg) {}
34
0
  const char *what() const noexcept override { return d_msg.c_str(); }
35
5.99k
  ~MolSanitizeException() noexcept override {}
36
0
  virtual MolSanitizeException *copy() const {
37
0
    return new MolSanitizeException(*this);
38
0
  }
39
0
  virtual std::string getType() const { return "MolSanitizeException"; }
40
41
 protected:
42
  std::string d_msg;
43
};
44
45
class RDKIT_GRAPHMOL_EXPORT AtomSanitizeException
46
    : public MolSanitizeException {
47
 public:
48
  AtomSanitizeException(const char *msg, unsigned int atomIdx)
49
0
      : MolSanitizeException(msg), d_atomIdx(atomIdx) {}
50
  AtomSanitizeException(const std::string &msg, unsigned int atomIdx)
51
3.97k
      : MolSanitizeException(msg), d_atomIdx(atomIdx) {}
52
  AtomSanitizeException(const AtomSanitizeException &other)
53
0
      : MolSanitizeException(other), d_atomIdx(other.d_atomIdx) {}
54
0
  unsigned int getAtomIdx() const { return d_atomIdx; }
55
0
  ~AtomSanitizeException() noexcept override {}
56
0
  MolSanitizeException *copy() const override {
57
0
    return new AtomSanitizeException(*this);
58
0
  }
59
0
  std::string getType() const override { return "AtomSanitizeException"; }
60
61
 protected:
62
  unsigned int d_atomIdx;
63
};
64
65
class RDKIT_GRAPHMOL_EXPORT AtomValenceException
66
    : public AtomSanitizeException {
67
 public:
68
  AtomValenceException(const char *msg, unsigned int atomIdx)
69
0
      : AtomSanitizeException(msg, atomIdx) {}
70
  AtomValenceException(const std::string &msg, unsigned int atomIdx)
71
2.63k
      : AtomSanitizeException(msg, atomIdx) {}
72
  AtomValenceException(const AtomValenceException &other)
73
0
      : AtomSanitizeException(other) {}
74
0
  ~AtomValenceException() noexcept override {}
75
0
  MolSanitizeException *copy() const override {
76
0
    return new AtomValenceException(*this);
77
0
  }
78
0
  std::string getType() const override { return "AtomValenceException"; }
79
};
80
81
class RDKIT_GRAPHMOL_EXPORT AtomKekulizeException
82
    : public AtomSanitizeException {
83
 public:
84
  AtomKekulizeException(const char *msg, unsigned int atomIdx)
85
0
      : AtomSanitizeException(msg, atomIdx) {}
86
  AtomKekulizeException(const std::string &msg, unsigned int atomIdx)
87
1.33k
      : AtomSanitizeException(msg, atomIdx) {}
88
  AtomKekulizeException(const AtomKekulizeException &other)
89
0
      : AtomSanitizeException(other) {}
90
0
  ~AtomKekulizeException() noexcept override {}
91
0
  MolSanitizeException *copy() const override {
92
0
    return new AtomKekulizeException(*this);
93
0
  }
94
0
  std::string getType() const override { return "AtomKekulizeException"; }
95
};
96
97
class RDKIT_GRAPHMOL_EXPORT KekulizeException : public MolSanitizeException {
98
 public:
99
  KekulizeException(const char *msg, std::vector<unsigned int> indices)
100
0
      : MolSanitizeException(msg), d_atomIndices(std::move(indices)) {}
101
  KekulizeException(const std::string &msg, std::vector<unsigned int> indices)
102
2.02k
      : MolSanitizeException(msg), d_atomIndices(std::move(indices)) {}
103
  KekulizeException(const KekulizeException &other)
104
0
      : MolSanitizeException(other), d_atomIndices(other.d_atomIndices) {}
105
0
  const std::vector<unsigned int> &getAtomIndices() const {
106
0
    return d_atomIndices;
107
0
  }
108
2.02k
  ~KekulizeException() noexcept override {}
109
0
  MolSanitizeException *copy() const override {
110
0
    return new KekulizeException(*this);
111
0
  }
112
0
  std::string getType() const override { return "KekulizeException"; }
113
114
 protected:
115
  std::vector<unsigned int> d_atomIndices;
116
};
117
118
}  // namespace RDKit
119
120
#endif