PDI 1.7.1

the PDI data interface

PDI::Ref_any< R, W > Class Template Reference

A dynamically typed reference to data with automatic memory management and read/write locking semantic. More...

Inheritance diagram for PDI::Ref_any< R, W >:
PDI::Reference_base

Public Member Functions

 Ref_any ()=default
 Constructs a null reference.
 
 Ref_any (const Ref_any &other) noexcept
 Copies an existing reference.
 
template<bool OR, bool OW>
 Ref_any (const Ref_any< OR, OW > &other) noexcept
 Copies an existing reference with different privileges.
 
 Ref_any (Ref_any &&other) noexcept
 Moves an existing reference.
 
 Ref_any (void *data, std::function< void(void *)> freefunc, Datatype_sptr type, bool readable, bool writable)
 Creates a reference to currently unreferenced data.
 
 ~Ref_any ()
 Destructor.
 
Ref_anyoperator= (Ref_any &&other) noexcept
 
Ref_anyoperator= (const Ref_any &other) const noexcept
 
bool operator== (const Reference_base &o) const noexcept
 
bool operator!= (const Reference_base &o) const noexcept
 
bool operator< (const Reference_base &o) const noexcept
 
bool operator> (const Reference_base &o) const noexcept
 
bool operator<= (const Reference_base &o) const noexcept
 
bool operator>= (const Reference_base &o) const noexcept
 
Ref operator[] (const std::string &member_name) const
 Create a sub-reference to a member in case the content behind the ref is a record.
 
Ref operator[] (const char *member_name) const
 Create a sub-reference to a member in case the content behind the ref is a record.
 
template<class T >
std::enable_if_t< std::is_integral< T >::value, Refoperator[] (T index) const
 Create a sub-reference to the content at a given index in case the content behind the ref is an array.
 
Ref operator[] (std::pair< std::size_t, std::size_t > slice) const
 Create a sub-reference to the content at a given slice in case the content behind the ref is an array.
 
Ref dereference () const
 Create a reference to the pointed content in case the ref type is a reference.
 
 operator ref_access_t< R, W > () const
 Offers access to the referenced raw data.
 
ref_access_t< R, W > get () const
 Offers access to the referenced raw data, throws on null references.
 
ref_access_t< R, W > get (std::nothrow_t) const noexcept
 Offers access to the referenced raw data, returns null for null references.
 
template<class T >
scalar_value () const
 Returns a scalar value of type T taken from the data buffer.
 
 operator bool () const noexcept
 Checks whether this is a null reference.
 
void reset () noexcept
 Nullify the reference.
 
Ref copy () const
 Makes a copy of the raw content behind this reference and returns a new reference.
 
void * release () noexcept
 Releases ownership of the referenced raw data by nullifying all existing references.
 
void on_nullify (std::function< void(Ref)> notifier) const noexcept
 Registers a nullification callback.
 
- Public Member Functions inherited from PDI::Reference_base
Datatype_sptr type () const noexcept
 accesses the type of the referenced raw data
 
size_t hash () const noexcept
 

Friends

template<bool OR, bool OW>
class Ref_any
 

Additional Inherited Members

- Protected Member Functions inherited from PDI::Reference_base
 Reference_base () noexcept
 Constructs a null reference.
 
 Reference_base (const Reference_base &)=delete
 
 Reference_base (Reference_base &&)=delete
 
Reference_baseoperator= (const Reference_base &)=delete
 
Reference_baseoperator= (Reference_base &&)=delete
 
- Static Protected Member Functions inherited from PDI::Reference_base
static std::shared_ptr< Referenced_dataget_content (const Reference_base &other) noexcept
 Function to access the content from a reference with different access right.
 
static Ref do_copy (Ref_r ref)
 
- Protected Attributes inherited from PDI::Reference_base
std::shared_ptr< Referenced_datam_content
 Pointer on the data content, can be null if the ref is null.
 

Detailed Description

template<bool R, bool W>
class PDI::Ref_any< R, W >

A dynamically typed reference to data with automatic memory management and read/write locking semantic.

Ref_any is a smart pointer that features:

  • a dynamic type system,
  • garbage collection mechanism similar to std::shared_ptr,
  • a read/write locking mechanism similar to std::shared_mutex,
  • a release system that nullifies all existing references to the raw data,
  • a notification system to be notified when a reference is going to be nullified.

Constructor & Destructor Documentation

◆ Ref_any() [1/5]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( )
default

Constructs a null reference.

◆ Ref_any() [2/5]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( const Ref_any< R, W > &  other)
inlinenoexcept

Copies an existing reference.

if the requested rights can not be granted, the reference is made null

Parameters
otherthe ref to copy

◆ Ref_any() [3/5]

template<bool R, bool W>
template<bool OR, bool OW>
PDI::Ref_any< R, W >::Ref_any ( const Ref_any< OR, OW > &  other)
inlinenoexcept

Copies an existing reference with different privileges.

if the requested rights can not be granted, the reference is made null

Parameters
otherthe ref to copy

◆ Ref_any() [4/5]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( Ref_any< R, W > &&  other)
inlinenoexcept

Moves an existing reference.

Parameters
otherthe ref to copy

◆ Ref_any() [5/5]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( void *  data,
std::function< void(void *)>  freefunc,
Datatype_sptr  type,
bool  readable,
bool  writable 
)
inline

Creates a reference to currently unreferenced data.

Parameters
datathe raw data to reference
freefuncthe function to use to free the data buffer
typethe type of the referenced data, ownership will be taken
readablethe maximum allowed access to the underlying content
writablethe maximum allowed access to the underlying content

◆ ~Ref_any()

template<bool R, bool W>
PDI::Ref_any< R, W >::~Ref_any ( )
inline

Destructor.

Member Function Documentation

◆ operator=() [1/2]

template<bool R, bool W>
Ref_any & PDI::Ref_any< R, W >::operator= ( Ref_any< R, W > &&  other)
inlinenoexcept

◆ operator=() [2/2]

template<bool R, bool W>
Ref_any & PDI::Ref_any< R, W >::operator= ( const Ref_any< R, W > &  other) const
inlinenoexcept

◆ operator==()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator== ( const Reference_base o) const
inlinenoexcept

◆ operator!=()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator!= ( const Reference_base o) const
inlinenoexcept

◆ operator<()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator< ( const Reference_base o) const
inlinenoexcept

◆ operator>()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator> ( const Reference_base o) const
inlinenoexcept

◆ operator<=()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator<= ( const Reference_base o) const
inlinenoexcept

◆ operator>=()

template<bool R, bool W>
bool PDI::Ref_any< R, W >::operator>= ( const Reference_base o) const
inlinenoexcept

◆ operator[]() [1/4]

template<bool R, bool W>
Ref PDI::Ref_any< R, W >::operator[] ( const std::string &  member_name) const
inline

Create a sub-reference to a member in case the content behind the ref is a record.

Parameters
member_namemember to make a subref for
Returns
created subreference

◆ operator[]() [2/4]

template<bool R, bool W>
Ref PDI::Ref_any< R, W >::operator[] ( const char *  member_name) const
inline

Create a sub-reference to a member in case the content behind the ref is a record.

Parameters
member_namemember to make a subref for
Returns
created subreference

◆ operator[]() [3/4]

template<bool R, bool W>
template<class T >
std::enable_if_t< std::is_integral< T >::value, Ref > PDI::Ref_any< R, W >::operator[] ( index) const
inline

Create a sub-reference to the content at a given index in case the content behind the ref is an array.

Parameters
indexindex to make a subref for
Returns
created subreference

◆ operator[]() [4/4]

template<bool R, bool W>
Ref PDI::Ref_any< R, W >::operator[] ( std::pair< std::size_t, std::size_t >  slice) const
inline

Create a sub-reference to the content at a given slice in case the content behind the ref is an array.

Parameters
slicepair with start and end index
Returns
created subreference

◆ dereference()

template<bool R, bool W>
Ref PDI::Ref_any< R, W >::dereference ( ) const
inline

Create a reference to the pointed content in case the ref type is a reference.

Returns
a reference to the dereferenced data

◆ operator ref_access_t< R, W >()

template<bool R, bool W>
PDI::Ref_any< R, W >::operator ref_access_t< R, W > ( ) const
inline

Offers access to the referenced raw data.

Returns
a pointer to the referenced raw data

◆ get() [1/2]

template<bool R, bool W>
ref_access_t< R, W > PDI::Ref_any< R, W >::get ( ) const
inline

Offers access to the referenced raw data, throws on null references.

Returns
a pointer to the referenced raw data

◆ get() [2/2]

template<bool R, bool W>
ref_access_t< R, W > PDI::Ref_any< R, W >::get ( std::nothrow_t  ) const
inlinenoexcept

Offers access to the referenced raw data, returns null for null references.

Returns
a pointer to the referenced raw data

◆ scalar_value()

template<bool R, bool W>
template<class T >
T PDI::Ref_any< R, W >::scalar_value ( ) const
inline

Returns a scalar value of type T taken from the data buffer.

Returns
value taken from the data buffer

◆ operator bool()

template<bool R, bool W>
PDI::Ref_any< R, W >::operator bool ( ) const
inlinenoexcept

Checks whether this is a null reference.

Returns
whether this reference is non-null

◆ reset()

template<bool R, bool W>
void PDI::Ref_any< R, W >::reset ( )
inlinenoexcept

Nullify the reference.

◆ copy()

template<bool R, bool W>
Ref PDI::Ref_any< R, W >::copy ( ) const
inline

Makes a copy of the raw content behind this reference and returns a new reference.

Returns
a new reference to a copy of the raw data this references

◆ release()

template<bool R, bool W>
void * PDI::Ref_any< R, W >::release ( )
inlinenoexcept

Releases ownership of the referenced raw data by nullifying all existing references.

Returns
the previously referenced raw data or nullptr if this was a null reference, i.e. the value which would be returned by get() before the call.

◆ on_nullify()

template<bool R, bool W>
void PDI::Ref_any< R, W >::on_nullify ( std::function< void(Ref)>  notifier) const
inlinenoexcept

Registers a nullification callback.

Parameters
notifierthe function to call when this reference becomes null

Friends And Related Function Documentation

◆ Ref_any

template<bool R, bool W>
template<bool OR, bool OW>
friend class Ref_any
friend

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