7#ifndef MI_BASE_HANDLE_H 
    8#define MI_BASE_HANDLE_H 
   14#ifdef __cpp_variadic_templates 
   27struct Dup_interface_helper {};
 
  111template <
class Interface>
 
  136    template <
typename I2> 
friend class Handle;
 
  150    explicit Handle( Interface* ptr) : m_iptr( ptr) { }
 
  168      : m_iptr( other.m_iptr)
 
  180    template <
class Interface2>
 
  182      : m_iptr( other.
get())
 
  188#ifdef MI_CXX_FEATURE_RVALUE_REFERENCES 
  191      : m_iptr( other.m_iptr)
 
  197    template <
class Interface2>
 
  199      : m_iptr( other.m_iptr)
 
  208        Interface* tmp_iptr = m_iptr;
 
  209        m_iptr = other.m_iptr;
 
  210        other.m_iptr = tmp_iptr;
 
  217        Self( other).swap( *
this);
 
  228    template <
class Interface2>
 
  231        Self( other).swap( *
this);
 
  235#ifdef MI_CXX_FEATURE_RVALUE_REFERENCES 
  239        if( 
this != &other) {
 
  242            m_iptr = other.m_iptr;
 
  249    template <
class Interface2>
 
  254        m_iptr = other.m_iptr;
 
  268        Self( ptr).swap( *
this);
 
  294    Interface* 
get()
 const { 
return  m_iptr; }
 
  301        Interface* ptr = m_iptr;
 
  306#ifdef __cpp_variadic_templates 
  308    template <
typename... T>
 
  309    Self& emplace(T&&... args)
 
  311        return emplace<Interface>(std::forward<T>(args)...);
 
  319    template <
typename Impl, 
typename... T>
 
  320    Self& emplace(T&&... args)
 
  323        m_iptr = 
new Impl(std::forward<T>(args)...);
 
  352    template <
class New_
interface>
 
  358            m_iptr->get_interface( 
typename New_interface::IID())));
 
  387        return lhs.
get() == rhs;
 
  393        return lhs == rhs.
get();
 
  399        return !( lhs == rhs);
 
  404        return !( lhs == rhs);
 
  409template <
class Interface1, 
class Interface2>
 
  412    return lhs.
get() == rhs.
get();
 
  416template <
class Interface1, 
class Interface2>
 
  419    return !( lhs == rhs);
 
  427template <
class Interface>
 
  438template <
class Interface>
 
  444#ifdef __cpp_variadic_templates 
  449template <
typename Impl, 
typename... T>
 
  450inline Handle<Impl> construct_handle(T&&... args)
 
  452    return Handle<Impl>{
new Impl(std::forward<T>(args)...)};
 
Assertions and compile-time assertions.
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Configuration of the Base API.
#define mi_base_assert_msg(expr, msg)
Base API assertion macro (with message).
Definition: assert.h:103
Interface * pointer
Mutable-pointer type to underlying interface.
Definition: handle.h:130
Handle()
Default constructor, initializes handle to hold an invalid interface.
Definition: handle.h:143
Interface * operator->() const
The arrow operator accesses the interface.
Definition: handle.h:340
Interface & operator*() const
The dereference operator accesses the interface.
Definition: handle.h:331
Handle(const Handle<Interface2> &other)
Copy constructor template which allows the construction from assignment compatible interface pointers...
Definition: handle.h:181
Handle(const Self &other)
Copy constructor, increments reference count if interface is valid.
Definition: handle.h:167
friend bool operator==(const Interface *lhs, const Handle<Interface> &rhs)
Returns true if lhs is equal to the underlying interface pointer of rhs.
Definition: handle.h:391
~Handle()
Destructor, releases the interface if it is valid, which decrements the reference count,...
Definition: handle.h:284
friend bool operator==(const Handle<Interface> &lhs, const Interface *rhs)
Returns true if the underlying interface pointer of lhs is equal to rhs.
Definition: handle.h:385
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:439
Difference difference_type
Difference type (signed integral type to hold pointer differences).
Definition: handle.h:127
void swap(Self &other)
Swap two interfaces.
Definition: handle.h:206
static const Dup_interface DUP_INTERFACE
Symbolic constant to trigger a special constructor in the Handle class.
Definition: handle.h:37
Handle(Interface *ptr, Dup_interface)
Constructor from interface pointer, does not take ownership of interface but duplicates it.
Definition: handle.h:159
bool operator==(const Handle<Interface1> &lhs, const Handle<Interface2> &rhs)
Returns true if the underlying interface pointers are equal.
Definition: handle.h:410
Handle(Handle<Interface2> &&other) noexcept
Converting move constructor.
Definition: handle.h:198
friend bool operator!=(const Handle<Interface> &lhs, const Interface *rhs)
Returns true if the underlying interface pointer of lhs is not equal to rhs.
Definition: handle.h:397
Self & operator=(Self &&other) noexcept
Move assignment operator, releases old interface.
Definition: handle.h:237
Handle<New_interface> get_interface() const
Returns a new handle for a possibly different interface type, similar to a dynamic cast,...
Definition: handle.h:353
Handle(Self &&other) noexcept
Move constructor.
Definition: handle.h:190
Handle<Interface> make_handle(Interface *iptr)
Returns a handle that holds the interface pointer passed in as argument.
Definition: handle.h:428
Handle<Interface> Self
Own type.
Definition: handle.h:116
Handle(Interface *ptr)
Constructor from interface pointer, takes ownership of interface.
Definition: handle.h:150
Interface * extract()
Extracts the interface and releases the handle.
Definition: handle.h:299
friend bool operator!=(const Interface *lhs, const Handle<Interface> &rhs)
Returns true if lhs is not equal to the underlying interface pointer of rhs.
Definition: handle.h:403
Self & operator=(const Self &other)
Assignment operator, releases old interface and increments reference count of the new interface if in...
Definition: handle.h:215
bool(Handle::* bool_conversion_support)() const
Helper typedef.
Definition: handle.h:365
Self & operator=(Interface *ptr)
Assignment operator from interface pointer, releases old interface and assigns new interface ptr,...
Definition: handle.h:266
Interface Interface_type
Type of the underlying interface.
Definition: handle.h:119
const Dup_interface_helper * Dup_interface
Type for a symbolic constant to trigger a special constructor in the Handle class.
Definition: handle.h:32
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
Self & operator=(const Handle<Interface2> &other)
Assignment operator template, releases old interface and increments reference count of the new interf...
Definition: handle.h:229
Interface value_type
Type of the underlying interface.
Definition: handle.h:124
Self & operator=(Handle<Interface2> &&other) noexcept
Converting move assignment operator, releases old interface.
Definition: handle.h:250
bool operator!=(const Handle<Interface1> &lhs, const Handle<Interface2> &rhs)
Returns true if the underlying interface pointers are not equal.
Definition: handle.h:417
Interface & reference
Mutable-reference type to underlying interface.
Definition: handle.h:133
void reset()
Releases the current interface, decrementing the reference count.
Definition: handle.h:273
bool is_valid_interface() const
Returns true if the interface is valid.
Definition: handle.h:291
Sint64 Difference
Signed integral type that is large enough to hold the difference of two pointers.
Definition: types.h:122
The basic extensible interface.
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: math.h:22