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 
18 #include "UT_IndexedHashSet.h"
19 #include "UT_IndexedHashSetImpl.h"
20 #include "UT_NonCopyable.h"
21 #include "UT_StringHolder.h"
22 
23 #include <iosfwd>
24 
26 {
27 public:
29  ~UT_SharedString();
30 
32 
33  const UT_StringHolder &get(const UT_StringRef &str)
34  {
35  if (!str.isstring())
37 
38  UT_IndexedHashSetItemId id = myStrings.add(str);
39  return *myStrings.get(id);
40  }
41 
42  void free(const UT_StringRef &str)
43  {
44  if (str.isstring())
45  myStrings.remove(UTmakeUnsafeRef(str));
46  }
47  void outputStats();
48  void dumpTable(std::ostream &os);
49 
50  // Old-school
52  { return get(str); }
53  void freeString(const UT_StringRef &str)
54  { return free(str); }
55 private:
57 };
58 
59 #endif
exint UT_IndexedHashSetItemId
Each item in the shared map is assigned a unique id.
#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.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
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)
SYS_FORCE_INLINE bool isstring() const