HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PRM_RefId.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: PRM_RefId.h (PRM Library, C++)
7  *
8  * COMMENTS: A simple pair class of parm index and sub index.
9  */
10 
11 #ifndef __PRM_REFID_H_INCLUDED__
12 #define __PRM_REFID_H_INCLUDED__
13 
14 #include "PRM_API.h"
15 #include <UT/UT_Assert.h>
16 #include <SYS/SYS_Math.h>
17 
18 class UT_String;
19 class CH_Channel;
20 class PRM_ParmList;
21 
23 {
24 public:
26  {
27  myParmIndex = -1;
28  myParmSubIndex = -1;
29  }
30  PRM_RefId(int pi, int vi)
31  : myParmIndex(pi)
32  , myParmSubIndex(vi)
33  {
34  }
35 
36  PRM_RefId( const PRM_RefId &copy ) = default;
37 
38  PRM_RefId &operator =( const PRM_RefId &copy ) = default;
39 
40  bool isValid() const
41  { return myParmIndex >= 0; }
42 
43  void setParmRef( int parm_index, int sub_index = -1 )
44  {
45  myParmIndex = parm_index;
46  myParmSubIndex = sub_index;
47  }
48  int getParmRef() const
49  {
50  UT_ASSERT_P( isValid() );
51  return myParmIndex;
52  }
53  void setParmSubIndex(int sub_index)
54  {
55  myParmSubIndex = sub_index;
56  }
57  int getParmSubIndex() const
58  {
59  UT_ASSERT_P( isValid() );
60  return myParmSubIndex;
61  }
62 
63  unsigned hash() const
64  {
65  return SYSwang_inthash(
66  myParmIndex * 1024 + myParmSubIndex
67  );
68  }
69  int operator==( const PRM_RefId &other) const
70  {
71  return( myParmIndex == other.myParmIndex &&
72  myParmSubIndex == other.myParmSubIndex );
73  }
74  // matches() is like operator==() except it also takes into account -1
75  // subindices to mean there's no info about them
76  bool matches(const PRM_RefId &other) const
77  {
78  if (myParmIndex != other.myParmIndex)
79  return false;
80  if (myParmSubIndex == -1 || other.myParmSubIndex == -1)
81  return true;
82  return (myParmSubIndex == other.myParmSubIndex);
83  }
84 
85  void getToken(const PRM_ParmList &parmlist, UT_String &token) const;
86  void getAlias(const PRM_ParmList &parmlist, UT_String &alias) const;
87 
88 private:
89  int myParmIndex;
90  int myParmSubIndex;
91 };
92 
93 #endif // __PRM_REFID_H_INCLUDED__
void setParmRef(int parm_index, int sub_index=-1)
Definition: PRM_RefId.h:43
int getParmRef() const
Definition: PRM_RefId.h:48
PRM_RefId(int pi, int vi)
Definition: PRM_RefId.h:30
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:125
int getParmSubIndex() const
Definition: PRM_RefId.h:57
PRM_RefId()
Definition: PRM_RefId.h:25
int operator==(const PRM_RefId &other) const
Definition: PRM_RefId.h:69
unsigned hash() const
Definition: PRM_RefId.h:63
bool matches(const PRM_RefId &other) const
Definition: PRM_RefId.h:76
void setParmSubIndex(int sub_index)
Definition: PRM_RefId.h:53
bool isValid() const
Definition: PRM_RefId.h:40
#define PRM_API
Definition: PRM_API.h:10