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