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 <iosfwd>
20 
21 class UT_String;
22 class UT_WorkBuffer;
23 
24 
25 // In addition to alphanumeric and '_' characters, these are the characters
26 // that are legal in the operator type name.
27 // '.' - allowed for version numbering
28 // ':' - used for namespaces
29 // '/' - used for namespaces (scoping within another operator, which requires
30 // a slash for "table/opname" specification)
31 #define OTL_LEGAL_OPTYPE_NAME_CHARS ".:/"
32 
33 
35 {
36 public:
38 
39  OP_OTLDefinition(const OP_OTLDefinition &definition) = default;
40  OP_OTLDefinition &operator=(const OP_OTLDefinition &src) = default;
41 
42  const UT_StringHolder &getName() const
43  { return myName; }
45  { myName = name; }
46  const UT_StringHolder &getLabel() const
47  { return myLabel; }
49  { myLabel = label; }
50  const UT_StringHolder &getPath() const
51  { return myPath; }
53  { myPath = path; }
54  const UT_StringHolder &getIcon() const
55  { return myIcon; }
56  void setIcon(const UT_StringHolder &icon)
57  { myIcon = icon; }
58  const UT_StringHolder &getAuthor() const
59  { return myAuthor; }
60  void setAuthor(const UT_StringHolder &author)
61  { myAuthor = author; }
63  { return myCopyright; }
64  void setCopyright(const UT_StringHolder &copyright)
65  { myCopyright = copyright; }
67  { return myOpTableName; }
68  void setOpTableName(const UT_StringHolder &optablename)
69  { myOpTableName = optablename; }
71  { return myIndexPath; }
72  void setIndexPath(const UT_StringHolder &indexpath)
73  { myIndexPath = indexpath; }
75  { return myIndexFile; }
76  void setIndexFile(const UT_StringHolder &indexfile)
77  { myIndexFile = indexfile; }
79  { return myLicenseInfo; }
80  void setLicenseInfo(const UT_StringHolder &licenseinfo)
81  { myLicenseInfo = licenseinfo; }
83  { return myExtraInfo; }
84  void setExtraInfo(const UT_StringHolder &extrainfo)
85  { myExtraInfo = extrainfo; }
87  { return myUserInfo; }
88  void setUserInfo(const UT_StringHolder &userinfo)
89  { myUserInfo = userinfo; }
90  int getMinInputs() const
91  { return myMinInputs; }
92  void setMinInputs(int inputs)
93  { myMinInputs = inputs; }
94  int getMaxInputs() const
95  { return myMaxInputs; }
96  void setMaxInputs(int inputs)
97  { myMaxInputs = inputs; }
98  int getMaxOutputs() const
99  { return myMaxOutputs; }
100  void setMaxOutputs(int outputs)
101  { myMaxOutputs = outputs; }
102  int getModTime() const
103  { return myModTime; }
104  void setModTime(int modtime)
105  { myModTime = modtime; }
106  bool getIsSubnet() const
107  { return myIsSubnet; }
108  void setIsSubnet(bool issubnet)
109  { myIsSubnet = issubnet ? 1 : 0; }
110  bool getIsPython() const
111  { return myIsPython; }
112  void setIsPython(bool ispython)
113  { myIsPython = ispython ? 1 : 0; }
114  bool getIsDummyDefinition() const
115  { return myIsDummyDefinition; }
116  void setIsDummyDefinition(bool isdummy)
117  { myIsDummyDefinition = isdummy ? 1 : 0; }
119  { return myCachedLicenseType; }
121  { myCachedLicenseType = type; }
122 
123  /// Return if this is an internally defined operator
124  bool isInternal() const
125  { return myPath == theInternalPath.asRef(); }
126 
127  /// Mark as internal
129  { setPath(theInternalPath.asHolder()); }
130 
131  // Handle options that appear in index files (-icon, -inputs, etc.).
132  int handleOption(int argc, char *argv[]);
133  // Concatenates the op table name and the op name to get a unique name.
134  void getTableAndName(UT_WorkBuffer &name) const;
135  void getTableAndName(UT_String &name) const;
136 
137  // Converts the table name into an OP_OpTypeId.
138  OP_OpTypeId getOpTypeId() const;
139 
140  bool load(UT_IStream &is,
141  UT_StringHolder *errors = nullptr);
142  bool save(std::ostream &os);
143  // Writes a text description that is easily readable by the user.
144  void writeTextDescription(UT_WorkBuffer &buffer,
145  const char *indent = 0) const;
146  // Writes a text description based on the format string. The format
147  // string is a series of characters. Each character represents one
148  // piece of information. The information is output on a single line.
149  void writeFormattedText(UT_WorkBuffer &buffer,
150  const char *format) const;
151  // Read in a text description written out as above. We return false if an
152  // invalid or malformed description is found. We return true if we read in
153  // a good description _or_ if we reach the end of the stream before even
154  // starting a description.
155  bool readTextDescription(UT_IStream &is);
156 
157  /// Returns an official name of the library section that contains
158  /// the HDA definition eg "Object/hda", or "artistA::Object/hda::2.0".
159  /// See UT_OpUtils::getOpTypeDefSectionName() for more details.
160  /// @{
161  void getDefinitionSectionName(UT_String &sectname) const;
162  void getDefinitionSectionName(UT_WorkBuffer &sectname) const;
163  /// @}
164 
165  /// Returns an official file path that should be used for a given
166  /// definition, eg "oplib:/Object/hda?Object/hda".
167  void constructDefinitionPath(UT_String &path) const;
168 
169  /// Utility function for converting a string to a modification time.
170  static int getModTimeFromString(const char *str);
171 
172  /// Returns true if the name is a valid operator name that can be used for
173  /// an OP_Operator instance.
174  static bool isValidOperatorName(const char *name);
175 
176  /// Returns true if op_name includes a namespace and that namesapce
177  /// matches the given scope_opname, e.g., op_name of "Object/geo::op"
178  /// matches scope_name of "Object/geo".
179  /// If op_name does not include a namespace, it is allowed everywhere,
180  /// so it will match any scope, thus this function will return true.
181  /// Returns false otherwise.
182  static bool isMatchingNamespaceScope( const char *op_name,
183  const char *scope_opname );
184 
185 private:
186  UT_StringHolder myName;
187  UT_StringHolder myLabel;
188  UT_StringHolder myPath;
189  UT_StringHolder myIcon;
190  UT_StringHolder myAuthor;
191  UT_StringHolder myCopyright;
192  UT_StringHolder myOpTableName;
193  UT_StringHolder myIndexPath;
194  UT_StringHolder myIndexFile;
195  UT_StringHolder myLicenseInfo;
196  UT_StringHolder myExtraInfo;
197  UT_StringHolder myUserInfo;
198  int32 myMinInputs;
199  int32 myMaxInputs;
200  int32 myMaxOutputs;
201  int32 myModTime;
202  char myIsSubnet;
203  char myIsPython;
204  char myIsDummyDefinition;
205  OP_OTLLicenseType myCachedLicenseType;
206 
207  // Path value that marks definition as isInternal()
208  static const UT_StringLit theInternalPath;
209 };
210 
212 
213 #endif
214 
UT_ValArray< OP_OTLDefinition * > OP_OTLDefinitionArray
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
void setLicenseInfo(const UT_StringHolder &licenseinfo)
const UT_StringHolder & getLicenseInfo() const
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
bool getIsPython() const
const UT_StringHolder & getUserInfo() const
const UT_StringHolder & getLabel() const
void setIsSubnet(bool issubnet)
void setMaxOutputs(int outputs)
void setUserInfo(const UT_StringHolder &userinfo)
GLuint buffer
Definition: glcorearb.h:659
const UT_StringHolder & getIcon() const
bool getIsDummyDefinition() const
const UT_StringHolder & getAuthor() const
void setLabel(const UT_StringHolder &label)
bool isInternal() const
Return if this is an internally defined operator.
void setIcon(const UT_StringHolder &icon)
void setExtraInfo(const UT_StringHolder &extrainfo)
const UT_StringHolder & getPath() const
void setIsPython(bool ispython)
OP_OTLLicenseType getCachedLicenseType() const
int getMaxInputs() const
void setCopyright(const UT_StringHolder &copyright)
OP_OpTypeId
Definition: OP_OpTypeId.h:15
GLuint const GLchar * name
Definition: glcorearb.h:785
int int32
Definition: SYS_Types.h:35
void setName(const UT_StringHolder &name)
int getMinInputs() const
int getModTime() const
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:107
void setMinInputs(int inputs)
void setPath(const UT_StringHolder &path)
void setIndexFile(const UT_StringHolder &indexfile)
#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)
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
void setOpTableName(const UT_StringHolder &optablename)
const UT_StringHolder & getName() const
void setPathToInternal()
Mark as internal.
void setAuthor(const UT_StringHolder &author)
bool getIsSubnet() const
void setModTime(int modtime)
const UT_StringHolder & getIndexPath() const
void setIsDummyDefinition(bool isdummy)
void setMaxInputs(int inputs)
const UT_StringHolder & getCopyright() const
const UT_StringHolder & getOpTableName() const
const UT_StringHolder & getExtraInfo() const
GLenum src
Definition: glcorearb.h:1792