1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: vtkParseExtras.h
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
14 =========================================================================*/
15 /*-------------------------------------------------------------------------
16 Copyright (c) 2011 David Gobbi.
18 Contributed to the VisualizationToolkit by the author in May 2011
19 under the terms of the Visualization Toolkit 2008 copyright.
20 -------------------------------------------------------------------------*/
23 * This file contains extra utilities for parsing and wrapping.
26 #ifndef VTK_PARSE_EXTRAS_H
27 #define VTK_PARSE_EXTRAS_H
29 #include "vtkParseData.h"
37 * Skip over a sequence of characters that begin with an alphabetic
38 * character or an underscore, and include only alphanumeric
39 * characters or underscores. Return the number of characters.
41 size_t vtkParse_IdentifierLength(const char *text);
44 * Skip over a name, including any namespace prefixes and
45 * any template arguments. Return the number of characters.
46 * Examples are "name", "::name", "name<arg>", "name::name2",
47 * "::name::name2<arg1,arg2>".
49 size_t vtkParse_NameLength(const char *text);
52 * Skip over a name, including any template arguments, but stopping
53 * if a '::' is encoutered. Return the number of characters.
54 * Examples are "name" and "name<arg>"
56 size_t vtkParse_UnscopedNameLength(const char *text);
59 * Skip over a literal, which may be a number, a char in single
60 * quotes, a string in double quotes, or a name, or a name followed
61 * by arguments in parentheses.
63 size_t vtkParse_LiteralLength(const char *text);
66 * Get a type from a type name, and return the number of characters used.
67 * If the "classname" argument is not NULL, then it is used to return
68 * the short name for the type, e.g. "long int" becomes "long", while
69 * typedef names and class names are returned unchanged. If "const"
70 * appears in the type name, then the const bit flag is set for the
71 * type, but "const" will not appear in the returned classname.
73 size_t vtkParse_BasicTypeFromString(
74 const char *text, unsigned int *type,
75 const char **classname, size_t *classname_len);
78 * Generate a ValueInfo by parsing the type from the provided text.
79 * Only simple text strings are supported, e.g. "const T **".
80 * Returns the number of characters consumed.
82 size_t vtkParse_ValueInfoFromString(
83 ValueInfo *val, StringCache *cache, const char *text);
86 * Generate a declaration string from a ValueInfo struct. If the
87 * "nf" arg is set, the returned string must be freed.
88 * Only simple text strings are supported, e.g. "const T **".
89 * The variable or typedef name, if present, is ignored.
91 const char *vtkParse_ValueInfoToString(ValueInfo *val, int *nf);
94 * Expand a typedef within a variable, parameter, or typedef declaration.
95 * The expansion is done in-place.
97 void vtkParse_ExpandTypedef(ValueInfo *valinfo, ValueInfo *typedefinfo);
100 * Expand any unrecognized types within a variable, parameter, or typedef
101 * that match any of the supplied typedefs. The expansion is done in-place.
103 void vtkParse_ExpandTypedefs(
104 ValueInfo *valinfo, StringCache *cache,
105 int n, const char *name[], const char *val[],
106 ValueInfo *typedefinfo[]);
109 * Wherever one of the specified names exists inside a Value or inside
110 * a Dimension size, replace it with the corresponding val string.
111 * This is used to replace constants with their values.
113 void vtkParse_ExpandValues(
114 ValueInfo *valinfo, StringCache *cache,
115 int n, const char *name[], const char *val[]);
118 * Search and replace, return the initial string if no replacements
119 * occurred, else return a new string allocated with malloc. */
120 const char *vtkParse_StringReplace(
121 const char *str1, int n, const char *name[], const char *val[]);
124 * Extract the class name and template args from a templated
125 * class type ID. Returns the full number of characters that
126 * were consumed during the decomposition.
128 size_t vtkParse_DecomposeTemplatedType(
129 const char *text, const char **classname,
130 int n, const char ***args, const char *defaults[]);
133 * Free the list of strings returned by ExtractTemplateArgs.
135 void vtkParse_FreeTemplateDecomposition(
136 const char *classname, int n, const char **args);
139 * Instantiate a class template by substituting the provided arguments
140 * for the template parameters. If "n" is less than the number of template
141 * parameters, then default parameter values (if present) will be used.
142 * If an error occurs, the error will be printed to stderr and NULL will
145 void vtkParse_InstantiateClassTemplate(
146 ClassInfo *data, StringCache *cache, int n, const char *args[]);
149 * Instantiate a function or class method template by substituting the
150 * provided arguments for the template parameters. If "n" is less than
151 * the number of template parameters, then default parameter values
152 * (if present) will be used. If an error occurs, the error will be
153 * printed to stderr and NULL will be returned.
155 void vtkParse_IntantiateFunctionTemplate(
156 FunctionInfo *data, int n, const char *args[]);
159 * Get a zero-terminated array of the types in vtkTemplateMacro.
161 const char **vtkParse_GetTemplateMacroTypes();
164 * Get a zero-terminated array of the types in vtkArray.
166 const char **vtkParse_GetArrayTypes();