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 UT_StringHolder &get(const UT_StringRef &str)
26  {
27  if (!str.isstring())
29 
31  ptr = myMap.add(UT_StringHolder(str));
32  return ptr->getKey();
33  }
34 
35  void free(const UT_StringRef &str)
36  {
37  if (str.isstring())
38  myMap.remove(UTmakeUnsafeRef(str));
39  }
40  void outputStats();
41  void dumpTable(std::ostream &os);
42 
43  // Old-school
45  { return get(str); }
46  void freeString(const UT_StringRef &str)
47  { return free(str); }
48 private:
49  UT_IndexedStringMap myMap;
50 };
51 
52 #endif
#define UT_API
Definition: UT_API.h:14
void freeString(const UT_StringRef &str)
const UT_StringHolder & allocString(const UT_StringRef &str)
static const UT_StringHolder theEmptyString
SYS_FORCE_INLINE const UT_StringHolder & UTmakeUnsafeRef(const UT_StringRef &ref)
Convert a UT_StringRef into a UT_StringHolder that is a shallow reference.
void free(const UT_StringRef &str)
UT_API void outputStats(std::ostream &os, exint size, exint bucket_count, exint capacity, float load_factor, float min_load_factor, float max_load_factor)
auto ptr(T p) -> const void *
Definition: format.h:2448
SYS_FORCE_INLINE bool isstring() const