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