Libftpp
A modern C++ library
memento.cpp
Go to the documentation of this file.
1 #include "memento.hpp"
2 
4 {
5  Snapshot snap;
6  this->_saveToSnapshot(snap);
7  return snap;
8 }
9 
11 {
12  _cursor = 0;
13 }
14 
15 void Memento::load(const Memento::Snapshot& state)
16 {
17  Snapshot tmp = state;
18  tmp.reset();
19  this->_loadFromSnapshot(tmp);
20 }
21 
23 {
24  size_t size = value.length();
25  *this << size;
26  _buffer.insert(_buffer.end(), value.begin(), value.end());
27  return *this;
28 }
29 
31 {
32  size_t size;
33  *this >> size;
34  if (size + _cursor > _buffer.size())
35  throw std::runtime_error("Read out of Buffer !");
36 
37  value.assign(_buffer.begin() + _cursor, _buffer.begin() + _cursor + size);
38 
39  _cursor += size;
40  return *this;
41 }
Snapshot operator>>(T &value)
Definition: memento.hpp:69
Snapshot & operator<<(const T &value)
Definition: memento.hpp:60
void load(const Memento::Snapshot &state)
Definition: memento.cpp:15
Snapshot save()
Definition: memento.cpp:3