File: ReactionPickler.h

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (118 lines) | stat: -rw-r--r-- 4,269 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
//  Copyright (C) 2009 Greg Landrum
//  Copyright (c) 2014, Novartis Institutes for BioMedical Research Inc.
//
//   @@ All Rights Reserved @@
//  This file is part of the RDKit.
//  The contents are covered by the terms of the BSD license
//  which is included in the file license.txt, found at the root
//  of the RDKit source tree.
//
#include <RDGeneral/export.h>
#ifndef RD_RXNPICKLE_H_2JUNE2009
#define RD_RXNPICKLE_H_2JUNE2009

#include <GraphMol/MolPickler.h>
// Std stuff
#include <iostream>
#include <string>
#include <exception>
#ifdef WIN32
#include <ios>
#endif

namespace RDKit {
class ChemicalReaction;

//! used to indicate exceptions whilst pickling (serializing) reactions
class RDKIT_CHEMREACTIONS_EXPORT ReactionPicklerException : public std::exception {
 public:
  ReactionPicklerException(const char *msg) : _msg(msg){};
  ReactionPicklerException(const std::string msg) : _msg(msg){};
  const char *message() const { return _msg.c_str(); };
  ~ReactionPicklerException() throw(){};

 private:
  std::string _msg;
};

//! handles pickling (serializing) reactions
class RDKIT_CHEMREACTIONS_EXPORT ReactionPickler {
 public:
  static const boost::int32_t versionMajor; //!< mark the pickle version
  static const boost::int32_t versionMinor; //!< mark the pickle version
  static const boost::int32_t versionPatch; //!< mark the pickle version
  static const boost::int32_t endianId;  //! mark the endian-ness of the pickle

  //! the pickle format is tagged using these tags:
  //! NOTE: if you add to this list, be sure to put new entries AT THE BOTTOM,
  //! otherwise you will break old pickles.
  typedef enum {
    VERSION = 10000,
    BEGINREACTANTS,
    ENDREACTANTS,
    BEGINPRODUCTS,
    ENDPRODUCTS,
    BEGINAGENTS,
    ENDAGENTS,
    ENDREACTION,
    BEGINPROPS,
    ENDPROPS
  } Tags;

  //! pickles a reaction and sends the results to stream \c ss
  static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss,
                             unsigned int propertyFlags);
  static void pickleReaction(const ChemicalReaction *rxn, std::ostream &ss);
  static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss) {
    ReactionPickler::pickleReaction(&rxn, ss);
  };
  static void pickleReaction(const ChemicalReaction &rxn, std::ostream &ss,
                             unsigned int propertyFlags) {
    ReactionPickler::pickleReaction(&rxn, ss, propertyFlags);
  };
  //! pickles a reaction and adds the results to string \c res
  static void pickleReaction(const ChemicalReaction *rxn, std::string &res,
                             unsigned int propertyFlags);
  static void pickleReaction(const ChemicalReaction *rxn, std::string &res);
  static void pickleReaction(const ChemicalReaction &rxn, std::string &res) {
    ReactionPickler::pickleReaction(&rxn, res);
  };
  static void pickleReaction(const ChemicalReaction &rxn, std::string &res,
                             unsigned int propertyFlags) {
    ReactionPickler::pickleReaction(&rxn, res, propertyFlags);
  };

  //! constructs a reaction from a pickle stored in a
  //! string
  static void reactionFromPickle(const std::string &pickle,
                                 ChemicalReaction *rxn);
  static void reactionFromPickle(const std::string &pickle,
                                 ChemicalReaction &rxn) {
    ReactionPickler::reactionFromPickle(pickle, &rxn);
  };

  //! constructs a reaction from a pickle stored in a
  //! stream
  static void reactionFromPickle(std::istream &ss, ChemicalReaction *rxn);
  static void reactionFromPickle(std::istream &ss, ChemicalReaction &rxn) {
    ReactionPickler::reactionFromPickle(ss, &rxn);
  };

 private:
  //! do the actual work of pickling a reaction
  static void _pickle(const ChemicalReaction *rxn, std::ostream &ss,
                      unsigned int propertyFlags);

  //! do the actual work of de-pickling a reaction
  static void _depickle(std::istream &ss, ChemicalReaction *rxn, int version);

  //! pickle standard properties
  static void _pickleProperties(std::ostream &ss, const RDProps &props,
                                unsigned int pickleFlags);
  //! unpickle standard properties
  static void _unpickleProperties(std::istream &ss, RDProps &props);
};
};

#endif