HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP3D_SelectionCache.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: OP3D_SelectionCache.h ( OP3D Library, C++)
7  *
8  * COMMENTS:
9  * A cache for the various OP3D_GUSelectionSet objects that we create
10  * to represent user component selections.
11  *
12  * Generally there is one cache instance per selection scope that is
13  * used to cache selections both for nodes in that scope (internal)
14  * and for nodes outside of that scope (external).
15  */
16 
17 #ifndef __OP3D_SelectionCache__
18 #define __OP3D_SelectionCache__
19 
20 #include "OP3D_API.h"
21 
22 #include <UT/UT_NonCopyable.h>
23 #include <UT/UT_SharedPtr.h>
24 #include <UT/UT_Map.h>
25 #include <UT/UT_Array.h>
26 #include <SYS/SYS_Hash.h>
27 
30 
33 
34 /// A cache for user component selections.
36 {
37 public:
38  /// Construct a new, empty, component selection.
40 
42 
43  void clear(bool clear_local, bool clear_external);
44 
45  /// Returns the selection set handle for the given node. If there is no
46  /// selection set for the given node, an empty handle is returned.
47  OP3D_GUSelectionSetHandle getSelectionSet(
48  int node_id, int detail_index = 0,
49  bool external = false);
50 
51  /// Set the selection set for the given node. This class only stores
52  /// one selection set per node, so do not set both an external and a
53  /// local (non-external) set on the same node.
54  void setSelectionSet(
55  int node_id, int detail_index,
56  OP3D_GUSelectionSetHandle selection_set,
57  bool external);
58 
59  void remove(int node_id, int detail_index);
60 
61  /// Return the total memory used by the selections stored in this cache
62  /// in bytes.
63  int64 getSelectionMemoryUsage() const;
64 
65  /// Attempt to reduce the memory used by a specified amount, returning the
66  /// actual number of bytes freed.
67  int64 reduceSelectionMemoryUsage(int64 amount);
68 
69  class Key;
70 
71 private:
72  class Entry
73  {
74  public:
75  OP3D_GUSelectionSetHandle mySelectionSet;
76  bool myExternalFlag;
77  };
78 
79  UT_Map<Key, Entry> mySelections;
80 };
81 
82 // Key class for the selection map.
84 {
85 public:
86  Key(int node_id, int detail_index)
87  : myNodeId(node_id), myDetailIndex(detail_index)
88  {
89  }
90 
91  bool operator==(const OP3D_SelectionCache::Key &key) const
92  {
93  return myNodeId == key.myNodeId && myDetailIndex == key.myDetailIndex;
94  }
95 
96  int myNodeId;
98 };
99 
101 {
102  size_t hash_value = SYShash(key.myNodeId);
103  SYShashCombine(hash_value, key.myDetailIndex);
104  return hash_value;
105 }
106 
107 #endif // __OP3D_SelectionCache__
Key(int node_id, int detail_index)
bool operator==(const OP3D_SelectionCache::Key &key) const
UT_SharedPtr< OP3D_SelectionCache > OP3D_SelectionCacheHandle
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE size_t hash_value(const OP3D_SelectionCache::Key &key)
A cache for user component selections.
UT_SharedPtr< OP3D_GUSelectionSet > OP3D_GUSelectionSetHandle
#define OP3D_API
Definition: OP3D_API.h:10
UT_SharedPtr< OP3D_GUSelectionSet > OP3D_GUSelectionSetHandle