Molassembler  3.0.0
Molecule graph and conformer library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Serialization.h
Go to the documentation of this file.
1 
8 #ifndef INCLUDE_MOLASSEMBLER_SERIALIZATION_H
9 #define INCLUDE_MOLASSEMBLER_SERIALIZATION_H
10 
11 #include <cstdint>
12 #include <vector>
13 #include <string>
14 #include <memory>
15 
16 #include "Molassembler/Export.h"
17 
18 namespace Scine {
19 namespace Molassembler {
20 
21 // Forward-declarations
22 class Molecule;
23 
79 class MASM_EXPORT JsonSerialization {
80 public:
84  using BinaryType = std::vector<std::uint8_t>;
85 
87  enum class BinaryFormat {
88  CBOR,
89  BSON,
90  MsgPack,
91  UBJSON
92  };
94 
97  static std::string base64Encode(const BinaryType& binary);
98  static BinaryType base64Decode(const std::string& base64String);
104  static bool base64EqualMolecules(const std::string& stringA, const std::string& stringB,
105  BinaryFormat binaryFormat = BinaryFormat::CBOR);
114  static bool equalDecisionLists(const std::string& listStringA, const std::string& listStringB);
116 
119  JsonSerialization(JsonSerialization&& other) noexcept;
120  JsonSerialization& operator = (JsonSerialization&& other) noexcept;
121  JsonSerialization(const JsonSerialization& other);
122  JsonSerialization& operator = (const JsonSerialization& other);
125 
128  JsonSerialization() = delete;
130  explicit JsonSerialization(const std::string& jsonString);
132  explicit JsonSerialization(const Molecule& molecule);
134  JsonSerialization(const BinaryType& binary, BinaryFormat format);
136 
140  operator std::string() const;
142  operator Molecule() const;
144  BinaryType toBinary(BinaryFormat format) const;
146 
149 
167  JsonSerialization& standardize();
169 
170 private:
171  struct Impl;
172  std::unique_ptr<Impl> pImpl_;
173  static std::vector<std::tuple<int, int, int, int> > unpackDecisionListString(const std::string& listString);
174  static std::tuple<int, int, int, int> canonicalizeDecisionListElement(const std::tuple<int, int, int, int>& decisionListElement);
175  static bool equalVersions(const std::vector<unsigned> versionA, const std::vector<unsigned> versionB);
176  static std::vector<std::string> splitBase64StringIntoMoleculeStrings(std::string base64String);
177  static bool compareMoleculeDecisionList(const std::vector<std::tuple<int, int, int, int>>& listA,
178  const std::vector<std::tuple<int, int, int, int>>& listB);
179 
180 };
181 
182 } // namespace Molassembler
183 } // namespace Scine
184 
185 #endif
Models a molecule as a graph (connectivity of atoms) and a list of stereopermutators.
Definition: Molecule.h:77
BinaryFormat
Binary formats that JSON can be encoded into and decoded from.
Definition: Serialization.h:87
Class representing a compact JSON serialization of a molecule.
Definition: Serialization.h:79
std::vector< std::uint8_t > BinaryType
Type used to represent binary JSON formats.
Definition: Serialization.h:84