RDKit
Open-source cheminformatics and machine learning.
Loading...
Searching...
No Matches
ReactionPickler.h
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Greg Landrum
3// Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
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#include <RDGeneral/export.h>
12#ifndef RD_RXNPICKLE_H_2JUNE2009
13#define RD_RXNPICKLE_H_2JUNE2009
14
15#include <GraphMol/MolPickler.h>
16// Std stuff
17#include <string>
18#include <exception>
19#ifdef WIN32
20#include <ios>
21#endif
22
23namespace RDKit {
25
26//! used to indicate exceptions whilst pickling (serializing) reactions
28 : public std::exception {
29 public:
30 ReactionPicklerException(const char *msg) : _msg(msg) {}
31 ReactionPicklerException(const std::string msg) : _msg(msg) {}
32 const char *what() const noexcept override { return _msg.c_str(); }
33 ~ReactionPicklerException() noexcept override = default;
34
35 private:
36 std::string _msg;
37};
38
39//! handles pickling (serializing) reactions
41 public:
42 static const std::int32_t versionMajor; //!< mark the pickle version
43 static const std::int32_t versionMinor; //!< mark the pickle version
44 static const std::int32_t versionPatch; //!< mark the pickle version
45 static const std::int32_t endianId; //!< mark the endian-ness of the pickle
46
47 //! the pickle format is tagged using these tags:
48 //! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM,
49 //! otherwise you will break old pickles.
64
65 //! pickles a reaction and sends the results to stream \c ss
66 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
67 unsigned int propertyFlags);
68 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
69 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
71 }
72 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
73 unsigned int propertyFlags) {
74 ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
75 }
76 //! pickles a reaction and adds the results to string \c res
77 static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
78 unsigned int propertyFlags);
79 static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
80 static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
82 }
83 static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
84 unsigned int propertyFlags) {
85 ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
86 }
87
88 //! constructs a reaction from a pickle stored in a
89 //! string
90 static void reactionFromPickle(const std::string &pickle,
91 ChemicalReaction *rxn);
92 static void reactionFromPickle(const std::string &pickle,
93 ChemicalReaction &rxn) {
95 }
96
97 //! constructs a reaction from a pickle stored in a
98 //! stream
99 static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
100 static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
102 }
103
104 private:
105 //! do the actual work of pickling a reaction
106 static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
107 unsigned int propertyFlags);
108
109 //! do the actual work of de-pickling a reaction
110 static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
111
112 //! pickle standard properties
113 static void _pickleProperties(std::ostream &ss, const RDProps &props,
114 unsigned int pickleFlags);
115 //! unpickle standard properties
116 static void _unpickleProperties(std::istream &ss, RDProps &props);
117};
118}; // namespace RDKit
119
120#endif
This is a class for storing and applying general chemical reactions.
Definition Reaction.h:121
~ReactionPicklerException() noexcept override=default
const char * what() const noexcept override
ReactionPicklerException(const char *msg)
ReactionPicklerException(const std::string msg)
handles pickling (serializing) reactions
static const std::int32_t endianId
mark the endian-ness of the pickle
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss, unsigned int propertyFlags)
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
static const std::int32_t versionMajor
mark the pickle version
static void pickleReaction(const ChemicalReaction *rxn, std::string &res)
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
static void pickleReaction(const ChemicalReaction &rxn, std::string &res, unsigned int propertyFlags)
static const std::int32_t versionPatch
mark the pickle version
static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn)
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss, unsigned int propertyFlags)
pickles a reaction and sends the results to stream ss
static const std::int32_t versionMinor
mark the pickle version
static void pickleReaction(const ChemicalReaction *rxn, std::string &res, unsigned int propertyFlags)
pickles a reaction and adds the results to string res
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss)
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
#define RDKIT_CHEMREACTIONS_EXPORT
Definition export.h:57
Std stuff.