cgv
Loading...
Searching...
No Matches
cgv::data::ref_ptr< T, is_ref_counted > Class Template Reference

reference counted pointer, which can work together with types that are derived from ref_counted, in which case the reference count of ref_counted is used. More...

#include <ref_ptr.h>

Inheritance diagram for cgv::data::ref_ptr< T, is_ref_counted >:
cgv::data::ref_ptr_impl< T, is_ref_counted >

Public Types

typedef ref_ptr< T, is_ref_counted > this_type
 type of the reference counted pointer
 
typedef ref_ptr_impl< T, is_ref_counted > base_type
 type of base class that implements the reference count specific methods
 

Public Member Functions

 ref_ptr (T *p=0)
 construction from pointer or empty if pointer is not given
 
 ref_ptr (const this_type &r)
 copy constructor for reference pointers of the same type
 
 ~ref_ptr ()
 destruct reference counted pointer
 
template<typename S >
 ref_ptr (const ref_ptr< S, is_ref_counted > &s)
 allow to copy ref_ptr to a ref_ptr<T> if T is a base class of S and if T has a virtual destructor
 
template<typename S >
ref_ptr< S, is_ref_counted > down_cast () const
 use static cast to convert from T to S if T is a base class of S and has a virtual destructor
 
this_typeoperator= (const this_type &r)
 assignment to pointer of same type
 
template<typename S >
this_typeoperator= (const ref_ptr< S, is_ref_counted > &r)
 assignment to pointer of derived type with virtual destructor
 
T & operator* () const
 access to element
 
T * operator-> () const
 access to element pointer
 
bool operator== (const this_type &r) const
 compare by pointer
 
bool operator< (const this_type &r) const
 compare by pointer
 
bool operator!= (const this_type &r) const
 compare by pointer
 
bool unique () const
 check if this is the only reference
 
bool empty () const
 check if pointer is not yet set
 
 operator bool () const
 conversion to bool results in false if the stored pointer is a null pointer
 
void clear ()
 set to null pointer
 
- Public Member Functions inherited from cgv::data::ref_ptr_impl< T, is_ref_counted >
int get_count () const
 return current count
 

Additional Inherited Members

- Protected Member Functions inherited from cgv::data::ref_ptr_impl< T, is_ref_counted >
void release ()
 decrement the count, delete if it is 0
 
T * ref () const
 return the pointer itself
 
 ref_ptr_impl (T *p=0)
 construct reference counted pointer
 
 ref_ptr_impl (const ref_ptr_impl< T, false > &r)
 copy construct from same pointer type and increment count
 
template<typename S >
 ref_ptr_impl (const ref_ptr_impl< S, false > &s)
 copy construct from pointer of derived type with virtual destructor
 
- Protected Attributes inherited from cgv::data::ref_ptr_impl< T, is_ref_counted >
counter_typecounter
 store pointer to counter struct
 

Detailed Description

template<class T, bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
class cgv::data::ref_ptr< T, is_ref_counted >

reference counted pointer, which can work together with types that are derived from ref_counted, in which case the reference count of ref_counted is used.

Otherwise a reference count is allocated and access to the stored instance needs to follow two pointers.

Definition at line 159 of file ref_ptr.h.

Member Typedef Documentation

◆ base_type

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
typedef ref_ptr_impl<T,is_ref_counted> cgv::data::ref_ptr< T, is_ref_counted >::base_type

type of base class that implements the reference count specific methods

Definition at line 165 of file ref_ptr.h.

◆ this_type

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
typedef ref_ptr<T,is_ref_counted> cgv::data::ref_ptr< T, is_ref_counted >::this_type

type of the reference counted pointer

Definition at line 163 of file ref_ptr.h.

Constructor & Destructor Documentation

◆ ref_ptr() [1/3]

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
cgv::data::ref_ptr< T, is_ref_counted >::ref_ptr ( T *  p = 0)
inline

construction from pointer or empty if pointer is not given

Definition at line 168 of file ref_ptr.h.

◆ ref_ptr() [2/3]

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
cgv::data::ref_ptr< T, is_ref_counted >::ref_ptr ( const this_type r)
inline

copy constructor for reference pointers of the same type

Definition at line 170 of file ref_ptr.h.

◆ ~ref_ptr()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
cgv::data::ref_ptr< T, is_ref_counted >::~ref_ptr ( )
inline

destruct reference counted pointer

Definition at line 172 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::release().

◆ ref_ptr() [3/3]

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
template<typename S >
cgv::data::ref_ptr< T, is_ref_counted >::ref_ptr ( const ref_ptr< S, is_ref_counted > &  s)
inline

allow to copy ref_ptr to a ref_ptr<T> if T is a base class of S and if T has a virtual destructor

Definition at line 177 of file ref_ptr.h.

Member Function Documentation

◆ clear()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
void cgv::data::ref_ptr< T, is_ref_counted >::clear ( )
inline

◆ down_cast()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
template<typename S >
ref_ptr< S, is_ref_counted > cgv::data::ref_ptr< T, is_ref_counted >::down_cast ( ) const
inline

use static cast to convert from T to S if T is a base class of S and has a virtual destructor

Definition at line 180 of file ref_ptr.h.

Referenced by cgv::gui::gui_group::add_control(), cgv::gui::gui_group::add_control(), cgv::gui::gui_group::add_view(), cgv::gui::gui_group::find_control(), and cgv::gui::gui_group::find_view().

◆ empty()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
bool cgv::data::ref_ptr< T, is_ref_counted >::empty ( ) const
inline

check if pointer is not yet set

Definition at line 230 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::get_count().

Referenced by cgv::gui::provider::add_button(), cgv::gui::provider::add_control(), cgv::gui::provider::add_control(), cgv::gui::provider::add_control_void(), cgv::gui::provider::add_decorator(), cgv::gui::provider::add_group(), cgv::gui::event_handler::add_key_control(), cgv::gui::provider::add_view(), cgv::gui::provider::add_view_void(), cgv::gui::provider::align(), cgv::render::shader_program::collect_dir(), cgv::gui::connect_gamepad_server(), cgv::gui::connect_vr_server(), cgv::gui::application::copy_to_clipboard(), cgv::gui::create_text_editor(), cgv::gui::directory_open_dialog(), cgv::gui::directory_save_dialog(), cgv::render::context::draw_text(), cgv::gui::file_open_dialog(), cgv::gui::file_save_dialog(), cgv::gui::files_open_dialog(), cgv::gui::provider::find_control(), cgv::gui::provider::find_control_void(), cgv::gui::provider::find_element(), cgv::render::shader_code::find_file(), cgv::gui::provider::find_view(), cgv::gui::provider::find_view_void(), cgv::render::gl::gl_context::get_current_font_face(), cgv::render::gl::gl_context::get_info_font_face(), cgv::gui::application::get_nr_windows(), cgv::base::grab_focus(), cgv::base::group::link(), cgv::gui::message(), cgv::data::ref_ptr< T, is_ref_counted >::operator bool(), cgv::gui::application::paste_from_clipboard(), cgv::gui::query(), cgv::gui::question(), cgv::gui::question(), cgv::gui::application::quit(), cgv::render::shader_code::read_code_file(), cgv::gui::provider::remove_all_elements(), cgv::gui::provider::remove_element(), cgv::gui::application::run(), cgv::gui::application::set_focus(), cgv::base::traverser::traverse_tmp_1(), and cgv::base::group::unlink().

◆ operator bool()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
cgv::data::ref_ptr< T, is_ref_counted >::operator bool ( ) const
inline

conversion to bool results in false if the stored pointer is a null pointer

Definition at line 234 of file ref_ptr.h.

References cgv::data::ref_ptr< T, is_ref_counted >::empty().

◆ operator!=()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
bool cgv::data::ref_ptr< T, is_ref_counted >::operator!= ( const this_type r) const
inline

compare by pointer

Definition at line 222 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::ref().

◆ operator*()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
T & cgv::data::ref_ptr< T, is_ref_counted >::operator* ( ) const
inline

access to element

Definition at line 206 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::ref().

◆ operator->()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
T * cgv::data::ref_ptr< T, is_ref_counted >::operator-> ( ) const
inline

access to element pointer

Definition at line 210 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::ref().

◆ operator<()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
bool cgv::data::ref_ptr< T, is_ref_counted >::operator< ( const this_type r) const
inline

compare by pointer

Definition at line 218 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::ref().

◆ operator=() [1/2]

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
template<typename S >
this_type & cgv::data::ref_ptr< T, is_ref_counted >::operator= ( const ref_ptr< S, is_ref_counted > &  r)
inline

assignment to pointer of derived type with virtual destructor

Definition at line 200 of file ref_ptr.h.

◆ operator=() [2/2]

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
this_type & cgv::data::ref_ptr< T, is_ref_counted >::operator= ( const this_type r)
inline

assignment to pointer of same type

Definition at line 191 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::release().

◆ operator==()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
bool cgv::data::ref_ptr< T, is_ref_counted >::operator== ( const this_type r) const
inline

compare by pointer

Definition at line 214 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::ref().

◆ unique()

template<class T , bool is_ref_counted = type::cond::is_base_of<ref_counted,T>::value>
bool cgv::data::ref_ptr< T, is_ref_counted >::unique ( ) const
inline

check if this is the only reference

Definition at line 226 of file ref_ptr.h.

References cgv::data::ref_ptr_impl< T, is_ref_counted >::get_count().


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