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