1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: vtkParseString.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 =========================================================================*/
17 String allocation routines used by vtkParse.
19 The parser uses "const char *" as its string object type, and expects
20 all string objects to persist and be constant for the entire lifetime
21 of the data generated by the parse (usually this means until the parser
22 executable has exited). All strings that are stored in the parser's
23 data objects should either be statically allocated, or allocated with
24 the vtkParse_NewString() or vtkParse_CacheString() methods declared here.
27 #ifndef VTK_PARSE_STRING_H
28 #define VTK_PARSE_STRING_H
37 * StringCache provides a simple way of allocating strings centrally.
38 * It eliminates the need to allocate and free each individual strings,
39 * which makes the code simpler and more efficient.
41 typedef struct _StringCache
43 unsigned long NumberOfChunks;
50 * Initialize the string cache.
52 void vtkParse_InitStringCache(StringCache *cache);
55 * Alocate a new string from the cache.
56 * A total of n+1 bytes will be allocated, to leave room for null.
58 char *vtkParse_NewString(StringCache *cache, size_t n);
61 * Cache a string so that it can then be used in the vtkParse data
62 * structures. The string will last until the application exits.
63 * At most 'n' chars will be copied, and the string will be terminated.
64 * If a null pointer is provided, then a null pointer will be returned.
66 const char *vtkParse_CacheString(StringCache *cache, const char *cp, size_t n);
69 * Free all strings that were created with vtkParse_NewString() or
70 * with vtkParse_CacheString().
72 void vtkParse_FreeStringCache(StringCache *cache);