PDI 1.5.0-alpha.2021-12-01.6fb714a

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. More...
 
 Ref_any (const Ref_any &other) noexcept
 Copies an existing reference. More...
 
template<bool OR, bool OW>
 Ref_any (const Ref_any< OR, OW > &other) noexcept
 Copies an existing reference with different privileges. More...
 
 Ref_any (Ref_any &&other) noexcept
 Moves an existing reference. More...
 
 Ref_any (void *data, std::function< void(void *)> freefunc, Datatype_uptr type, bool readable, bool writable)
 Creates a reference to currently unreferenced data. More...
 
 Ref_any (Ref other, const Datatype::Accessor_base &accessor)
 Creates a subreference from reference. More...
 
 Ref_any (Ref other, const std::vector< std::unique_ptr< Datatype::Accessor_base >> &accessors)
 Creates a subreference from reference. More...
 
 ~Ref_any ()
 Destructor. More...
 
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. More...
 
Ref operator[] (const char *member_name) const
 Create a sub-reference to a member in case the content behind the ref is a record. More...
 
Ref operator[] (std::size_t index) const
 Create a sub-reference to the content at a given index in case the content behind the ref is an array. More...
 
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. More...
 
 operator typename Ref_access< R, W >::type () const
 Offers access to the referenced raw data. More...
 
Ref_access< R, W >::type get () const
 Offers access to the referenced raw data, throws on null references. More...
 
Ref_access< R, W >::type get (std::nothrow_t) const noexcept
 Offers access to the referenced raw data, returns null for null references. More...
 
template<class T >
scalar_value ()
 Returns a scalar value of type T taken from the data buffer. More...
 
 operator bool () const noexcept
 Checks whether this is a null reference. More...
 
void reset () noexcept
 Nullify the reference. More...
 
Ref copy () const
 Makes a copy of the raw content behind this reference and returns a new reference. More...
 
void * release () noexcept
 Releases ownership of the referenced raw data by nullifying all existing references. More...
 
void on_nullify (std::function< void(Ref)> notifier) const noexcept
 Registers a nullification callback. More...
 
- Public Member Functions inherited from PDI::Reference_base
const Datatypetype () const noexcept
 accesses the type of the referenced raw data More...
 
size_t hash () const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from PDI::Reference_base
 Reference_base () noexcept
 Constructs a null reference. More...
 
 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 Referenced_dataget_content (const Reference_base &other) noexcept
 Function to access the content from a reference with different access right. More...
 
static Ref do_copy (Ref_r ref)
 
- Protected Attributes inherited from PDI::Reference_base
Referenced_datam_content
 Pointer on the data content, can be null if the ref is null. More...
 

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.
Warning
As of now, and unlike std::shared_ptr, the lock system can not be relied upon in a multithreaded environment.

Constructor & Destructor Documentation

◆ Ref_any() [1/7]

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

Constructs a null reference.

◆ Ref_any() [2/7]

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/7]

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/7]

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/7]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( void *  data,
std::function< void(void *)>  freefunc,
Datatype_uptr  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() [6/7]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( Ref  other,
const Datatype::Accessor_base accessor 
)
inline

Creates a subreference from reference.

Parameters
othersource reference
accessoraccessor to use to create subreference

◆ Ref_any() [7/7]

template<bool R, bool W>
PDI::Ref_any< R, W >::Ref_any ( Ref  other,
const std::vector< std::unique_ptr< Datatype::Accessor_base >> &  accessors 
)
inline

Creates a subreference from reference.

Parameters
othersource reference
accessorsvector of accessor to use to create subreference

◆ ~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>
Ref PDI::Ref_any< R, W >::operator[] ( std::size_t  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

◆ operator typename Ref_access< R, W >::type()

template<bool R, bool W>
PDI::Ref_any< R, W >::operator typename Ref_access< R, W >::type ( ) 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<R, W>::type 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<R, W>::type 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 ( )
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

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