STL Memory Versioning
Public Member Functions | Public Attributes | List of all members
Segment Class Reference

Class to keep track what Versioned variables were changed. More...

#include <segment.h>

Inheritance diagram for Segment:
Inheritance graph
[legend]
Collaboration diagram for Segment:
Collaboration graph
[legend]

Public Member Functions

 Segment ()
 Construct the very first Segment. More...
 
 Segment (std::shared_ptr< Segment > parent)
 Construct a new Segment object. More...
 
void Release ()
 Release Segment when it's no longer needed. More...
 
void Collapse (std::shared_ptr< Revision > main)
 Compress branch of Segments into one Segment. More...
 

Public Attributes

std::shared_ptr< Segment > parent
 Previous Segment. More...
 
int version
 Version of that Segment. More...
 
int refcount
 Count of references for that Segment. More...
 
std::list< VersionedI * > written
 List of all Versioned variables that were changed. More...
 

Detailed Description

Class to keep track what Versioned variables were changed.

Definition at line 20 of file segment.h.

Constructor & Destructor Documentation

◆ Segment() [1/2]

Segment::Segment ( )

Construct the very first Segment.

Definition at line 7 of file segment.cpp.

7  {
8  parent = nullptr;
9 
10  version = versionCount++;
11  refcount = 1;
12 }
int refcount
Count of references for that Segment.
Definition: segment.h:66
int version
Version of that Segment.
Definition: segment.h:60
std::shared_ptr< Segment > parent
Previous Segment.
Definition: segment.h:54

◆ Segment() [2/2]

Segment::Segment ( std::shared_ptr< Segment >  parent)

Construct a new Segment object.

Parameters
parentThe parent Segment for new Segment

Definition at line 14 of file segment.cpp.

14  {
15  parent = my_parent;
16  if (parent)
17  parent->refcount++;
18 
19  version = versionCount++;
20  refcount = 1;
21 }

Member Function Documentation

◆ Collapse()

void Segment::Collapse ( std::shared_ptr< Revision >  main)

Compress branch of Segments into one Segment.

Parameters
mainRevision of whose branch of Segments needs to be collapsed
See also
Revision

Definition at line 33 of file segment.cpp.

33  {
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 }

◆ Release()

void Segment::Release ( )

Release Segment when it's no longer needed.

Definition at line 23 of file segment.cpp.

23  {
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 }
std::list< VersionedI * > written
List of all Versioned variables that were changed.
Definition: segment.h:73

Member Data Documentation

◆ parent

std::shared_ptr<Segment> Segment::parent

Previous Segment.

Definition at line 54 of file segment.h.

◆ refcount

int Segment::refcount

Count of references for that Segment.

Definition at line 66 of file segment.h.

◆ version

int Segment::version

Version of that Segment.

Definition at line 60 of file segment.h.

◆ written

std::list<VersionedI*> Segment::written

List of all Versioned variables that were changed.

See also
VersionedI

Definition at line 73 of file segment.h.


The documentation for this class was generated from the following files: