DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::ref_or_owned< T > Class Template Reference

A utility class that simplifies declaring function attributes that need to be stored without requiring the user to create a shared pointer. More...

#include <ref_or_owned.h>

Public Member Functions

 ref_or_owned (ref_or_owned< T > &&other) noexcept
 
 ref_or_owned (const ref_or_owned< T > &other)
 
template<ref_or_owned_compatible< T > U>
 ref_or_owned (U &value)
 Constructs a ref_or_owned object from a reference to an object. More...
 
template<ref_or_owned_compatible< T > U>
 ref_or_owned (U &&value)
 Constructs a ref_or_owned object from a temporary object. More...
 
template<ref_or_owned_compatible< T > U>
 ref_or_owned (std::shared_ptr< U > ptr)
 
const T & get () const
 Returns a const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer. More...
 
T & get ()
 Returns a non-const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer. More...
 
std::shared_ptr< T > to_shared_ptr () const
 

Detailed Description

template<typename T>
class docwire::ref_or_owned< T >

A utility class that simplifies declaring function attributes that need to be stored without requiring the user to create a shared pointer.

The ref_or_owned class is designed to make it easy to declare function parameters that need to store a value, without requiring the user to manually manage the memory. It acts as a "sink" that can accept either a reference or a temporary object, and will automatically manage the memory for the user.

Template Parameters
TThe type of the object being stored.

Definition at line 33 of file ref_or_owned.h.

Constructor & Destructor Documentation

◆ ref_or_owned() [1/2]

template<typename T >
template<ref_or_owned_compatible< T > U>
docwire::ref_or_owned< T >::ref_or_owned ( U &  value)
inline

Constructs a ref_or_owned object from a reference to an object.

The object is stored as a reference, and the ref_or_owned object will not manage its memory.

Parameters
valueThe object to be stored.

Definition at line 55 of file ref_or_owned.h.

◆ ref_or_owned() [2/2]

template<typename T >
template<ref_or_owned_compatible< T > U>
docwire::ref_or_owned< T >::ref_or_owned ( U &&  value)
inline

Constructs a ref_or_owned object from a temporary object.

The object is stored as a shared pointer, and the ref_or_owned object will manage its memory.

Parameters
valueThe object to be stored.

Definition at line 67 of file ref_or_owned.h.

Member Function Documentation

◆ get() [1/2]

template<typename T >
T& docwire::ref_or_owned< T >::get ( )
inline

Returns a non-const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.

Returns
A non-const reference to the stored object.

Definition at line 90 of file ref_or_owned.h.

◆ get() [2/2]

template<typename T >
const T& docwire::ref_or_owned< T >::get ( ) const
inline

Returns a const reference to the stored object, regardless of whether it is stored as a reference or a shared pointer.

Returns
A const reference to the stored object.

Definition at line 81 of file ref_or_owned.h.


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