RDKit
Open-source cheminformatics and machine learning.
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(); };
32 
33  private:
34  std::string _msg;
35 };
36 
37 //! handles pickling (serializing) reactions
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,
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) {
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) {
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) {
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) {
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
const int versionMinor
Definition: Catalog.h:32
const char * message() const
static const boost::int32_t versionPatch
mark the pickle version
static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss)
This is a class for storing and applying general chemical reactions.
Definition: Reaction.h:116
ReactionPicklerException(const std::string msg)
used to indicate exceptions whilst pickling (serializing) reactions
static void reactionFromPickle(const std::string &pickle, ChemicalReaction *rxn)
constructs a reaction from a pickle stored in a string
static void reactionFromPickle(const std::string &pickle, ChemicalReaction &rxn)
Std stuff.
Definition: Atom.h:29
Tags
mark the endian-ness of the pickle
static void pickleReaction(const ChemicalReaction &rxn, std::string &res)
static const boost::int32_t endianId
static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn)
const int versionMajor
Definition: Catalog.h:31
handles pickling (serializing) reactions
ReactionPicklerException(const char *msg)
static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss)
pickles a reaction and sends the results to stream ss
void pickle(const boost::shared_ptr< EnumerationStrategyBase > &enumerator, std::ostream &ss)
pickles a EnumerationStrategy and adds the results to a stream ss