Molassembler  2.0.1
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 <vector>
12 #include <string>
13 #include <memory>
14 
15 #include "Molassembler/Export.h"
16 
17 namespace Scine {
18 namespace Molassembler {
19 
20 // Forward-declarations
21 class Molecule;
22 
78 class MASM_EXPORT JsonSerialization {
79 public:
83  using BinaryType = std::vector<std::uint8_t>;
84 
86  enum class BinaryFormat {
87  CBOR,
88  BSON,
89  MsgPack,
90  UBJSON
91  };
93 
96  static std::string base64Encode(const BinaryType& binary);
97  static BinaryType base64Decode(const std::string& base64String);
103  static bool base64EqualMolecules(const std::string& stringA, const std::string& stringB,
104  BinaryFormat binaryFormat = BinaryFormat::CBOR);
113  static bool equalDecisionLists(const std::string& listStringA, const std::string& listStringB);
115 
118  JsonSerialization(JsonSerialization&& other) noexcept;
119  JsonSerialization& operator = (JsonSerialization&& other) noexcept;
120  JsonSerialization(const JsonSerialization& other);
121  JsonSerialization& operator = (const JsonSerialization& other);
124 
127  JsonSerialization() = delete;
129  explicit JsonSerialization(const std::string& jsonString);
131  explicit JsonSerialization(const Molecule& molecule);
133  JsonSerialization(const BinaryType& binary, BinaryFormat format);
135 
139  operator std::string() const;
141  operator Molecule() const;
143  BinaryType toBinary(BinaryFormat format) const;
145 
148 
166  JsonSerialization& standardize();
168 
169 private:
170  struct Impl;
171  std::unique_ptr<Impl> pImpl_;
172  static std::vector<std::tuple<int, int, int, int> > unpackDecisionListString(const std::string& listString);
173  static std::tuple<int, int, int, int> canonicalizeDecisionListElement(const std::tuple<int, int, int, int>& decisionListElement);
174  static bool equalVersions(const std::vector<unsigned> versionA, const std::vector<unsigned> versionB);
175  static std::vector<std::string> splitBase64StringIntoMoleculeStrings(std::string base64String);
176  static bool compareMoleculeDecisionList(const std::vector<std::tuple<int, int, int, int>>& listA,
177  const std::vector<std::tuple<int, int, int, int>>& listB);
178 
179 };
180 
181 } // namespace Molassembler
182 } // namespace Scine
183 
184 #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:86
Class representing a compact JSON serialization of a molecule.
Definition: Serialization.h:78
std::vector< std::uint8_t > BinaryType
Type used to represent binary JSON formats.
Definition: Serialization.h:83