HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sortedIds.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 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_HD_SORTED_IDS_H
8 #define PXR_IMAGING_HD_SORTED_IDS_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 
13 #include "pxr/usd/sdf/path.h"
14 
15 #include <memory>
16 
18 
19 ///
20 /// Manages a container of Hydra Ids in a sorted order.
21 ///
22 /// Note that this class behaves like a multiset. Duplicate elements are
23 /// allowed.
24 ///
25 class Hd_SortedIds {
26 public:
27  /// Default ctor produces an empty container.
28  HD_API
29  Hd_SortedIds();
30 
31  HD_API
32  ~Hd_SortedIds();
33 
34  /// Copy construct.
35  HD_API
36  Hd_SortedIds(Hd_SortedIds const &);
37 
38  /// Move construct.
39  HD_API
40  Hd_SortedIds(Hd_SortedIds &&);
41 
42  /// Copy assign.
43  HD_API
44  Hd_SortedIds &operator=(Hd_SortedIds const &);
45 
46  /// Move assign.
47  HD_API
48  Hd_SortedIds &operator=(Hd_SortedIds &&);
49 
50  /// Sorts the ids if needed and returns the sorted list of ids.
51  HD_API
52  const SdfPathVector &GetIds();
53 
54  /// Add an id to the collection. If the id is already present in the
55  /// collection, a duplicate id is added.
56  HD_API
57  void Insert(const SdfPath &id);
58 
59  /// Remove up to one occurrence of id from the collection. If the id is not
60  /// present, do nothing. Otherwise remove one copy of id.
61  HD_API
62  void Remove(const SdfPath &id);
63 
64  /// Remove a range of id from the collection.
65  /// Range defined by position index in sorted list.
66  /// end is inclusive.
67  HD_API
68  void RemoveRange(size_t start, size_t end);
69 
70  /// Removes all ids from the collection.
71  HD_API
72  void Clear();
73 
74 private:
75  struct _UpdateImpl;
76 
77  enum _EditMode { _NoMode, _InsertMode, _RemoveMode, _UpdateMode };
78 
79  void _Sort();
80 
81  SdfPathVector _ids;
82  SdfPathVector _edits;
83  _EditMode _mode = _NoMode;
84  std::unique_ptr<_UpdateImpl> _updater;
85 };
86 
88 
89 #endif // PXR_IMAGING_HD_SORTED_IDS_H
HD_API void Remove(const SdfPath &id)
GLuint start
Definition: glcorearb.h:475
#define HD_API
Definition: api.h:23
HD_API void Insert(const SdfPath &id)
HD_API Hd_SortedIds()
Default ctor produces an empty container.
std::vector< class SdfPath > SdfPathVector
HD_API void RemoveRange(size_t start, size_t end)
GLuint GLuint end
Definition: glcorearb.h:475
Definition: path.h:273
HD_API Hd_SortedIds & operator=(Hd_SortedIds const &)
Copy assign.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API const SdfPathVector & GetIds()
Sorts the ids if needed and returns the sorted list of ids.
HD_API ~Hd_SortedIds()
HD_API void Clear()
Removes all ids from the collection.