Chromium Embedded Framework (CEF)  126.2.0+g5c56e98+chromium-126.0.6478.62
base::ScopedTypeRef< T, Traits > Class Template Reference

ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership of a reference to any type that is maintained by Retain and Release methods. More...

#include "include/base/cef_scoped_typeref_mac.h"

Public Types

using element_type = T
 

Public Member Functions

constexpr ScopedTypeRef (element_type object=Traits::InvalidValue(), base::scoped_policy::OwnershipPolicy policy=base::scoped_policy::ASSUME)
 
 ScopedTypeRef (const ScopedTypeRef< T, Traits > &that)
 
template<typename R , typename RTraits >
 ScopedTypeRef (const ScopedTypeRef< R, RTraits > &that_as_subclass)
 
 ScopedTypeRef (ScopedTypeRef< T, Traits > &&that)
 
 ~ScopedTypeRef ()
 
ScopedTypeRefoperator= (const ScopedTypeRef< T, Traits > &that)
 
element_typeInitializeInto ()
 
void reset (const ScopedTypeRef< T, Traits > &that)
 
void reset (element_type object=Traits::InvalidValue(), base::scoped_policy::OwnershipPolicy policy=base::scoped_policy::ASSUME)
 
bool operator== (const element_type &that) const
 
bool operator!= (const element_type &that) const
 
 operator element_type () const
 
element_type get () const
 
void swap (ScopedTypeRef &that)
 
element_type release ()
 

Detailed Description

template<typename T, typename Traits = ScopedTypeRefTraits<T>>
class base::ScopedTypeRef< T, Traits >

ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership of a reference to any type that is maintained by Retain and Release methods.

The Traits structure must provide the Retain and Release methods for type T. A default ScopedTypeRefTraits is used but not defined, and should be defined for each type to use this interface. For example, an appropriate definition of ScopedTypeRefTraits for CGLContextObj would be:

  template<>
  struct ScopedTypeRefTraits<CGLContextObj> {
    static CGLContextObj InvalidValue() { return nullptr; }
    static CGLContextObj Retain(CGLContextObj object) {
      CGLContextRetain(object);
      return object;
    }
    static void Release(CGLContextObj object) { CGLContextRelease(object); }
  };

For the many types that have pass-by-pointer create functions, the function InitializeInto() is provided to allow direct initialization and assumption of ownership of the object. For example, continuing to use the above CGLContextObj specialization:

  base::ScopedTypeRef<CGLContextObj> context;
  CGLCreateContext(pixel_format, share_group, context.InitializeInto());

For initialization with an existing object, the caller may specify whether the ScopedTypeRef<> being initialized is assuming the caller's existing ownership of the object (and should not call Retain in initialization) or if it should not assume this ownership and must create its own (by calling Retain in initialization). This behavior is based on the |policy| parameter, with |ASSUME| for the former and |RETAIN| for the latter. The default policy is to |ASSUME|.

Member Typedef Documentation

◆ element_type

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
using base::ScopedTypeRef< T, Traits >::element_type = T

Constructor & Destructor Documentation

◆ ScopedTypeRef() [1/4]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
constexpr base::ScopedTypeRef< T, Traits >::ScopedTypeRef ( element_type  object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy  policy = base::scoped_policy::ASSUME 
)
inlineexplicitconstexpr

◆ ScopedTypeRef() [2/4]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
base::ScopedTypeRef< T, Traits >::ScopedTypeRef ( const ScopedTypeRef< T, Traits > &  that)
inline

◆ ScopedTypeRef() [3/4]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
template<typename R , typename RTraits >
base::ScopedTypeRef< T, Traits >::ScopedTypeRef ( const ScopedTypeRef< R, RTraits > &  that_as_subclass)
inlineexplicit

◆ ScopedTypeRef() [4/4]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
base::ScopedTypeRef< T, Traits >::ScopedTypeRef ( ScopedTypeRef< T, Traits > &&  that)
inline

◆ ~ScopedTypeRef()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
base::ScopedTypeRef< T, Traits >::~ScopedTypeRef ( )
inline

Member Function Documentation

◆ get()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
element_type base::ScopedTypeRef< T, Traits >::get ( ) const
inline

◆ InitializeInto()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
element_type* base::ScopedTypeRef< T, Traits >::InitializeInto ( )
inline

◆ operator element_type()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
base::ScopedTypeRef< T, Traits >::operator element_type ( ) const
inline

◆ operator!=()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
bool base::ScopedTypeRef< T, Traits >::operator!= ( const element_type that) const
inline

◆ operator=()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
ScopedTypeRef& base::ScopedTypeRef< T, Traits >::operator= ( const ScopedTypeRef< T, Traits > &  that)
inline

◆ operator==()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
bool base::ScopedTypeRef< T, Traits >::operator== ( const element_type that) const
inline

◆ release()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
element_type base::ScopedTypeRef< T, Traits >::release ( )
inline

◆ reset() [1/2]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
void base::ScopedTypeRef< T, Traits >::reset ( const ScopedTypeRef< T, Traits > &  that)
inline

◆ reset() [2/2]

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
void base::ScopedTypeRef< T, Traits >::reset ( element_type  object = Traits::InvalidValue(),
base::scoped_policy::OwnershipPolicy  policy = base::scoped_policy::ASSUME 
)
inline

◆ swap()

template<typename T , typename Traits = ScopedTypeRefTraits<T>>
void base::ScopedTypeRef< T, Traits >::swap ( ScopedTypeRef< T, Traits > &  that)
inline

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