STL Memory Versioning
Public Types | Public Member Functions | List of all members
vs::vs_stack< _Key, _Strategy > Class Template Reference

A versioned mimic of a stl::stack, suitable for multithread. More...

#include <vs_stack.h>

Public Types

typedef Versioned< std::stack< _Key >, _Strategy > _Versioned
 
typedef std::stack< _Key >::size_type size_type
 

Public Member Functions

 vs_stack ()
 Creates a vs_stack with no elements. More...
 
 vs_stack (std::initializer_list< _Key > __l)
 Builds a vs_stack from an initializer_list. More...
 
 vs_stack (const vs_stack &__vs_stack)
 vs_stack copy constructor More...
 
const _Key & top () const
 access top element More...
 
size_type size () const noexcept
 size of underlying stack More...
 
void push (const _Key &__x)
 Attempts to push an element into the stack. More...
 
void pop ()
 Remove first element of stack. More...
 

Detailed Description

template<typename _Key, typename _Strategy = vs_stack_strategy<_Key>>
class vs::vs_stack< _Key, _Strategy >

A versioned mimic of a stl::stack, suitable for multithread.

Parameters
_KeyType of key objects.
_StrategyCustom strategy class for different merge behaviour

Definition at line 26 of file vs_stack.h.

Member Typedef Documentation

◆ _Versioned

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
typedef Versioned<std::stack<_Key>,_Strategy> vs::vs_stack< _Key, _Strategy >::_Versioned

Definition at line 35 of file vs_stack.h.

◆ size_type

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
typedef std::stack<_Key>::size_type vs::vs_stack< _Key, _Strategy >::size_type

Definition at line 36 of file vs_stack.h.

Constructor & Destructor Documentation

◆ vs_stack() [1/3]

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
vs::vs_stack< _Key, _Strategy >::vs_stack ( )
inlineexplicit

Creates a vs_stack with no elements.

Definition at line 49 of file vs_stack.h.

50  : _v_s(std::stack<_Key>()) { }

◆ vs_stack() [2/3]

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
vs::vs_stack< _Key, _Strategy >::vs_stack ( std::initializer_list< _Key >  __l)
inline

Builds a vs_stack from an initializer_list.

Parameters
__lAn initializer_list.
__compComparator to use.

Copy elements of the list to created vs_stack. Non-standard, but handy to have instead of copying with stack{{initilizer}}

Definition at line 60 of file vs_stack.h.

61  : _v_s(std::stack<_Key>())
62  {
63  _v_s.Set(_v_s.Get(),
64  [&](std::stack<_Key>& _stack){
65  for (auto& i: __l){
66  _stack.push(i);
67  }
68  return true;
69  });
70  }
const T & Get() const
Get the current value of the object in the current Revision.
Definition: versioned.h:186
bool Set(const T &v, const std::function< bool(T &)> &updater=nullptr)
Set new value of the object.
Definition: versioned.h:205

◆ vs_stack() [3/3]

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
vs::vs_stack< _Key, _Strategy >::vs_stack ( const vs_stack< _Key, _Strategy > &  __vs_stack)
inline

vs_stack copy constructor

does not inherit versions history

Definition at line 77 of file vs_stack.h.

78  : _v_s(__vs_stack._v_s.Get()) { }

Member Function Documentation

◆ pop()

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
void vs::vs_stack< _Key, _Strategy >::pop ( )
inline

Remove first element of stack.

Definition at line 119 of file vs_stack.h.

120  {
121  if (_v_s.Get().size() > 0)
122  _v_s.Set(_v_s.Get(), [](std::stack<_Key>& _stack){ _stack.pop(); return true; });
123  }

◆ push()

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
void vs::vs_stack< _Key, _Strategy >::push ( const _Key &  __x)
inline

Attempts to push an element into the stack.

Parameters
__xElement to be inserted.

Definition at line 110 of file vs_stack.h.

111  {
112  _v_s.Set(_v_s.Get(), [&](std::stack<_Key>& _stack){ _stack.push(__x); return true; });
113  }

◆ size()

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
size_type vs::vs_stack< _Key, _Strategy >::size ( ) const
inlinenoexcept

size of underlying stack

Definition at line 100 of file vs_stack.h.

101  { return _v_s.Get().size(); }

◆ top()

template<typename _Key , typename _Strategy = vs_stack_strategy<_Key>>
const _Key& vs::vs_stack< _Key, _Strategy >::top ( ) const
inline

access top element

Returns a read-only (constant) reference that points to the first element in the vs_stack.

Definition at line 93 of file vs_stack.h.

94  { return _v_s.Get().top(); }

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