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 <vector>
22 #include <exception>
23 
24 namespace RDKit {
25 
26 //! class for flagging sanitization errors
27 class RDKIT_GRAPHMOL_EXPORT MolSanitizeException : public std::exception {
28  public:
MolSanitizeException(const char * msg)29   MolSanitizeException(const char *msg) : d_msg(msg){};
MolSanitizeException(const std::string & msg)30   MolSanitizeException(const std::string &msg) : d_msg(msg){};
MolSanitizeException(const MolSanitizeException & other)31   MolSanitizeException(const MolSanitizeException &other)
32       : d_msg(other.d_msg){};
what()33   virtual const char *what() const noexcept override { return d_msg.c_str(); };
~MolSanitizeException()34   virtual ~MolSanitizeException() noexcept {};
copy()35   virtual MolSanitizeException *copy() const {
36     return new MolSanitizeException(*this);
37   };
getType()38   virtual std::string getType() const { return "MolSanitizeException"; };
39 
40  protected:
41   std::string d_msg;
42 };
43 
44 class RDKIT_GRAPHMOL_EXPORT AtomSanitizeException
45     : public MolSanitizeException {
46  public:
AtomSanitizeException(const char * msg,unsigned int atomIdx)47   AtomSanitizeException(const char *msg, unsigned int atomIdx)
48       : MolSanitizeException(msg), d_atomIdx(atomIdx){};
AtomSanitizeException(const std::string & msg,unsigned int atomIdx)49   AtomSanitizeException(const std::string &msg, unsigned int atomIdx)
50       : MolSanitizeException(msg), d_atomIdx(atomIdx){};
AtomSanitizeException(const AtomSanitizeException & other)51   AtomSanitizeException(const AtomSanitizeException &other)
52       : MolSanitizeException(other), d_atomIdx(other.d_atomIdx){};
getAtomIdx()53   unsigned int getAtomIdx() const { return d_atomIdx; };
~AtomSanitizeException()54   virtual ~AtomSanitizeException() noexcept {};
copy()55   virtual MolSanitizeException *copy() const {
56     return new AtomSanitizeException(*this);
57   };
getType()58   virtual std::string getType() const { return "AtomSanitizeException"; };
59 
60  protected:
61   unsigned int d_atomIdx;
62 };
63 
64 class RDKIT_GRAPHMOL_EXPORT AtomValenceException
65     : public AtomSanitizeException {
66  public:
AtomValenceException(const char * msg,unsigned int atomIdx)67   AtomValenceException(const char *msg, unsigned int atomIdx)
68       : AtomSanitizeException(msg, atomIdx){};
AtomValenceException(const std::string & msg,unsigned int atomIdx)69   AtomValenceException(const std::string &msg, unsigned int atomIdx)
70       : AtomSanitizeException(msg, atomIdx){};
AtomValenceException(const AtomValenceException & other)71   AtomValenceException(const AtomValenceException &other)
72       : AtomSanitizeException(other){};
~AtomValenceException()73   virtual ~AtomValenceException() noexcept {};
copy()74   MolSanitizeException *copy() const {
75     return new AtomValenceException(*this);
76   };
getType()77   std::string getType() const { return "AtomValenceException"; };
78 };
79 
80 class RDKIT_GRAPHMOL_EXPORT AtomKekulizeException
81     : public AtomSanitizeException {
82  public:
AtomKekulizeException(const char * msg,unsigned int atomIdx)83   AtomKekulizeException(const char *msg, unsigned int atomIdx)
84       : AtomSanitizeException(msg, atomIdx){};
AtomKekulizeException(const std::string & msg,unsigned int atomIdx)85   AtomKekulizeException(const std::string &msg, unsigned int atomIdx)
86       : AtomSanitizeException(msg, atomIdx){};
AtomKekulizeException(const AtomKekulizeException & other)87   AtomKekulizeException(const AtomKekulizeException &other)
88       : AtomSanitizeException(other){};
~AtomKekulizeException()89   virtual ~AtomKekulizeException() noexcept {};
copy()90   MolSanitizeException *copy() const {
91     return new AtomKekulizeException(*this);
92   };
getType()93   std::string getType() const { return "AtomKekulizeException"; };
94 };
95 
96 class RDKIT_GRAPHMOL_EXPORT KekulizeException : public MolSanitizeException {
97  public:
KekulizeException(const char * msg,const std::vector<unsigned int> & indices)98   KekulizeException(const char *msg, const std::vector<unsigned int> &indices)
99       : MolSanitizeException(msg), d_atomIndices(indices){};
KekulizeException(const std::string & msg,const std::vector<unsigned int> & indices)100   KekulizeException(const std::string &msg,
101                     const std::vector<unsigned int> &indices)
102       : MolSanitizeException(msg), d_atomIndices(indices){};
KekulizeException(const KekulizeException & other)103   KekulizeException(const KekulizeException &other)
104       : MolSanitizeException(other), d_atomIndices(other.d_atomIndices){};
getAtomIndices()105   const std::vector<unsigned int> &getAtomIndices() const {
106     return d_atomIndices;
107   };
~KekulizeException()108   virtual ~KekulizeException() noexcept {};
copy()109   MolSanitizeException *copy() const { return new KekulizeException(*this); };
getType()110   std::string getType() const { return "KekulizeException"; };
111 
112  protected:
113   std::vector<unsigned int> d_atomIndices;
114 };
115 
116 }  // namespace RDKit
117 
118 #endif
119