Atoms Crowd  7.0.0
Serialiser.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsCore/Globals.h>
11 #include <AtomsCore/AtomsMath.h>
12 #include <AtomsCore/MemoryUtils.h>
13 #include <AtomsCore/Hash.h>
14 #include <string>
15 #include <vector>
16 #include <cassert>
17 #include <cstdio>
18 
19 namespace AtomsCore
20 {
21  // Forward declaration
22  class Metadata;
23 
25 
28  class ATOMSCORE_EXPORT Archive
29  {
30  public:
31 
32  enum Tags
33  {
34  kNone = 0,
35  kCompress = 1,
36  kRandomAccessCompress = 2,
37  kMultithread = 4
38  };
39 
42 
44 
51  Archive(size_t len, size_t tag = kNone);
52 
54 
57 
59 
63  bool writeToFile(const std::string& fileName);
64 
66 
70  bool readFromFile(const std::string& fileName);
71 
73  void reset();
74 
76  void clear();
77 
79  void resize(size_t len);
80 
82 
86  std::string encodeBase64(bool compress = false);
87 
89 
93  bool decodeBase64(const std::string& stringValue);
94 
95  public:
96 
98  unsigned char* buffer;
99 
101 
103  size_t index;
104 
106  size_t size;
107 
109  size_t version;
110 
112  std::string headerString;
113 
115  size_t tags;
116 
118 
121 
122  private:
123 
125  Archive(const Archive&);
126 
128  Archive& operator=(const Archive&);
129  };
130 }
131 
132 namespace AtomsCore
133 {
135  ATOMSCORE_EXPORT AtomsCore::Archive& operator<<(AtomsCore::Archive& os, const AtomsCore::Archive& ark);
136 }
137 
138 #include "Serialiser.impl.h"
Archive class.
Definition: Serialiser.h:29
void clear()
Clears the binary stream.
size_t index
Current binary stream index.
Definition: Serialiser.h:103
Archive(size_t len, size_t tag=kNone)
Constructor.
size_t size
Memory size of the binary stream.
Definition: Serialiser.h:106
Archive()
Constructor.
void resize(size_t len)
Resize buffer.
bool decodeBase64(const std::string &stringValue)
Reads a base64 string and store inside the binary stream.
bool writeToFile(const std::string &fileName)
Writes binary stream to a file.
~Archive()
Destructor.
unsigned char * buffer
Binary stream.
Definition: Serialiser.h:98
bool readFromFile(const std::string &fileName)
Reads a file and store inside the binary stream.
std::string headerString
Header string.
Definition: Serialiser.h:112
size_t version
Archive serialization version.
Definition: Serialiser.h:109
std::string encodeBase64(bool compress=false)
Encode the binary stream in base 64.
size_t tags
Flags.
Definition: Serialiser.h:115
bool autoDelete
Autodelete flag.
Definition: Serialiser.h:120
void reset()
Resets the index pointer of the archive.
AtomsCore namespace.
Definition: Agent.h:344