HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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_StringHolder.h>
24 
26 {
27 public:
28  typedef enum {
31  ENTRY
32  } VOP_ExportedParmType;
33 
35  : myType(ENDGROUP), myNodeId(OP_INVALID_NODE_ID) { }
36  VOP_ExportedParm(const char *groupname)
37  : myType(STARTGROUP), myName(groupname),
38  myNodeId(OP_INVALID_NODE_ID)
39  { }
41  : myType(ENTRY), myNodeId(vop->getUniqueId()) {
42  myName = vop->getParmNameCache();
43  }
44  VOP_ExportedParm(const VOP_ExportedParm &src) = default;
45 
47  { return myType; }
48  const char *getName() const
49  { return myName.c_str(); }
50  void setName(const char *name)
51  { myName = name; }
53  {
54  OP_Node *node = OP_Node::lookupNode(myNodeId);
55  if (!node)
56  return NULL;
57 
58  return VOP_Node::castToParmGenerator(node);
59  }
60  int getOpId() const
61  { return myNodeId; }
62 
63  bool operator==(const VOP_ExportedParm &o) const
64  { return myType == o.myType && myName == o.myName && myNodeId == o.myNodeId; }
65 
66  bool operator!=(const VOP_ExportedParm &o) const
67  { return myType != o.myType || myName != o.myName || myNodeId != o.myNodeId; }
68 
69 private:
70  VOP_ExportedParmType myType;
71  UT_StringHolder myName;
72  int myNodeId;
73 };
74 
76 {
77 public:
79  { }
81  {
82  clear();
83 
84  int i;
85  for (i=0; i<src_list.entries(); i++)
86  append(src_list(i));
87  }
89  { clear(); }
90 
92  {
93  if (&src != this)
94  {
95  int i;
96  clear();
97  for (i=0; i<src.entries(); i++)
98  append(src(i));
99  }
100  return *this;
101  }
103  {
104  int i;
105  if (entries() != src.entries())
106  return false;
107  for (i = 0; i < entries(); ++i)
108  if ((*this)(i) != src(i))
109  return false;
110  return true;
111  }
112  bool operator!=(const VOP_ExportedParmList &s) const
113  { return !(*this == s); }
114 
115  void append(const VOP_ExportedParm &parm)
116  {
117  VOP_ExportedParm *new_parm;
118  new_parm = new VOP_ExportedParm(parm);
119 
120  myParms.append(new_parm);
121  myParmNodes[new_parm->getOpId()] = new_parm;
122  }
123  void insert(const VOP_ExportedParm &parm, int idx)
124  {
125  VOP_ExportedParm *new_parm;
126  new_parm = new VOP_ExportedParm(parm);
127 
128  myParms.insert(new_parm, idx);
129  myParmNodes[new_parm->getOpId()] = new_parm;
130  }
131  void move(int first, int last, int newpos)
132  {
133  myParms.move(first, last, newpos);
134  }
135  void remove(int idx)
136  {
137  VOP_ExportedParm *parm;
138  int node_id;
139 
140  node_id = myParms(idx)->getOpId();
141  parm = myParms(idx);
142 
143  myParms.removeIndex(idx);
144  myParmNodes.erase(node_id);
145  delete parm;
146  }
147  void clear()
148  {
149  UTdeleteAll(myParms);
150  myParms.clear();
151  myParmNodes.clear();
152  }
153 
154  /// Return the list index of the requested parameter.
155  /// Return -1 if no parameter with the name equal to `parm_name`
156  /// can be found in the list.
157  int getParmIndex(const char *parm_name) const
158  {
159  if (!parm_name)
160  return -1;
161 
162  for (int i=0; i<myParms.entries(); i++)
163  {
164  const char *code_parm_name;
165  code_parm_name = myParms(i)->getName();
166  if (!code_parm_name)
167  continue;
168 
169  if (::strcmp(code_parm_name, parm_name) == 0)
170  return i;
171  }
172 
173  return -1;
174  }
175 
176  /// Return the name of the parameter generated by the given node.
177  /// If no such parameter exists, then return NULL.
178  const char *getParmName(int node_id) const
179  {
180  auto it = myParmNodes.find(node_id);
181  if (it == myParmNodes.end())
182  return nullptr;
183 
184  return it->second->getName();
185  }
186 
187  const VOP_ExportedParm &operator()(int idx) const
188  {
189  return *myParms(idx);
190  }
192  {
193  return *myParms(idx);
194  }
195  int entries() const
196  {
197  return myParms.entries();
198  }
199  bool hasNode(int node_id) const
200  {
201  return myParmNodes.contains(node_id);
202  }
203  bool hasParmName(const char *parm_name) const
204  {
205  if (!parm_name)
206  return false;
207 
208  for (int i=0; i<myParms.entries(); i++)
209  {
210  const char *code_parm_name;
211  code_parm_name = myParms(i)->getName();
212  if (!code_parm_name)
213  continue;
214 
215  if (::strcmp(code_parm_name, parm_name) == 0)
216  return true;
217  }
218 
219  return false;
220  }
221 
222 
223 
224 private:
227 };
228 
229 #endif
GLint first
Definition: glcorearb.h:404
const VOP_ExportedParmList & operator=(const VOP_ExportedParmList &src)
exint removeIndex(exint index)
Definition: UT_Array.h:225
void insert(const VOP_ExportedParm &parm, int idx)
int getOpId() const
#define OP_INVALID_NODE_ID
Definition: OP_Node.h:196
png_uint_32 i
Definition: png.h:2877
VOP_ParmGenerator * getOp() const
void append(const VOP_ExportedParm &parm)
const char * getName() const
VOP_ExportedParm & operator()(int idx)
void UTdeleteAll(ForwardIt begin, ForwardIt end)
Definition: UT_Algorithm.h:232
#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:785
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:446
bool operator==(const VOP_ExportedParmList &src) const
void move(int first, int last, int newpos)
VOP_ExportedParm(const char *groupname)
int getParmIndex(const char *parm_name) const
exint append(void)
Definition: UT_Array.h:95
bool operator==(const VOP_ExportedParm &o) const
static OP_Node * lookupNode(int unique_id, bool include_proxy=false)
Definition: OP_Node.h:675
bool hasNode(int node_id) const
const UT_String & getParmNameCache() const
bool operator!=(const VOP_ExportedParm &o) const
void clear()
Resets list to an empty list.
Definition: UT_Array.h:506
void move(exint srcIdx, exint destIdx, exint howMany)
Definition: UT_ArrayImpl.h:567
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:122
bool contains(const key_type &key) const
Returns true if a value with the key is contained in the map.
Definition: UT_Map.h:141
GLenum src
Definition: glcorearb.h:1792