HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UNI_SessionID.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: UNI_SessionID.h ( UNI Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UNI_SessionID_h__
13 #define __UNI_SessionID_h__
14 
15 #include "UNI_API.h"
16 #include "UNI_ID.h"
17 
18 
19 // ============================================================================
20 /// A class representing a global unique ID in Houdini session
21 /// for items that can be found inside UNI graphs.
22 /// This class can encode two separate IDs: a graph ID and item's local ID
23 /// into a single numeric value (UNI_ID::NumericType) stored in the base class.
24 /// It can also take the raw numerical value of the global unique ID too,
25 /// and thus can convert between the two representations.
27 {
28 protected:
29  /// Creates a unique global ID from a raw numerical value.
30  explicit UNI_SessionIDCoder( UNI_ID::NumericType session_id_number )
31  : UNI_ID( session_id_number ) {}
32 
33  /// Creates a unique ID that gobally identifies the item in Houdini session.
34  /// The global ID is constructed based on the given graph ID
35  /// and the item's local ID within that graph.
36  UNI_SessionIDCoder( UNI_GraphID graph_id, UNI_ID::NumericType local_id );
37 
38  /// Returns the graph ID encoded in this session ID.
39  UNI_GraphID decodeGraphID() const;
40 
41  /// Returns the numeric value of the item ID encoded in this session ID.
42  UNI_ID::NumericType decodeItemID() const;
43 };
44 
45 // ============================================================================
46 /// A convenience class of converting between item's local and session IDs,
47 /// allowing using the formal ID types like UNI_NodeID
48 /// (as the template argument).
49 template <typename LOCAL_ID>
51 {
52 public:
53  /// Creates a unique global ID from a raw numerical value.
55  : UNI_SessionIDCoder( id ) {}
56 
57  /// Creates a unique ID that gobally identifies the item in Houdini session.
58  /// The global ID is constructed based on the given graph ID
59  /// and the item's local ID within that graph.
60  UNI_SessionID( UNI_GraphID graph_id, LOCAL_ID local_id )
61  : UNI_SessionIDCoder( graph_id, local_id.numericValue() )
62  {}
63 
64  /// Returns the UNI graph ID encoded in this session ID.
65  UNI_GraphID graphID() const
66  {
68  }
69 
70  /// Returns the local ID of an item, locating it within the given graph.
71  LOCAL_ID localID() const
72  {
73  return LOCAL_ID( UNI_SessionIDCoder::decodeItemID() );
74  }
75 };
76 
77 
78 // ============================================================================
79 /// Aliases for UNI_SessionID template, to be used without template arguments.
84 
85 // ============================================================================
86 /// String formatting ID for debug printouts, etc:
87 #define UNI_SESSION_ID_FORMATTER(UniSesID) \
88 inline size_t \
89 UTformatBuffer(char *buffer, size_t buffer_size, const UniSesID &v) \
90 { \
91  UT::Format::Writer w(buffer, buffer_size); \
92  UT::Format::Formatter f; \
93  return f.format(w, #UniSesID "({}={}:{})", {v.exintValue(), \
94  v.graphID().exintValue(), v.localID().exintValue()}); \
95 } \
96 inline size_t \
97 UTformatBuffer(char *buffer, size_t buffer_size, const UT_Array<UniSesID> &v) \
98 { \
99  UT::Format::Writer w(buffer, buffer_size); \
100  UT::Format::Formatter f; \
101  size_t bytesWritten = w("UT_Array<" #UniSesID ">([", \
102  sizeof("UT_Array<" #UniSesID ">([")-1); \
103  bool first = true; \
104  for (auto &&item : v) \
105  { \
106  bytesWritten += f.format(w, first ? "{}" : ", {}", \
107  {item.exintValue()}); \
108  first = false; \
109  } \
110  bytesWritten += w("])", 2); \
111  return bytesWritten; \
112 } \
113 
118 
119 #endif
120 
#define UNI_SESSION_ID_FORMATTER(UniSesID)
String formatting ID for debug printouts, etc:
Definition: UNI_SessionID.h:87
UNI_SessionID(UNI_GraphID graph_id, LOCAL_ID local_id)
Definition: UNI_SessionID.h:60
#define UNI_API
Definition: UNI_API.h:11
exint NumericType
Numerical representation of the ID.
Definition: UNI_ID.h:29
LOCAL_ID localID() const
Returns the local ID of an item, locating it within the given graph.
Definition: UNI_SessionID.h:71
GLuint id
Definition: glcorearb.h:655
UNI_SessionIDCoder(UNI_ID::NumericType session_id_number)
Creates a unique global ID from a raw numerical value.
Definition: UNI_SessionID.h:30
UNI_ID::NumericType decodeItemID() const
Returns the numeric value of the item ID encoded in this session ID.
UNI_SessionID(UNI_ID::NumericType id=INVALID_ID)
Creates a unique global ID from a raw numerical value.
Definition: UNI_SessionID.h:54
UNI_GraphID decodeGraphID() const
Returns the graph ID encoded in this session ID.
UNI_GraphID graphID() const
Returns the UNI graph ID encoded in this session ID.
Definition: UNI_SessionID.h:65
constexpr NumericType numericValue() const
Returns the numeric value of this ID.
Definition: UNI_ID.h:68
Definition: UNI_ID.h:25
static constexpr NumericType INVALID_ID
Definition: UNI_ID.h:30