HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_SharedString.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_SharedString.h ( UT Library, C++)
7  *
8  * COMMENTS: Container class for a shared string database. This can be used
9  * when you need to allocate many strings where there are
10  * potentially a lot of duplicate string values.
11  */
12 
13 #ifndef __UT_SharedString__
14 #define __UT_SharedString__
15 
16 #include "UT_API.h"
17 #include <iosfwd>
18 #include "UT_SymbolTable.h"
19 #include "UT_IndexedHashMapT.h"
20 
22 public:
24 
25  const char *get(const char *str)
26  {
27  if (!str || *str == '\0')
28  return theEmptySharedString;
29 
31  ptr = myMap.add(str);
32  return ptr->getKey().getString();
33  }
34 
35  void free(const char *str)
36  {
37  if (str && str != theEmptySharedString)
38  myMap.remove(str);
39  }
40  void outputStats();
41  void dumpTable(std::ostream &os);
42 
43  // Old-school
44  const char *allocString(const char *str) { return get(str); }
45  void freeString(const char *str) { return free(str); }
46 
47 private:
48  static const char *theEmptySharedString;
49  UT_IndexedStringMap myMap;
50 };
51 
52 #endif
png_voidp ptr
Definition: png.h:2145
#define UT_API
Definition: UT_API.h:13
const char * allocString(const char *str)
void free(const char *str)
void freeString(const char *str)