STL Memory Versioning
segment.cpp
Go to the documentation of this file.
1 #include "segment.h"
2 #include "versioned.h"
3 #include "revision.h"
4 
5 int Segment::versionCount = 0;
6 
8  parent = nullptr;
9 
10  version = versionCount++;
11  refcount = 1;
12 }
13 
14 Segment::Segment(std::shared_ptr<Segment> my_parent) {
15  parent = my_parent;
16  if (parent)
17  parent->refcount++;
18 
19  version = versionCount++;
20  refcount = 1;
21 }
22 
24  if (--refcount == 0) {
25  for (auto &v: written) {
26  v->Release(shared_from_this());
27  }
28  if (parent != NULL)
29  parent->Release();
30  }
31 }
32 
33 void Segment::Collapse(std::shared_ptr<Revision> main) {
34  while (parent != main->root && parent->refcount == 1) {
35  for(auto &v : parent->written) {
36  v->Collapse(main, parent);
37  }
38  parent = parent->parent; // remove parent
39  }
40 }
void Release()
Release Segment when it's no longer needed.
Definition: segment.cpp:23
int refcount
Count of references for that Segment.
Definition: segment.h:66
int version
Version of that Segment.
Definition: segment.h:60
void Collapse(std::shared_ptr< Revision > main)
Compress branch of Segments into one Segment.
Definition: segment.cpp:33
std::list< VersionedI * > written
List of all Versioned variables that were changed.
Definition: segment.h:73
Segment()
Construct the very first Segment.
Definition: segment.cpp:7
std::shared_ptr< Segment > parent
Previous Segment.
Definition: segment.h:54
Implementation of the class Revision.
Implementation of the class Segment.
Implementation of the Versioned classes and interface.