RDKit: ReactionPickler.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 #ifndef _RD_RXNPICKLE_H_2JUNE2009_
12 #define _RD_RXNPICKLE_H_2JUNE2009_
13
14 // Std stuff
15 #include <iostream>
16 #include <string>
17 #include <exception>
18 #ifdef WIN32
19 #include <ios>
20 #endif
21
22 namespace RDKit {
23 class ChemicalReaction;
24
25 //! used to indicate exceptions whilst pickling (serializing) reactions
26 class ReactionPicklerException : public std::exception {
27 public:
28 ReactionPicklerException(const char *msg) : _msg(msg){};
29 ReactionPicklerException(const std::string msg) : _msg(msg){};
30 const char *message() const { return _msg.c_str(); };
31 ~ReactionPicklerException() throw(){};
32
33 private:
34 std::string _msg;
35 };
36
37 //! handles pickling (serializing) reactions
38 class ReactionPickler {
39 public:
40 static const boost::int32_t versionMajor, versionMinor,
41 versionPatch; //!< mark the pickle version
42 static const boost::int32_t endianId; //! mark the endian-ness of the pickle
43
44 //! the pickle format is tagged using these tags:
45 //! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM,
46 // otherwise
47 //! you will break old pickles.
48 typedef enum {
49 VERSION = 10000,
50 BEGINREACTANTS,
51 ENDREACTANTS,
52 BEGINPRODUCTS,
53 ENDPRODUCTS,
54 BEGINAGENTS,
55 ENDAGENTS,
56 ENDREACTION,
57 } Tags;
58
59 //! pickles a reaction and sends the results to stream \c ss
60 static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
61 static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
62 ReactionPickler::pickleReaction(&rxn, ss);
63 };
64 //! pickles a reaction and adds the results to string \c res
65 static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
66 static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
67 ReactionPickler::pickleReaction(&rxn, res);
68 };
69
70 //! constructs a reaction from a pickle stored in a string
71 static void reactionFromPickle(const std::string &pickle,
72 ChemicalReaction *rxn);
73 static void reactionFromPickle(const std::string &pickle,
74 ChemicalReaction &rxn) {
75 ReactionPickler::reactionFromPickle(pickle, &rxn);
76 };
77
78 //! constructs a reaction from a pickle stored in a stream
79 static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
80 static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
81 ReactionPickler::reactionFromPickle(ss, &rxn);
82 };
83
84 private:
85 //! do the actual work of pickling a reaction
86 static void _pickle(const ChemicalReaction *rxn, std::ostream &ss);
87
88 //! do the actual work of de-pickling a reaction
89 static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);
90 };
91 };
92
93 #endif
RDCatalog::versionMinor
const int versionMinor
Definition: Catalog.h:32
RDKit::ReactionPickler::ENDREACTANTS
Definition: ReactionPickler.h:51
RDKit::ReactionPicklerException::message
const char * message() const
Definition: ReactionPickler.h:30
RDKit::ReactionPickler::versionPatch
static const boost::int32_t versionPatch
mark the pickle version
Definition: ReactionPickler.h:40
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
Definition: ReactionPickler.h:61
RDKit::ChemicalReaction
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:116
RDKit::ReactionPicklerException::ReactionPicklerException
ReactionPicklerException(const std::string msg)
Definition: ReactionPickler.h:29
RDKit::ReactionPicklerException
used to indicate exceptions whilst pickling (serializing) reactions
Definition: ReactionPickler.h:26
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
constructs a reaction from a pickle stored in a string
RDKit::ReactionPickler::ENDREACTION
Definition: ReactionPickler.h:56
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
Definition: ReactionPickler.h:73
RDKit::ReactionPickler::BEGINREACTANTS
Definition: ReactionPickler.h:50
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::ReactionPickler::BEGINAGENTS
Definition: ReactionPickler.h:54
RDKit::ReactionPickler::Tags
Tags
mark the endian-ness of the pickle
Definition: ReactionPickler.h:48
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
Definition: ReactionPickler.h:66
RDKit::ReactionPickler::endianId
static const boost::int32_t endianId
Definition: ReactionPickler.h:42
RDKit::ReactionPickler::reactionFromPickle
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
Definition: ReactionPickler.h:80
RDKit::ReactionPickler::ENDPRODUCTS
Definition: ReactionPickler.h:53
RDCatalog::versionMajor
const int versionMajor
Definition: Catalog.h:31
RDKit::ReactionPicklerException::~ReactionPicklerException
~ReactionPicklerException()
Definition: ReactionPickler.h:31
RDKit::ReactionPickler::ENDAGENTS
Definition: ReactionPickler.h:55
RDKit::ReactionPickler
handles pickling (serializing) reactions
Definition: ReactionPickler.h:38
RDKit::ReactionPicklerException::ReactionPicklerException
ReactionPicklerException(const char *msg)
Definition: ReactionPickler.h:28
RDKit::ReactionPickler::pickleReaction
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss)
pickles a reaction and sends the results to stream ss
RDKit::ReactionPickler::BEGINPRODUCTS
Definition: ReactionPickler.h:52
RDKit::EnumerationStrategyPickler::pickle
void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss