HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_ExportedParms.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: VOP_ExportedParms.h (VOP Library, C++)
7  *
8  * COMMENTS:
9  *
10  * Exported parameters generated by VOP_ParmGenerator objects.
11  */
12 
13 #ifndef __VOP_ExportedParms_h__
14 #define __VOP_ExportedParms_h__
15 
16 #include "VOP_API.h"
17 
18 #include "VOP_ParmGenerator.h"
19 
20 #include <OP/OP_Node.h>
21 #include <UT/UT_Array.h>
22 #include <UT/UT_Map.h>
23 #include <UT/UT_UniquePtr.h>
24 #include <UT/UT_StringHolder.h>
25 
26 #include <utility>
27 
29 {
30 public:
31  typedef enum {
34  ENTRY
35  } VOP_ExportedParmType;
36 
38  : myType(ENDGROUP), myNodeId(OP_INVALID_NODE_ID) { }
39  VOP_ExportedParm(const char *groupname)
40  : myType(STARTGROUP), myName(groupname),
41  myNodeId(OP_INVALID_NODE_ID)
42  { }
44  : myType(ENTRY), myNodeId(vop->getUniqueId()) {
45  myName = vop->getParmNameCache();
46  }
47  VOP_ExportedParm(const VOP_ExportedParm &src) = default;
48 
50  { return myType; }
51  const char *getName() const
52  { return myName.c_str(); }
53  void setName(const char *name)
54  { myName = name; }
56  {
57  OP_Node *node = OP_Node::lookupNode(myNodeId);
58  if (!node)
59  return NULL;
60 
61  return VOP_Node::castToParmGenerator(node);
62  }
63  int getOpId() const
64  { return myNodeId; }
65 
66  bool operator==(const VOP_ExportedParm &o) const
67  { return myType == o.myType && myName == o.myName && myNodeId == o.myNodeId; }
68 
69  bool operator!=(const VOP_ExportedParm &o) const
70  { return myType != o.myType || myName != o.myName || myNodeId != o.myNodeId; }
71 
72 private:
73  VOP_ExportedParmType myType;
74  UT_StringHolder myName;
75  int myNodeId;
76 };
77 
79 {
80 public:
82  { }
84  {
85  clear();
86 
87  int i;
88  for (i=0; i<src_list.entries(); i++)
89  append(src_list(i));
90  }
92  { clear(); }
93 
95  {
96  if (&src != this)
97  {
98  int i;
99  clear();
100  for (i=0; i<src.entries(); i++)
101  append(src(i));
102  }
103  return *this;
104  }
106  {
107  int i;
108  if (entries() != src.entries())
109  return false;
110  for (i = 0; i < entries(); ++i)
111  if ((*this)(i) != src(i))
112  return false;
113  return true;
114  }
115  bool operator!=(const VOP_ExportedParmList &s) const
116  { return !(*this == s); }
117 
118  void append(const VOP_ExportedParm &parm)
119  {
120  auto new_parm
121  = UTmakeUnique<VOP_ExportedParm>(parm);
122  myParmNodes[new_parm->getOpId()] = new_parm.get();
123  myParms.append(std::move(new_parm));
124  }
125  void insert(const VOP_ExportedParm &parm, int idx)
126  {
127  auto new_parm
128  = UTmakeUnique<VOP_ExportedParm>(parm);
129  myParmNodes[new_parm->getOpId()] = new_parm.get();
130  myParms.insert(std::move(new_parm), idx);
131  }
132  void move(int first, int last, int newpos)
133  {
134  myParms.move(first, last, newpos);
135  }
136  void remove(int idx)
137  {
138  int node_id = myParms(idx)->getOpId();
139  myParmNodes.erase(node_id);
140  myParms.removeIndex(idx);
141  }
142  void clear()
143  {
144  myParms.clear();
145  myParmNodes.clear();
146  }
147 
148  /// Return the list index of the requested parameter.
149  /// Return -1 if no parameter with the name equal to `parm_name`
150  /// can be found in the list.
151  int getParmIndex(const char *parm_name) const
152  {
153  if (!parm_name)
154  return -1;
155 
156  for (int i=0; i<myParms.entries(); i++)
157  {
158  const char *code_parm_name;
159  code_parm_name = myParms(i)->getName();
160  if (!code_parm_name)
161  continue;
162 
163  if (::strcmp(code_parm_name, parm_name) == 0)
164  return i;
165  }
166 
167  return -1;
168  }
169 
170  /// Return the name of the parameter generated by the given node.
171  /// If no such parameter exists, then return NULL.
172  const char *getParmName(int node_id) const
173  {
174  auto it = myParmNodes.find(node_id);
175  if (it == myParmNodes.end())
176  return nullptr;
177 
178  return it->second->getName();
179  }
180 
181  const VOP_ExportedParm &operator()(int idx) const
182  {
183  return *myParms(idx);
184  }
186  {
187  return *myParms(idx);
188  }
189  int entries() const
190  {
191  return myParms.entries();
192  }
193  bool hasNode(int node_id) const
194  {
195  return myParmNodes.contains(node_id);
196  }
197  bool hasParmName(const char *parm_name) const
198  {
199  if (!parm_name)
200  return false;
201 
202  for (int i=0; i<myParms.entries(); i++)
203  {
204  const char *code_parm_name;
205  code_parm_name = myParms(i)->getName();
206  if (!code_parm_name)
207  continue;
208 
209  if (::strcmp(code_parm_name, parm_name) == 0)
210  return true;
211  }
212 
213  return false;
214  }
215 
216 
217 
218 private:
221 };
222 
223 #endif
GLint first
Definition: glcorearb.h:405
const VOP_ExportedParmList & operator=(const VOP_ExportedParmList &src)
void move(exint src_idx, exint dst_idx, exint how_many)
const UT_StringHolder & getParmNameCache() const
GLdouble s
Definition: glad.h:3009
exint removeIndex(exint index)
Definition: UT_Array.h:375
void insert(const VOP_ExportedParm &parm, int idx)
int getOpId() const
void clear()
Definition: UT_Map.h:184
V get(const key_type &key, const V &defval) const
Definition: UT_Map.h:169
#define OP_INVALID_NODE_ID
Definition: OP_ItemId.h:24
VOP_ParmGenerator * getOp() const
void append(const VOP_ExportedParm &parm)
const char * getName() const
VOP_ExportedParm & operator()(int idx)
#define VOP_API
Definition: VOP_API.h:10
void setName(const char *name)
const VOP_ExportedParm & operator()(int idx) const
GLuint const GLchar * name
Definition: glcorearb.h:786
exint append()
Definition: UT_Array.h:142
const char * getParmName(int node_id) const
bool hasParmName(const char *parm_name) const
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
bool operator==(const VOP_ExportedParmList &src) const
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
void move(int first, int last, int newpos)
VOP_ExportedParm(const char *groupname)
int getParmIndex(const char *parm_name) const
bool operator==(const VOP_ExportedParm &o) const
static OP_Node * lookupNode(int unique_id, bool include_proxy=false)
Definition: OP_Node.h:707
bool hasNode(int node_id) const
bool operator!=(const VOP_ExportedParm &o) const
void clear()
Resets list to an empty list.
Definition: UT_Array.h:729
VOP_ExportedParmList(const VOP_ExportedParmList &src_list)
VOP_ExportedParmType getType() const
VOP_ExportedParm(VOP_ParmGenerator *vop)
bool operator!=(const VOP_ExportedParmList &s) const
exint insert(exint index)
Definition: UT_ArrayImpl.h:721
bool contains(const key_type &key) const
Returns true if a value with the key is contained in the map.
Definition: UT_Map.h:159
GLenum src
Definition: glcorearb.h:1793