HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_OpUtils.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: UT_OpUtils.h ( UT Library, C++)
7  *
8  * COMMENTS: Utility functions for basic manipulation of operator type names.
9  */
10 
11 #ifndef __UT_OpUtils__
12 #define __UT_OpUtils__
13 
14 #include "UT_API.h"
15 #include "UT_StringHolder.h"
16 
17 class UT_String;
18 class UT_StringArray;
19 class UT_WorkBuffer;
20 
22 {
23 public:
24  // In addition to alphanumeric and '_' characters, these are the characters
25  // that are legal in the operator type name.
26  // '.' - allowed for version numbering
27  // ':' - used for namespaces
28  // '/' - used for namespaces (scoping within another operator,
29  // which requires a slash for "table/opname" specification)
30  static constexpr auto theSafeNodeTypeNameChars = UT_StringLit(".:/");
31 
32  /// Returns true if the given name is a valid node operator type name.
33  /// @p extra_legal_chars - other special characters that are valid
34  /// in addition to the ones allowed for OP node types.
35  /// Used for supersets of OP node types.
36  static bool isValidNodeTypeName(const UT_StringRef &op_type_name,
37  const UT_StringRef &extra_legal_chars = UT_StringRef());
38 
39  /// Utility function to combine an index file path and a section name into
40  /// a section path according to the standard convention (using
41  /// UT_SECTION_SEPARATOR_CHAR, '?', as a separator).
42  /// E.g.,
43  /// "/path/to/index_file" and "section_name" -->
44  /// "/path/to/index_file?section_name".
45  /// Note, some non-standard index file file protocols may use '?' for
46  /// other purposses than separating a section name (eg "http:/foo?bar=baz"),
47  /// and this function should not be used for such paths.
48  static void combineStandardIndexFileSectionPath(
49  UT_String &source_section_path,
50  const char *index_file_path,
51  const char *section_name);
52 
53  /// Utility function to split the source path into an index file path
54  /// and a section name, if the source indeed refers to an index file section
55  /// (according to the standard convention of using
56  /// UT_SECTION_SEPARATOR_CHAR, '?', as a separator).
57  /// If source_section_path refers to a section, then index_file_path is set
58  /// to the index file and section_name to the name.
59  /// If source_section_path does not refer to any section, then
60  /// index_file_path is set to the original path and section_name to an empty
61  /// string.
62  /// Note, some non-standard index file file protocols may use '?' for
63  /// other purposses than separating a section name (eg "http:/foo?bar=baz"),
64  /// and this function should not be used for such paths.
65  /// Returns true if the original path indeed contains a section name.
66  static bool splitStandardIndexFileSectionPath(
67  const char *source_section_path,
68  UT_String &index_file_path,
69  UT_String &section_name);
70 
71  /// @{
72  /// Utility functions to check if the path starts with standard prefixes.
73  static bool startsWithOpDefPrefix(const char *path);
74  static bool startsWithOpLibPrefix(const char *path);
75  static bool startsWithOpDataBlockPrefix(const char *path);
76  /// @}
77 
78  /// @{
79  /// Returns a path that refers to an index file section within an
80  /// OTL library or within an HDA definition depending on the path prefix.
81  /// For example, the path may be "opdef:/Object/hda?section" or
82  /// "opdef:/artistA::Object/hda::2.0?section, etc, and for
83  /// nested sections with section array containing ["outer.idx", "inner"],
84  /// the path may be "opdef:/Object/hda?outer.idx?inner".
85  /// @param[out] path Will contain the path pointing to the section.
86  /// @param[in] prefix The prefix specifying the type of the main
87  /// index file (OTL or HDA), and should be either
88  /// UT_OTL_LIBRARY_PREFIX (ie, "oplib:") or
89  /// UT_HDA_DEFINITION_PREFIX (ie, "opdef:").
90  /// @param[in] table_and_opname The operator type name including
91  /// the table name. This specifies the operator
92  /// type OTL library or HDA definition that contains
93  /// the section. This argument value can be obtained
94  /// from combineTableAndOpName() method.
95  /// @param[in] section_name A string that specifies the section
96  /// name that the final path is supposed to refer to.
97  /// This is the section directly inside the OTL library
98  /// or HDA definition index file.
99  /// @param[in] section_names A string array that specifies a sequence
100  /// of sections, if the final innermost section
101  /// is nested within other sections (that themselves
102  /// are index files). For such nested sections,
103  /// the outer sections (the ones that are index
104  /// files themselves) are earlier in the array, and
105  /// the innermost section is at the end of the array.
106  static void combineOpIndexFileSectionPath(UT_String &path,
107  const char *prefix,
108  const char *table_and_opname,
109  const char *section_name );
110  static void combineOpIndexFileSectionPath(UT_String &path,
111  const char *prefix,
112  const char *table_and_opname,
113  const UT_StringArray &section_names );
114  /// @}
115 
116  /// @{
117  /// A fuction to split the original opdef or oplib source path into the
118  /// the prefix, table-and-opname, and section name components.
119  /// The path should start with either UT_OTL_LIBRARY_PREFIX (ie, "oplib:"),
120  /// or UT_HDA_DEFINITION_PREFIX (ie, "opdef:").
121  /// Eg,
122  /// "oplib:/Object/hda?Object/hda" -> "oplib:", "Object/hda", "Object/hda"
123  /// "opdef:/Object/hda?section" -> "opdef:", "Object/hda", "section"
124  /// "opdef:.?section" -> "opdef:", ".", "section"
125  /// "opdef:/Sop/hda?outer?inner" -> "opdef:", "Sop/hda", ["outer", "inner"]
126  ///
127  /// @param[in] path The original source path to split.
128  /// @param[out] prefix The prefix specifying the type of the main
129  /// index file (OTL or HDA), and will be either
130  /// UT_OTL_LIBRARY_PREFIX (ie, "oplib:") or
131  /// UT_HDA_DEFINITION_PREFIX (ie, "opdef:").
132  /// @param[out] table_and_opname The operator type name including
133  /// the table name. This will specifie the operator
134  /// type OTL library or HDA definition that contains
135  /// the section. This argument can be further
136  /// parsed with splitTableAndOpName() method.
137  /// @param[out] section_name If the original source path is expected
138  /// to contain only one section (ie, no nested section)
139  /// then this string parameter will contain the name of
140  /// that section. It is an error to use it for paths with
141  /// nested sections, and the string array argument should
142  /// be used instead.
143  /// @param[out] section_names If the original source path refers to
144  /// a section that is nested within other
145  /// sections (that themselves are index files), then
146  /// this parameter is set to these section names, with
147  /// the outermost section at the beginning of the array
148  /// and the innermost section (contained within the outer
149  /// sections) at the end of the array. If there is just
150  /// a single section, the array will contain a single
151  /// entry (the single section name)
152  static void splitOpIndexFileSectionPath(const char *path,
153  UT_String *prefix,
154  UT_String *table_and_opname,
155  UT_String *section);
156  static void splitOpIndexFileSectionPath(const char *path,
157  UT_String *prefix,
158  UT_String *table_and_opname,
159  UT_StringArray &section_names );
160  static void splitOpIndexFileSectionPath(const char *path,
161  UT_WorkBuffer *prefix,
162  UT_WorkBuffer *table_and_opname,
163  UT_StringArray *section_names );
164  /// @}
165 
166 
167  /// Returns the official name of the OTL library section that contains
168  /// the HDA definition. Eg "Object/hda", or "artistA::Object/hda::2.0"
169  static void getOpTypeDefSectionName(UT_String &sectname,
170  const char *table_name,
171  const char *op_name);
172 
173  /// @{
174  /// Obtains a full name with a table from a table name and op name (which
175  /// may include namespaces and version tags, but not a table name).
176  /// Eg, "Object" and "artistA::hda::2.0" -> "artistA::Object/hda::2.0"
177  static void combineTableAndOpName(UT_WorkBuffer & table_and_opname,
178  const char *table_name,
179  const char *op_name);
180  static void combineTableAndOpName(UT_String & table_and_opname,
181  const char *table_name,
182  const char *op_name);
183  /// @}
184 
185  /// @{
186  /// Obtains a table name and an operator name (which may include namespaces
187  /// and version tags, but not a table name) from a string that contains
188  /// a full opname with table name included in it.
189  /// If the table-and-opname has no slash, the table_name will be empty.
190  /// Eg, "artistA::Object/hda::2.0" -> "Object" and "artistA::hda::2.0"
191  static void splitTableAndOpName(const char *table_and_opname,
192  UT_String &table_name,
193  UT_String &op_name);
194  static void splitTableAndOpName(const char *table_and_opname,
195  UT_WorkBuffer &table_name,
196  UT_WorkBuffer &op_name);
197  /// @}
198 
199  /// Obtains a table name from a string that contains a full opname
200  /// with table name included in it. Full name may contain namespaces, etc.
201  /// If the table-and-opname has no slash, the table_name will be empty.
202  /// Eg, "artistA::Object/hda::2.0" -> "Object"
203  /// It's a faster version of splitTableAndOpName() if only table name
204  /// (node type category) is needed, since it does not reconstruct
205  /// the node type name by concatenating and copying components.
206  static UT_StringHolder tableFromTableAndOpName(const char*table_and_opname);
207 
208  /// @{
209  /// Build a full operator type name string that includes a scope operator,
210  /// namespace, op name, and version tags, out of the (separate) components
211  /// given by the arguments.
212  /// The caller can pass NULL for the components that don't apply.
213  /// E.g.,
214  /// NULL, "artistA", "my_op", and "2.0" -> "artistA::my_op::2.0" and
215  /// NULL, "artistA", "Object/my_op", and "2.0" ->
216  /// "artistA::Object/my_op::2.0"
217  /// "Object/light", NULL, "Sop/mybulb", NULL -> "Object/light::Sop/mybulb"
218  /// "vA::Object/outer::1.0", "vB", "Sop/inner", and "2.0" ->
219  /// "vA::Object/outer::1.0::vB:Sop/inner::2.0"
220  static void getFullNameFromComponents(UT_WorkBuffer & full_name,
221  const char *scope_opname,
222  const char *namespace_name,
223  const char *op_name,
224  const char *version);
225  static void getFullNameFromComponents(UT_String & full_name,
226  const char *scope_opname,
227  const char *namespace_name,
228  const char *op_name,
229  const char *version);
230  /// @}
231 
232  /// @{
233  /// Extract the components from a full operator type name.
234  /// The full operator name may include a scope operator (ie, a subnet
235  /// operator only in which 'op_name' operator can be created),
236  /// namespaces and version tag.
237  /// The caller can pass NULL for the components that it's not interested in.
238  /// E.g.,
239  /// "artistA::my_op::2.0" -> NULL, "artistA", "my_op", and "2.0"
240  /// "artistA::Object/my_op::2.0" -> NULL, "artistA", "Object/my_op", "2.0"
241  /// "Object/light::Sop/mybulb" -> "Object/light", NULL, "Sop/mybulb", NULL
242  /// "aA::Object/outer::1.0::aB:Sop/inner::2.0" -> "aA::Object/outer::1.0",
243  /// "aB", "Sop/inner", and "2.0".
244  static void getComponentsFromFullName(const char *full_name,
245  UT_WorkBuffer *scope_opname,
246  UT_WorkBuffer *namespace_name,
247  UT_WorkBuffer *op_name,
249  static void getComponentsFromFullName(const char *full_name,
250  UT_String *scope_opname,
251  UT_String *namespace_name,
252  UT_String *op_name,
253  UT_String *version);
254  /// @}
255 
256  /// @{
257  /// Makes sure the filename is valid on all platforms by converting
258  /// any invalid characters such as slashes and colons to dashes.
259  /// Eg, "ns::Object/hda::1.0" -> "ns-Object-hda-1.0".
260  /// If the file name is already valid, it remains unchanged.
261  static void ensureValidOpBasedFileName(UT_String &filename);
262  static void ensureValidOpBasedFileName(UT_WorkBuffer &filename);
263  /// @}
264 };
265 
266 #endif
267 
GT_API const UT_StringHolder filename
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define UT_API
Definition: UT_API.h:14
UN_API bool isValidNodeTypeName(const UT_StringRef &name, const UT_StringRef &safe_chars=UT_StringRef())
GT_API const UT_StringHolder version