HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  }
36  {
37  }
38 
39  PRM_RefId( const PRM_RefId &copy )
40  {
41  myParmIndex = copy.myParmIndex;
42  myParmSubIndex = copy.myParmSubIndex;
43  }
44 
45 
46  const PRM_RefId &operator =( const PRM_RefId &copy )
47  {
48  if( &copy != this )
49  {
50  myParmIndex = copy.myParmIndex;
51  myParmSubIndex = copy.myParmSubIndex;
52  }
53  return *this;
54  }
55 
56  bool isValid() const
57  { return myParmIndex >= 0; }
58 
59  void setParmRef( int parm_index, int sub_index = -1 )
60  {
61  myParmIndex = parm_index;
62  myParmSubIndex = sub_index;
63  }
64  int getParmRef() const
65  {
66  UT_ASSERT_P( isValid() );
67  return myParmIndex;
68  }
69  void setParmSubIndex(int sub_index)
70  {
71  myParmSubIndex = sub_index;
72  }
73  int getParmSubIndex() const
74  {
75  UT_ASSERT_P( isValid() );
76  return myParmSubIndex;
77  }
78 
79  unsigned hash() const
80  {
81  return SYSwang_inthash(
82  myParmIndex * 1024 + myParmSubIndex
83  );
84  }
85  int operator==( const PRM_RefId &other) const
86  {
87  return( myParmIndex == other.myParmIndex &&
88  myParmSubIndex == other.myParmSubIndex );
89  }
90  // matches() is like operator==() except it also takes into account -1
91  // subindices to mean there's no info about them
92  bool matches(const PRM_RefId &other) const
93  {
94  if (myParmIndex != other.myParmIndex)
95  return false;
96  if (myParmSubIndex == -1 || other.myParmSubIndex == -1)
97  return true;
98  return (myParmSubIndex == other.myParmSubIndex);
99  }
100 
101  void getToken(const PRM_ParmList &parmlist, UT_String &token) const;
102  void getAlias(const PRM_ParmList &parmlist, UT_String &alias) const;
103 
104 private:
105  int myParmIndex;
106  int myParmSubIndex;
107 };
108 
109 #endif // __PRM_REFID_H_INCLUDED__
void setParmRef(int parm_index, int sub_index=-1)
Definition: PRM_RefId.h:59
~PRM_RefId()
Definition: PRM_RefId.h:35
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
int getParmRef() const
Definition: PRM_RefId.h:64
PRM_RefId(int pi, int vi)
Definition: PRM_RefId.h:30
int getParmSubIndex() const
Definition: PRM_RefId.h:73
PRM_RefId()
Definition: PRM_RefId.h:25
int operator==(const PRM_RefId &other) const
Definition: PRM_RefId.h:85
unsigned hash() const
Definition: PRM_RefId.h:79
PRM_RefId(const PRM_RefId &copy)
Definition: PRM_RefId.h:39
bool matches(const PRM_RefId &other) const
Definition: PRM_RefId.h:92
void setParmSubIndex(int sub_index)
Definition: PRM_RefId.h:69
bool isValid() const
Definition: PRM_RefId.h:56
#define PRM_API
Definition: PRM_API.h:10