Loading...
Searching...
No Matches
handle.h
1//
2// Copyright 2020 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HGI_HANDLE_H
8#define PXR_IMAGING_HGI_HANDLE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hgi/api.h"
12
13#include <stdint.h>
14
15PXR_NAMESPACE_OPEN_SCOPE
16
31template<class T>
33{
34public:
35 HgiHandle() : _ptr(nullptr), _id(0) {}
36 HgiHandle(T* obj, uint64_t id) : _ptr(obj), _id(id) {}
37
38 T*
39 Get() const {
40 return _ptr;
41 }
42
43 uint64_t GetId() const {
44 return _id;
45 }
46
47 // Note this only checks if a ptr is set, it does not offer weak_ptr safety.
48 explicit operator bool() const {return _ptr!=nullptr;}
49
50 // Pointer access operator
51 T* operator ->() const {return _ptr;}
52
53 bool operator==(const HgiHandle& other) const {
54 return _id == other._id;
55 }
56
57 bool operator!=(const HgiHandle& other) const {
58 return !(*this == other);
59 }
60
61private:
62 T* _ptr;
63 uint64_t _id;
64};
65
66
67PXR_NAMESPACE_CLOSE_SCOPE
68
69#endif
Handle that contains a hgi object and unique id.
Definition: handle.h:33