STL Memory Versioning
Public Member Functions | Public Attributes | List of all members
Versioned< T, _Strategy > Class Template Reference

Wrapper to make any class Versioned. More...

#include <versioned.h>

Inheritance diagram for Versioned< T, _Strategy >:
Inheritance graph
[legend]
Collaboration diagram for Versioned< T, _Strategy >:
Collaboration graph
[legend]

Public Member Functions

 Versioned (const T &val)
 Construct a new Versioned object from your object. More...
 
 ~Versioned ()
 Destroy the Versioned object. More...
 
const T & Get () const
 Get the current value of the object in the current Revision. More...
 
bool Set (const T &v, const std::function< bool(T &)> &updater=nullptr)
 Set new value of the object. More...
 
void Release (std::shared_ptr< Segment > release) override
 Forget version that was changed in some Segment. More...
 
void Collapse (std::shared_ptr< Revision > main, std::shared_ptr< Segment > parent) override
 Collapse all changes made in Revision into one. More...
 
void Merge (std::shared_ptr< Revision > main, std::shared_ptr< Revision > joinRev, std::shared_ptr< Segment > join) override
 Merge changes from two Revisions. More...
 

Public Attributes

std::map< int, T > versions
 Map of all versions of specified object. More...
 

Detailed Description

template<class T, typename _Strategy = DefaultMergeStrategy<T>>
class Versioned< T, _Strategy >

Wrapper to make any class Versioned.

Template Parameters
TClass that needs to be versioned

Definition at line 53 of file versioned.h.

Constructor & Destructor Documentation

◆ Versioned()

template<class T , typename _Strategy >
Versioned< T, _Strategy >::Versioned ( const T &  val)

Construct a new Versioned object from your object.

Parameters
valYour object

Definition at line 163 of file versioned.h.

163  {
165 }
static thread_local std::shared_ptr< Revision > currentRevision
The current Revision for current thread.
Definition: revision.h:65
bool Set(const T &v, const std::function< bool(T &)> &updater=nullptr)
Set new value of the object.
Definition: versioned.h:205

◆ ~Versioned()

template<class T , typename _Strategy >
Versioned< T, _Strategy >::~Versioned
inline

Destroy the Versioned object.

Removes all mentions of that versioned object in current Revision

Definition at line 168 of file versioned.h.

169 {
170  std::shared_ptr<Segment> s = Revision::currentRevision->current;
171 
172  while (s) {
173  if (versions.find(s->version) != versions.end()) {
174  for (auto it = s->written.begin(); it != s->written.end();){
175  if (*it == this)
176  it = s->written.erase(it);
177  else
178  it++;
179  }
180  }
181  s = s->parent;
182  }
183 }
std::map< int, T > versions
Map of all versions of specified object.
Definition: versioned.h:61

Member Function Documentation

◆ Collapse()

template<class T , typename _Strategy >
void Versioned< T, _Strategy >::Collapse ( std::shared_ptr< Revision main,
std::shared_ptr< Segment parent 
)
overridevirtual

Collapse all changes made in Revision into one.

Parameters
mainRevision to start collapsing from
parentSegment until which to collapse

Implements VersionedI.

Definition at line 244 of file versioned.h.

244  {
245  if (versions.find(main->current->version) == versions.end()) {
246  Set(main, versions[parent->version]);
247  }
248  Release(parent);
249 }
void Release(std::shared_ptr< Segment > release) override
Forget version that was changed in some Segment.
Definition: versioned.h:239

◆ Get()

template<class T , typename _Strategy >
const T & Versioned< T, _Strategy >::Get

Get the current value of the object in the current Revision.

Returns
T Object value
See also
Revision

Definition at line 186 of file versioned.h.

186  {
188 }
const T & Get() const
Get the current value of the object in the current Revision.
Definition: versioned.h:186

◆ Merge()

template<class T , typename _Strategy >
void Versioned< T, _Strategy >::Merge ( std::shared_ptr< Revision main,
std::shared_ptr< Revision joinRev,
std::shared_ptr< Segment join 
)
overridevirtual

Merge changes from two Revisions.

Parameters
mainRevision to merge into
joinRevRevision to merge
joinSegment to which to merge

Implements VersionedI.

Definition at line 252 of file versioned.h.

252  {
253  std::shared_ptr<Segment> s = joinRev->current;
254  while (versions.find(s->version) == versions.end()) {
255  if (!s->parent)
256  break;
257 
258  s = s->parent;
259  }
260  if (s == join) {
261  SetMerge(main, versions[join->version]);
262  }
263 }

◆ Release()

template<class T , typename _Strategy >
void Versioned< T, _Strategy >::Release ( std::shared_ptr< Segment release)
overridevirtual

Forget version that was changed in some Segment.

Parameters
releaseSegment to forget
See also
Segment

Implements VersionedI.

Definition at line 239 of file versioned.h.

239  {
240  versions.erase(release->version);
241 }

◆ Set()

template<class T , typename _Strategy >
bool Versioned< T, _Strategy >::Set ( const T &  v,
const std::function< bool(T &)> &  updater = nullptr 
)

Set new value of the object.

Parameters
vNew object value
updaterFunction to update value
Returns
bool result of updater if defined, else true

If updater function is defined, object will be updated in-place instead of overwrite

Definition at line 205 of file versioned.h.

205  {
206  return Set(Revision::currentRevision, v, updater);
207 }

Member Data Documentation

◆ versions

template<class T , typename _Strategy = DefaultMergeStrategy<T>>
std::map<int, T> Versioned< T, _Strategy >::versions

Map of all versions of specified object.

Segment versions where that object was changed are used as a keys

See also
Segment

Definition at line 61 of file versioned.h.


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