HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OTLDefinition.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: OP_OTLDefinition.h ( OTL Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __OP_OTLDefinition__
13 #define __OP_OTLDefinition__
14 
15 #include "OP_API.h"
16 #include "OP_Node.h"
17 #include <UT/UT_StringHolder.h>
18 #include <UT/UT_ValArray.h>
19 #include <UT/UT_Color.h>
20 #include <iosfwd>
21 #include <time.h>
22 
23 class UT_String;
24 class UT_WorkBuffer;
25 
26 
27 // In addition to alphanumeric and '_' characters, these are the characters
28 // that are legal in the operator type name.
29 // '.' - allowed for version numbering
30 // ':' - used for namespaces
31 // '/' - used for namespaces (scoping within another operator, which requires
32 // a slash for "table/opname" specification)
33 #define OTL_LEGAL_OPTYPE_NAME_CHARS ".:/"
34 
36 {
37 public:
38  OP_ExtraInfoBuffer() = default;
39  OP_ExtraInfoBuffer(const char *extra_info)
40  { readExtraInfo(extra_info); }
41 
42  /// Parses the extra info string.
43  /// After this call, you can use the query methods below.
44  void readExtraInfo(const char *extra_info);
45 
46  /// @{ Writes out the extra info state of this object into a string.
47  void writeExtraInfo(UT_WorkBuffer &extra_info) const;
48  void writeExtraInfo(UT_String &extra_info) const;
49  void writeExtraInfo(UT_StringHolder &extra_info) const;
50  /// @}
51 
52  /// True if this is an old format, to ensure we preserve compatibility
53  /// if we re-save.
54  bool oldFormat() const
55  { return (myOptions.getNumOptions() == 1) && (myOptions.hasOption("vopnetmask")); }
56 
57 #define OP_EXTRA_ACCESSOR_COMMON(NAME, TOKEN) \
58  const UT_StringHolder &get##NAME##Token() const \
59  { \
60  static constexpr UT_StringLit token(TOKEN); \
61  return token.asHolder(); \
62  } \
63  void remove##NAME() \
64  { myOptions.removeOption(get##NAME##Token()); } \
65  bool has##NAME() const \
66  { return myOptions.hasOption(get##NAME##Token()); } \
67 /**/
68 
69  // WARNING: You cannot add more boolean accessors as they can't be
70  // recognized in earlier versions.
71 #define OP_EXTRA_ACCESSOR_BOOL(NAME, TOKEN) \
72  OP_EXTRA_ACCESSOR_COMMON(NAME, TOKEN) \
73  bool get##NAME() const \
74  { return myOptions.getOptionB(get##NAME##Token()); } \
75  void set##NAME(bool value) \
76  { myOptions.setOptionB(get##NAME##Token(), value); } \
77  /**/
78 #define OP_EXTRA_ACCESSOR_STRING(NAME, TOKEN) \
79  OP_EXTRA_ACCESSOR_COMMON(NAME, TOKEN) \
80  const UT_StringHolder & \
81  get##NAME() const \
82  { return myOptions.getOptionS(get##NAME##Token()); } \
83  void set##NAME(const UT_StringHolder &value) \
84  { myOptions.setOptionSRaw(get##NAME##Token(),value); } \
85  /**/
86 #define OP_EXTRA_ACCESSOR_INT(NAME, TOKEN) \
87  OP_EXTRA_ACCESSOR_COMMON(NAME, TOKEN) \
88  exint get##NAME() const \
89  { return myOptions.getOptionI(get##NAME##Token()); } \
90  void set##NAME(exint value) \
91  { myOptions.setOptionI(get##NAME##Token(),value); } \
92  /**/
93 
94  // WARNING: You cannot add more boolean accessors as they can't be
95  // recognized in earlier versions.
96  OP_EXTRA_ACCESSOR_BOOL (HideDefaultParms, "hidedefaultparms")
97  OP_EXTRA_ACCESSOR_BOOL (HasObjExtParms, "objextparms")
98  OP_EXTRA_ACCESSOR_STRING(RepresentativeNodePath, "rep")
99  OP_EXTRA_ACCESSOR_STRING(GuideNodePath, "guide")
100  OP_EXTRA_ACCESSOR_STRING(OpSubType, "subtype")
101  OP_EXTRA_ACCESSOR_STRING(ShaderType, "shadertype")
102  OP_EXTRA_ACCESSOR_STRING(RenderMask, "rendermask")
103  OP_EXTRA_ACCESSOR_STRING(VopnetMask, "vopnetmask")
104  OP_EXTRA_ACCESSOR_STRING(PDGType, "pdgtype")
105  OP_EXTRA_ACCESSOR_INT (AlwaysSync, "alwayssync")
106  OP_EXTRA_ACCESSOR_INT (VisibleOutputs, "visibleoutputs")
107  OP_EXTRA_ACCESSOR_STRING(CreateLicenseInfo, "createlicense")
108 
109 private:
110  OP_EXTRA_ACCESSOR_STRING(InputColorsString, "inputcolors")
111  OP_EXTRA_ACCESSOR_STRING(OutputColorsString, "outputcolors")
112 
113 public:
114  bool isBoolToken(const UT_StringRef &name)
115  {
116  return name == getHideDefaultParmsToken()
117  || name == getHasObjExtParmsToken()
118  ;
119  }
121  {
122  return name == getAlwaysSyncToken()
123  || name == getVisibleOutputsToken()
124  ;
125  }
126 
127 #undef OP_EXTRA_ACCESSOR_COMMON
128 #undef OP_EXTRA_ACCESSOR_BOOL
129 #undef OP_EXTRA_ACCESSOR_STRING
130 #undef OP_EXTRA_ACCESSOR_INT
131 
132  bool hasInputColors() const { return hasInputColorsString(); }
133  void removeInputColors() { myInputColors.clear(); removeInputColorsString(); }
134  const UT_Array<UT_Color> &getInputColors() const { return myInputColors; }
135  void setInputColors(const UT_Array<UT_Color> &colors)
136  {
137  myInputColors = colors;
138  setInputColorsString(writeColorString(colors));
139  }
140 
141  bool hasOutputColors() const { return hasOutputColorsString(); }
142  void removeOutputColors() { myOutputColors.clear(); removeOutputColorsString(); }
143  const UT_Array<UT_Color> &getOutputColors() const { return myOutputColors; }
145  {
146  myOutputColors = colors;
147  setOutputColorsString(writeColorString(colors));
148  }
149 
150 private:
151  static void readColorString(UT_Array<UT_Color> &colors, const char *str);
152  static UT_StringHolder writeColorString(const UT_Array<UT_Color> &colors);
153  UT_Options myOptions;
154 
155  UT_Array<UT_Color> myInputColors;
156  UT_Array<UT_Color> myOutputColors;
157 };
158 
160 {
161 public:
163 
164  OP_OTLDefinition(const OP_OTLDefinition &definition) = default;
165  OP_OTLDefinition &operator=(const OP_OTLDefinition &src) = default;
166 
167  const UT_StringHolder &getName() const
168  { return myName; }
170  { myName = name; }
171  const UT_StringHolder &getLabel() const
172  { return myLabel; }
174  { myLabel = label; }
175  const UT_StringHolder &getPath() const
176  { return myPath; }
178  { myPath = path; }
179  const UT_StringHolder &getIcon() const
180  { return myIcon; }
181  void setIcon(const UT_StringHolder &icon)
182  { myIcon = icon; }
183  const UT_StringHolder &getAuthor() const
184  { return myAuthor; }
185  void setAuthor(const UT_StringHolder &author)
186  { myAuthor = author; }
188  { return myCopyright; }
189  void setCopyright(const UT_StringHolder &copyright)
190  { myCopyright = copyright; }
192  { return myOpTableName; }
193  void setOpTableName(const UT_StringHolder &optablename)
194  { myOpTableName = optablename; }
196  { return myIndexPath; }
197  void setIndexPath(const UT_StringHolder &indexpath)
198  { myIndexPath = indexpath; }
200  { return myIndexFile; }
201  void setIndexFile(const UT_StringHolder &indexfile)
202  { myIndexFile = indexfile; }
204  { return myLicenseInfo; }
205  void setLicenseInfo(const UT_StringHolder &licenseinfo)
206  { myLicenseInfo = licenseinfo; }
207 
208  /// Extra operator info. This is stored as a raw string in the OTL
209  /// as the myExtraInfo. The parsed version of the string is kept in
210  /// sync as myExtraInfoBuffer.
212  { return myExtraInfo; }
213  void setExtraInfo(const UT_StringHolder &extrainfo)
214  { myExtraInfo = extrainfo;
215  myExtraInfoBuffer.readExtraInfo(extrainfo);
216  }
218  { return myExtraInfoBuffer; }
220  { myExtraInfoBuffer = buf;
221  UT_WorkBuffer extra;
222  buf.writeExtraInfo(extra);
223  myExtraInfo = std::move(extra);
224  }
225 
227  { return myUserInfo; }
228  void setUserInfo(const UT_StringHolder &userinfo)
229  { myUserInfo = userinfo; }
230  int getMinInputs() const
231  { return myMinInputs; }
232  void setMinInputs(int inputs)
233  { myMinInputs = inputs; }
234  int getMaxInputs() const
235  { return myMaxInputs; }
236  void setMaxInputs(int inputs)
237  { myMaxInputs = inputs; }
239  { return myNumOrderedInputs; }
240  void setNumOrderedInputs(int inputs)
241  { myNumOrderedInputs = inputs; }
242  int getMaxOutputs() const
243  { return myMaxOutputs; }
244  void setMaxOutputs(int outputs)
245  { myMaxOutputs = outputs; }
246  time_t getModTime() const
247  { return myModTime; }
248  void setModTime(time_t modtime)
249  { myModTime = modtime; }
250  bool getIsSubnet() const
251  { return myIsSubnet; }
252  void setIsSubnet(bool issubnet)
253  { myIsSubnet = issubnet ? 1 : 0; }
254  bool getIsPython() const
255  { return myIsPython; }
256  void setIsPython(bool ispython)
257  { myIsPython = ispython ? 1 : 0; }
258  bool getIsDummyDefinition() const
259  { return myIsDummyDefinition; }
260  void setIsDummyDefinition(bool isdummy)
261  { myIsDummyDefinition = isdummy ? 1 : 0; }
263  { return myCachedLicenseType; }
265  { myCachedLicenseType = type; }
266 
267  /// Return if this is an internally defined operator
268  bool isInternal() const
269  { return myPath == theInternalPath.asRef(); }
270 
271  /// Mark as internal
273  { setPath(theInternalPath.asHolder()); }
274 
275  // Handle options that appear in index files (-icon, -inputs, etc.).
276  int handleOption(int argc, char *argv[]);
277  // Concatenates the op table name and the op name to get a unique name.
278  void getTableAndName(UT_WorkBuffer &name) const;
279  void getTableAndName(UT_String &name) const;
280 
281  // Converts the table name into an OP_OpTypeId.
282  OP_OpTypeId getOpTypeId() const;
283 
284  bool load(UT_IStream &is,
285  UT_StringHolder *errors = nullptr);
286  bool save(std::ostream &os);
287  // Writes a text description that is easily readable by the user.
288  void writeTextDescription(UT_WorkBuffer &buffer,
289  const char *indent = 0) const;
290  // Writes a text description based on the format string. The format
291  // string is a series of characters. Each character represents one
292  // piece of information. The information is output on a single line.
293  void writeFormattedText(UT_WorkBuffer &buffer,
294  const char *format) const;
295  // Read in a text description written out as above. We return false if an
296  // invalid or malformed description is found. We return true if we read in
297  // a good description _or_ if we reach the end of the stream before even
298  // starting a description.
299  bool readTextDescription(UT_IStream &is);
300 
301  /// Returns an official name of the library section that contains
302  /// the HDA definition eg "Object/hda", or "artistA::Object/hda::2.0".
303  /// See UT_OpUtils::getOpTypeDefSectionName() for more details.
304  /// @{
305  void getDefinitionSectionName(UT_String &sectname) const;
306  void getDefinitionSectionName(UT_WorkBuffer &sectname) const;
307  /// @}
308 
309  /// Returns an official file path that should be used for a given
310  /// definition, eg "oplib:/Object/hda?Object/hda".
311  void constructDefinitionPath(UT_String &path) const;
312 
313  /// Utility function for converting a string to a modification time.
314  static time_t getModTimeFromString(const char *str);
315 
316  /// Returns true if the name is a valid operator name that can be used for
317  /// an OP_Operator instance.
318  static bool isValidOperatorName(const char *name);
319 
320  /// Returns true if op_name includes a namespace and that namesapce
321  /// matches the given scope_opname, e.g., op_name of "Object/geo::op"
322  /// matches scope_name of "Object/geo".
323  /// If op_name does not include a namespace, it is allowed everywhere,
324  /// so it will match any scope, thus this function will return true.
325  /// Returns false otherwise.
326  static bool isMatchingNamespaceScope( const char *op_name,
327  const char *scope_opname );
328 
329 private:
330  UT_StringHolder myName;
331  UT_StringHolder myLabel;
332  UT_StringHolder myPath;
333  UT_StringHolder myIcon;
334  UT_StringHolder myAuthor;
335  UT_StringHolder myCopyright;
336  UT_StringHolder myOpTableName;
337  UT_StringHolder myIndexPath;
338  UT_StringHolder myIndexFile;
339  UT_StringHolder myLicenseInfo;
340  UT_StringHolder myExtraInfo;
341  OP_ExtraInfoBuffer myExtraInfoBuffer;
342  UT_StringHolder myUserInfo;
343  int32 myMinInputs;
344  int32 myMaxInputs;
345  int32 myNumOrderedInputs;
346  int32 myMaxOutputs;
347  time_t myModTime;
348  char myIsSubnet;
349  char myIsPython;
350  char myIsDummyDefinition;
351  OP_OTLLicenseType myCachedLicenseType;
352 
353  // Path value that marks definition as isInternal()
354  static const UT_StringLit theInternalPath;
355 };
356 
358 
359 #endif
360 
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
UT_ValArray< OP_OTLDefinition * > OP_OTLDefinitionArray
bool hasInputColors() const
int int32
Definition: SYS_Types.h:39
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
void setLicenseInfo(const UT_StringHolder &licenseinfo)
#define OP_EXTRA_ACCESSOR_BOOL(NAME, TOKEN)
#define OP_EXTRA_ACCESSOR_INT(NAME, TOKEN)
const UT_StringHolder & getLicenseInfo() const
GLenum shadertype
Definition: glcorearb.h:1815
#define OP_EXTRA_ACCESSOR_STRING(NAME, TOKEN)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
bool getIsPython() const
const UT_StringHolder & getUserInfo() const
const UT_Array< UT_Color > & getInputColors() const
const UT_StringHolder & getLabel() const
void setIsSubnet(bool issubnet)
int getNumOrderedInputs() const
void setMaxOutputs(int outputs)
void setUserInfo(const UT_StringHolder &userinfo)
const UT_StringHolder & getIcon() const
bool getIsDummyDefinition() const
const UT_StringHolder & getAuthor() const
void setLabel(const UT_StringHolder &label)
bool oldFormat() const
void setNumOrderedInputs(int inputs)
bool isInternal() const
Return if this is an internally defined operator.
void setIcon(const UT_StringHolder &icon)
Definition: core.h:760
void setExtraInfo(const UT_StringHolder &extrainfo)
const UT_StringHolder & getPath() const
void setIsPython(bool ispython)
OP_ExtraInfoBuffer(const char *extra_info)
OP_OTLLicenseType getCachedLicenseType() const
int getMaxInputs() const
void setCopyright(const UT_StringHolder &copyright)
bool hasOutputColors() const
void setModTime(time_t modtime)
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:108
const UT_Array< UT_Color > & getOutputColors() const
OP_OpTypeId
Definition: OP_OpTypeId.h:18
void setOutputColors(const UT_Array< UT_Color > &colors)
void writeExtraInfo(UT_WorkBuffer &extra_info) const
Writes out the extra info state of this object into a string.
GLuint const GLchar * name
Definition: glcorearb.h:786
void setName(const UT_StringHolder &name)
const OP_ExtraInfoBuffer & getExtraInfoBuffer() const
int getMinInputs() const
time_t getModTime() const
A map of string to various well defined value types.
Definition: UT_Options.h:84
void setMinInputs(int inputs)
void setPath(const UT_StringHolder &path)
void setIndexFile(const UT_StringHolder &indexfile)
void setInputColors(const UT_Array< UT_Color > &colors)
LeafData & operator=(const LeafData &)=delete
#define OP_API
Definition: OP_API.h:10
OP_OTLLicenseType
const UT_StringHolder & getIndexFile() const
void setCachedLicenseType(OP_OTLLicenseType type)
int getMaxOutputs() const
void setIndexPath(const UT_StringHolder &indexpath)
void setOpTableName(const UT_StringHolder &optablename)
const UT_StringHolder & getName() const
void setPathToInternal()
Mark as internal.
bool isIntToken(const UT_StringRef &name)
void setAuthor(const UT_StringHolder &author)
bool getIsSubnet() const
const UT_StringHolder & getIndexPath() const
type
Definition: core.h:1059
void setIsDummyDefinition(bool isdummy)
void setMaxInputs(int inputs)
void setExtraInfoBuffer(const OP_ExtraInfoBuffer &buf)
const UT_StringHolder & getCopyright() const
const UT_StringHolder & getOpTableName() const
const UT_StringHolder & getExtraInfo() const
GLenum src
Definition: glcorearb.h:1793