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 
108 private:
109  OP_EXTRA_ACCESSOR_STRING(InputColorsString, "inputcolors")
110  OP_EXTRA_ACCESSOR_STRING(OutputColorsString, "outputcolors")
111 
112 public:
113  bool isBoolToken(const UT_StringRef &name)
114  {
115  return name == getHideDefaultParmsToken()
116  || name == getHasObjExtParmsToken()
117  ;
118  }
120  {
121  return name == getAlwaysSyncToken()
122  || name == getVisibleOutputsToken()
123  ;
124  }
125 
126 #undef OP_EXTRA_ACCESSOR_COMMON
127 #undef OP_EXTRA_ACCESSOR_BOOL
128 #undef OP_EXTRA_ACCESSOR_STRING
129 #undef OP_EXTRA_ACCESSOR_INT
130 
131  bool hasInputColors() const { return hasInputColorsString(); }
132  void removeInputColors() { myInputColors.clear(); removeInputColorsString(); }
133  const UT_Array<UT_Color> &getInputColors() const { return myInputColors; }
134  void setInputColors(const UT_Array<UT_Color> &colors)
135  {
136  myInputColors = colors;
137  setInputColorsString(writeColorString(colors));
138  }
139 
140  bool hasOutputColors() const { return hasOutputColorsString(); }
141  void removeOutputColors() { myOutputColors.clear(); removeOutputColorsString(); }
142  const UT_Array<UT_Color> &getOutputColors() const { return myOutputColors; }
144  {
145  myOutputColors = colors;
146  setOutputColorsString(writeColorString(colors));
147  }
148 
149 private:
150  static void readColorString(UT_Array<UT_Color> &colors, const char *str);
151  static UT_StringHolder writeColorString(const UT_Array<UT_Color> &colors);
152  UT_Options myOptions;
153 
154  UT_Array<UT_Color> myInputColors;
155  UT_Array<UT_Color> myOutputColors;
156 };
157 
159 {
160 public:
162 
163  OP_OTLDefinition(const OP_OTLDefinition &definition) = default;
164  OP_OTLDefinition &operator=(const OP_OTLDefinition &src) = default;
165 
166  const UT_StringHolder &getName() const
167  { return myName; }
169  { myName = name; }
170  const UT_StringHolder &getLabel() const
171  { return myLabel; }
173  { myLabel = label; }
174  const UT_StringHolder &getPath() const
175  { return myPath; }
177  { myPath = path; }
178  const UT_StringHolder &getIcon() const
179  { return myIcon; }
180  void setIcon(const UT_StringHolder &icon)
181  { myIcon = icon; }
182  const UT_StringHolder &getAuthor() const
183  { return myAuthor; }
184  void setAuthor(const UT_StringHolder &author)
185  { myAuthor = author; }
187  { return myCopyright; }
188  void setCopyright(const UT_StringHolder &copyright)
189  { myCopyright = copyright; }
191  { return myOpTableName; }
192  void setOpTableName(const UT_StringHolder &optablename)
193  { myOpTableName = optablename; }
195  { return myIndexPath; }
196  void setIndexPath(const UT_StringHolder &indexpath)
197  { myIndexPath = indexpath; }
199  { return myIndexFile; }
200  void setIndexFile(const UT_StringHolder &indexfile)
201  { myIndexFile = indexfile; }
203  { return myLicenseInfo; }
204  void setLicenseInfo(const UT_StringHolder &licenseinfo)
205  { myLicenseInfo = licenseinfo; }
206 
207  /// Extra operator info. This is stored as a raw string in the OTL
208  /// as the myExtraInfo. The parsed version of the string is kept in
209  /// sync as myExtraInfoBuffer.
211  { return myExtraInfo; }
212  void setExtraInfo(const UT_StringHolder &extrainfo)
213  { myExtraInfo = extrainfo;
214  myExtraInfoBuffer.readExtraInfo(extrainfo);
215  }
217  { return myExtraInfoBuffer; }
219  { myExtraInfoBuffer = buf;
220  UT_WorkBuffer extra;
221  buf.writeExtraInfo(extra);
222  myExtraInfo = std::move(extra);
223  }
224 
226  { return myUserInfo; }
227  void setUserInfo(const UT_StringHolder &userinfo)
228  { myUserInfo = userinfo; }
229  int getMinInputs() const
230  { return myMinInputs; }
231  void setMinInputs(int inputs)
232  { myMinInputs = inputs; }
233  int getMaxInputs() const
234  { return myMaxInputs; }
235  void setMaxInputs(int inputs)
236  { myMaxInputs = inputs; }
238  { return myNumOrderedInputs; }
239  void setNumOrderedInputs(int inputs)
240  { myNumOrderedInputs = inputs; }
241  int getMaxOutputs() const
242  { return myMaxOutputs; }
243  void setMaxOutputs(int outputs)
244  { myMaxOutputs = outputs; }
245  time_t getModTime() const
246  { return myModTime; }
247  void setModTime(time_t modtime)
248  { myModTime = modtime; }
249  bool getIsSubnet() const
250  { return myIsSubnet; }
251  void setIsSubnet(bool issubnet)
252  { myIsSubnet = issubnet ? 1 : 0; }
253  bool getIsPython() const
254  { return myIsPython; }
255  void setIsPython(bool ispython)
256  { myIsPython = ispython ? 1 : 0; }
257  bool getIsDummyDefinition() const
258  { return myIsDummyDefinition; }
259  void setIsDummyDefinition(bool isdummy)
260  { myIsDummyDefinition = isdummy ? 1 : 0; }
262  { return myCachedLicenseType; }
264  { myCachedLicenseType = type; }
265 
266  /// Return if this is an internally defined operator
267  bool isInternal() const
268  { return myPath == theInternalPath.asRef(); }
269 
270  /// Mark as internal
272  { setPath(theInternalPath.asHolder()); }
273 
274  // Handle options that appear in index files (-icon, -inputs, etc.).
275  int handleOption(int argc, char *argv[]);
276  // Concatenates the op table name and the op name to get a unique name.
277  void getTableAndName(UT_WorkBuffer &name) const;
278  void getTableAndName(UT_String &name) const;
279 
280  // Converts the table name into an OP_OpTypeId.
281  OP_OpTypeId getOpTypeId() const;
282 
283  bool load(UT_IStream &is,
284  UT_StringHolder *errors = nullptr);
285  bool save(std::ostream &os);
286  // Writes a text description that is easily readable by the user.
287  void writeTextDescription(UT_WorkBuffer &buffer,
288  const char *indent = 0) const;
289  // Writes a text description based on the format string. The format
290  // string is a series of characters. Each character represents one
291  // piece of information. The information is output on a single line.
292  void writeFormattedText(UT_WorkBuffer &buffer,
293  const char *format) const;
294  // Read in a text description written out as above. We return false if an
295  // invalid or malformed description is found. We return true if we read in
296  // a good description _or_ if we reach the end of the stream before even
297  // starting a description.
298  bool readTextDescription(UT_IStream &is);
299 
300  /// Returns an official name of the library section that contains
301  /// the HDA definition eg "Object/hda", or "artistA::Object/hda::2.0".
302  /// See UT_OpUtils::getOpTypeDefSectionName() for more details.
303  /// @{
304  void getDefinitionSectionName(UT_String &sectname) const;
305  void getDefinitionSectionName(UT_WorkBuffer &sectname) const;
306  /// @}
307 
308  /// Returns an official file path that should be used for a given
309  /// definition, eg "oplib:/Object/hda?Object/hda".
310  void constructDefinitionPath(UT_String &path) const;
311 
312  /// Utility function for converting a string to a modification time.
313  static time_t getModTimeFromString(const char *str);
314 
315  /// Returns true if the name is a valid operator name that can be used for
316  /// an OP_Operator instance.
317  static bool isValidOperatorName(const char *name);
318 
319  /// Returns true if op_name includes a namespace and that namesapce
320  /// matches the given scope_opname, e.g., op_name of "Object/geo::op"
321  /// matches scope_name of "Object/geo".
322  /// If op_name does not include a namespace, it is allowed everywhere,
323  /// so it will match any scope, thus this function will return true.
324  /// Returns false otherwise.
325  static bool isMatchingNamespaceScope( const char *op_name,
326  const char *scope_opname );
327 
328 private:
329  UT_StringHolder myName;
330  UT_StringHolder myLabel;
331  UT_StringHolder myPath;
332  UT_StringHolder myIcon;
333  UT_StringHolder myAuthor;
334  UT_StringHolder myCopyright;
335  UT_StringHolder myOpTableName;
336  UT_StringHolder myIndexPath;
337  UT_StringHolder myIndexFile;
338  UT_StringHolder myLicenseInfo;
339  UT_StringHolder myExtraInfo;
340  OP_ExtraInfoBuffer myExtraInfoBuffer;
341  UT_StringHolder myUserInfo;
342  int32 myMinInputs;
343  int32 myMaxInputs;
344  int32 myNumOrderedInputs;
345  int32 myMaxOutputs;
346  time_t myModTime;
347  char myIsSubnet;
348  char myIsPython;
349  char myIsDummyDefinition;
350  OP_OTLLicenseType myCachedLicenseType;
351 
352  // Path value that marks definition as isInternal()
353  static const UT_StringLit theInternalPath;
354 };
355 
357 
358 #endif
359 
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)
#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.
#define const
Definition: zconf.h:214
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