Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::vm::guarded_ptr< T > Struct Template Reference

#include <guarded_ptr.hpp>

Public Member Functions

 guarded_ptr (T *rp, size_t bnds)
 
guarded_ptroperator+= (size_t i)
 
guarded_ptroperator++ ()
 
guarded_ptr operator++ (int)
 
Toperator* () const
 
Toperator-> () const
 
Toperator= (const guarded_ptr< T > &ptr)=delete
 
Traw ()
 
size_t offset ()
 
auto scoped_shrink_bounds (std::size_t n)
 
auto scoped_consume_items (std::size_t n)
 
size_t bounds ()
 
T at (size_t index) const
 
T at () const
 
T operator[] (size_t index) const
 
 guarded_ptr (T *rp, size_t bnds)
 
guarded_ptroperator+= (size_t i)
 
guarded_ptroperator++ ()
 
guarded_ptr operator++ (int)
 
Toperator* () const
 
Toperator-> () const
 
Toperator= (const guarded_ptr< T > &ptr)=delete
 
Traw ()
 
size_t offset ()
 
auto scoped_shrink_bounds (std::size_t n)
 
auto scoped_consume_items (std::size_t n)
 
size_t bounds ()
 
T at (size_t index) const
 
T at () const
 
T operator[] (size_t index) const
 

Public Attributes

Traw_ptr
 
Torig_ptr
 
Tbnds
 

Friends

guarded_ptr operator+ (const guarded_ptr &arg, size_t i)
 
guarded_ptr operator+ (std::size_t i, const guarded_ptr &arg)
 
guarded_ptr operator+ (const guarded_ptr &arg, size_t i)
 
guarded_ptr operator+ (std::size_t i, const guarded_ptr &arg)
 

Detailed Description

template<typename T>
struct sysio::vm::guarded_ptr< T >

Definition at line 10 of file guarded_ptr.hpp.

Constructor & Destructor Documentation

◆ guarded_ptr() [1/2]

template<typename T >
sysio::vm::guarded_ptr< T >::guarded_ptr ( T * rp,
size_t bnds )
inline

Definition at line 14 of file guarded_ptr.hpp.

◆ guarded_ptr() [2/2]

template<typename T >
sysio::vm::guarded_ptr< T >::guarded_ptr ( T * rp,
size_t bnds )
inline

Definition at line 14 of file guarded_ptr.hpp.

14: raw_ptr(rp), orig_ptr(rp), bnds(rp + bnds) {}

Member Function Documentation

◆ at() [1/4]

template<typename T >
T sysio::vm::guarded_ptr< T >::at ( ) const
inline

Definition at line 96 of file guarded_ptr.hpp.

96 {
97 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
98 return *raw_ptr;
99 }
#define SYS_VM_ASSERT(expr, exc_type, msg)
Definition exceptions.hpp:8
Here is the caller graph for this function:

◆ at() [2/4]

template<typename T >
T sysio::vm::guarded_ptr< T >::at ( ) const
inline

Definition at line 96 of file guarded_ptr.hpp.

96 {
97 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
98 return *raw_ptr;
99 }

◆ at() [3/4]

template<typename T >
T sysio::vm::guarded_ptr< T >::at ( size_t index) const
inline

Definition at line 91 of file guarded_ptr.hpp.

91 {
92 SYS_VM_ASSERT(index < static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "accessing out of bounds");
93 return raw_ptr[index];
94 }
Here is the caller graph for this function:

◆ at() [4/4]

template<typename T >
T sysio::vm::guarded_ptr< T >::at ( size_t index) const
inline

Definition at line 91 of file guarded_ptr.hpp.

91 {
92 SYS_VM_ASSERT(index < static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "accessing out of bounds");
93 return raw_ptr[index];
94 }

◆ bounds() [1/2]

template<typename T >
size_t sysio::vm::guarded_ptr< T >::bounds ( )
inline

Definition at line 87 of file guarded_ptr.hpp.

87 {
88 return bnds - orig_ptr;
89 }

◆ bounds() [2/2]

template<typename T >
size_t sysio::vm::guarded_ptr< T >::bounds ( )
inline

Definition at line 87 of file guarded_ptr.hpp.

87 {
88 return bnds - orig_ptr;
89 }

◆ offset() [1/2]

template<typename T >
size_t sysio::vm::guarded_ptr< T >::offset ( )
inline

Definition at line 61 of file guarded_ptr.hpp.

61 {
62 return raw_ptr - orig_ptr;
63 }
Here is the caller graph for this function:

◆ offset() [2/2]

template<typename T >
size_t sysio::vm::guarded_ptr< T >::offset ( )
inline

Definition at line 61 of file guarded_ptr.hpp.

61 {
62 return raw_ptr - orig_ptr;
63 }

◆ operator*() [1/2]

template<typename T >
T & sysio::vm::guarded_ptr< T >::operator* ( ) const
inline

Definition at line 45 of file guarded_ptr.hpp.

45 {
46 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
47 return *raw_ptr;
48 }

◆ operator*() [2/2]

template<typename T >
T & sysio::vm::guarded_ptr< T >::operator* ( ) const
inline

Definition at line 45 of file guarded_ptr.hpp.

45 {
46 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
47 return *raw_ptr;
48 }

◆ operator++() [1/4]

template<typename T >
guarded_ptr & sysio::vm::guarded_ptr< T >::operator++ ( )
inline

Definition at line 22 of file guarded_ptr.hpp.

22 {
23 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "overbounding pointer");
24 raw_ptr += 1;
25 return *this;
26 }

◆ operator++() [2/4]

template<typename T >
guarded_ptr & sysio::vm::guarded_ptr< T >::operator++ ( )
inline

Definition at line 22 of file guarded_ptr.hpp.

22 {
23 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "overbounding pointer");
24 raw_ptr += 1;
25 return *this;
26 }

◆ operator++() [3/4]

template<typename T >
guarded_ptr sysio::vm::guarded_ptr< T >::operator++ ( int )
inline

Definition at line 28 of file guarded_ptr.hpp.

28 {
29 guarded_ptr tmp = *this;
30 ++*this;
31 return tmp;
32 }
guarded_ptr(T *rp, size_t bnds)

◆ operator++() [4/4]

template<typename T >
guarded_ptr sysio::vm::guarded_ptr< T >::operator++ ( int )
inline

Definition at line 28 of file guarded_ptr.hpp.

28 {
29 guarded_ptr tmp = *this;
30 ++*this;
31 return tmp;
32 }

◆ operator+=() [1/2]

template<typename T >
guarded_ptr & sysio::vm::guarded_ptr< T >::operator+= ( size_t i)
inline

Definition at line 16 of file guarded_ptr.hpp.

16 {
17 SYS_VM_ASSERT(i <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "overbounding pointer");
18 raw_ptr += i;
19 return *this;
20 }

◆ operator+=() [2/2]

template<typename T >
guarded_ptr & sysio::vm::guarded_ptr< T >::operator+= ( size_t i)
inline

Definition at line 16 of file guarded_ptr.hpp.

16 {
17 SYS_VM_ASSERT(i <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "overbounding pointer");
18 raw_ptr += i;
19 return *this;
20 }

◆ operator->() [1/2]

template<typename T >
T * sysio::vm::guarded_ptr< T >::operator-> ( ) const
inline

Definition at line 50 of file guarded_ptr.hpp.

50 {
51 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
52 return raw_ptr;
53 }

◆ operator->() [2/2]

template<typename T >
T * sysio::vm::guarded_ptr< T >::operator-> ( ) const
inline

Definition at line 50 of file guarded_ptr.hpp.

50 {
51 SYS_VM_ASSERT(raw_ptr < bnds, guarded_ptr_exception, "accessing out of bounds");
52 return raw_ptr;
53 }

◆ operator=() [1/2]

template<typename T >
T & sysio::vm::guarded_ptr< T >::operator= ( const guarded_ptr< T > & ptr)
delete

◆ operator=() [2/2]

template<typename T >
T & sysio::vm::guarded_ptr< T >::operator= ( const guarded_ptr< T > & ptr)
delete

◆ operator[]() [1/2]

template<typename T >
T sysio::vm::guarded_ptr< T >::operator[] ( size_t index) const
inline

Definition at line 101 of file guarded_ptr.hpp.

101 {
102 return at(index);
103 }
Here is the call graph for this function:

◆ operator[]() [2/2]

template<typename T >
T sysio::vm::guarded_ptr< T >::operator[] ( size_t index) const
inline

Definition at line 101 of file guarded_ptr.hpp.

101 {
102 return at(index);
103 }
Here is the call graph for this function:

◆ raw() [1/2]

template<typename T >
T * sysio::vm::guarded_ptr< T >::raw ( )
inline

Definition at line 57 of file guarded_ptr.hpp.

57 {
58 return raw_ptr;
59 }
Here is the caller graph for this function:

◆ raw() [2/2]

template<typename T >
T * sysio::vm::guarded_ptr< T >::raw ( )
inline

Definition at line 57 of file guarded_ptr.hpp.

57 {
58 return raw_ptr;
59 }

◆ scoped_consume_items() [1/2]

template<typename T >
auto sysio::vm::guarded_ptr< T >::scoped_consume_items ( std::size_t n)
inline

Definition at line 74 of file guarded_ptr.hpp.

74 {
75 SYS_VM_ASSERT(n <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "guarded ptr out of bounds");
76 int exceptions = std::uncaught_exceptions();
77 T* old_bnds = bnds;
78 bnds = raw_ptr + n;
79 struct throwing_destructor { ~throwing_destructor() noexcept(false) {} };
80 throwing_destructor x;
81 return scope_guard{ [this, old_bnds, exceptions, x](){
82 SYS_VM_ASSERT(exceptions != std::uncaught_exceptions() || raw_ptr == bnds, guarded_ptr_exception, "guarded_ptr not advanced");
83 bnds = old_bnds;
84 } };
85 }
#define T(meth, val, expected)
Here is the caller graph for this function:

◆ scoped_consume_items() [2/2]

template<typename T >
auto sysio::vm::guarded_ptr< T >::scoped_consume_items ( std::size_t n)
inline

Definition at line 74 of file guarded_ptr.hpp.

74 {
75 SYS_VM_ASSERT(n <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "guarded ptr out of bounds");
76 int exceptions = std::uncaught_exceptions();
77 T* old_bnds = bnds;
78 bnds = raw_ptr + n;
79 struct throwing_destructor { ~throwing_destructor() noexcept(false) {} };
80 throwing_destructor x;
81 return scope_guard{ [this, old_bnds, exceptions, x](){
82 SYS_VM_ASSERT(exceptions != std::uncaught_exceptions() || raw_ptr == bnds, guarded_ptr_exception, "guarded_ptr not advanced");
83 bnds = old_bnds;
84 } };
85 }

◆ scoped_shrink_bounds() [1/2]

template<typename T >
auto sysio::vm::guarded_ptr< T >::scoped_shrink_bounds ( std::size_t n)
inline

Definition at line 66 of file guarded_ptr.hpp.

66 {
67 SYS_VM_ASSERT(n <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "guarded ptr out of bounds");
68 T* old_bnds = bnds;
69 bnds = raw_ptr + n;
70 return scope_guard{ [this, old_bnds](){ bnds = old_bnds; } };
71 }

◆ scoped_shrink_bounds() [2/2]

template<typename T >
auto sysio::vm::guarded_ptr< T >::scoped_shrink_bounds ( std::size_t n)
inline

Definition at line 66 of file guarded_ptr.hpp.

66 {
67 SYS_VM_ASSERT(n <= static_cast<std::size_t>(bnds - raw_ptr), guarded_ptr_exception, "guarded ptr out of bounds");
68 T* old_bnds = bnds;
69 bnds = raw_ptr + n;
70 return scope_guard{ [this, old_bnds](){ bnds = old_bnds; } };
71 }

Friends And Related Symbol Documentation

◆ operator+ [1/4]

template<typename T >
guarded_ptr operator+ ( const guarded_ptr< T > & arg,
size_t i )
friend

Definition at line 34 of file guarded_ptr.hpp.

34 {
35 guarded_ptr tmp = arg;
36 tmp += i;
37 return tmp;
38 }

◆ operator+ [2/4]

template<typename T >
guarded_ptr operator+ ( const guarded_ptr< T > & arg,
size_t i )
friend

Definition at line 34 of file guarded_ptr.hpp.

34 {
35 guarded_ptr tmp = arg;
36 tmp += i;
37 return tmp;
38 }

◆ operator+ [3/4]

template<typename T >
guarded_ptr operator+ ( std::size_t i,
const guarded_ptr< T > & arg )
friend

Definition at line 39 of file guarded_ptr.hpp.

39 {
40 guarded_ptr tmp = arg;
41 tmp += i;
42 return tmp;
43 }

◆ operator+ [4/4]

template<typename T >
guarded_ptr operator+ ( std::size_t i,
const guarded_ptr< T > & arg )
friend

Definition at line 39 of file guarded_ptr.hpp.

39 {
40 guarded_ptr tmp = arg;
41 tmp += i;
42 return tmp;
43 }

Member Data Documentation

◆ bnds

template<typename T >
T * sysio::vm::guarded_ptr< T >::bnds

Definition at line 13 of file guarded_ptr.hpp.

◆ orig_ptr

template<typename T >
T * sysio::vm::guarded_ptr< T >::orig_ptr

Definition at line 12 of file guarded_ptr.hpp.

◆ raw_ptr

template<typename T >
T * sysio::vm::guarded_ptr< T >::raw_ptr

Definition at line 11 of file guarded_ptr.hpp.


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