PDI 0.4.1

Data exchange made easy

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 >:
Inheritance graph

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 ()
 Destructor. More...
 
bool operator== (const Ref_base &o) const noexcept
 
bool operator!= (const Ref_base &o) const noexcept
 
bool operator< (const Ref_base &o) const noexcept
 
bool operator> (const Ref_base &o) const noexcept
 
bool operator<= (const Ref_base &o) const noexcept
 
bool operator>= (const Ref_base &o) const noexcept
 
 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...
 
 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::Ref_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::Ref_base
 Ref_base () noexcept
 Constructs a null reference. More...
 
 Ref_base (const Ref_base &)=delete
 
 Ref_base (Ref_base &&)=delete
 
Ref_baseoperator= (const Ref_base &)=delete
 
Ref_baseoperator= (Ref_base &&)=delete
 
- Static Protected Member Functions inherited from PDI::Ref_base
static Referencedget_content (const Ref_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::Ref_base
Referencedm_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/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_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()

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

Destructor.

Member Function Documentation

◆ operator==()

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

◆ operator!=()

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

◆ operator<()

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

◆ operator>()

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

◆ operator<=()

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

◆ operator>=()

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

◆ 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

◆ 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: