OpenShot Library | libopenshot-audio  0.1.9
juce_StringPool.h
1 
2 /** @weakgroup juce_core-text
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  A StringPool holds a set of shared strings, which reduces storage overheads and improves
33  comparison speed when dealing with many duplicate strings.
34 
35  When you add a string to a pool using getPooledString, it'll return a character
36  array containing the same string. This array is owned by the pool, and the same array
37  is returned every time a matching string is asked for. This means that it's trivial to
38  compare two pooled strings for equality, as you can simply compare their pointers. It
39  also cuts down on storage if you're using many copies of the same string.
40 
41  @tags{Core}
42 */
44 {
45 public:
46  //==============================================================================
47  /** Creates an empty pool. */
48  StringPool() noexcept;
49 
50  /** Destructor */
51  ~StringPool();
52 
53  //==============================================================================
54  /** Returns a pointer to a shared copy of the string that is passed in.
55  The pool will always return the same String object when asked for a string that matches it.
56  */
57  String getPooledString (const String& original);
58 
59  /** Returns a pointer to a copy of the string that is passed in.
60  The pool will always return the same String object when asked for a string that matches it.
61  */
62  String getPooledString (const char* original);
63 
64  /** Returns a pointer to a shared copy of the string that is passed in.
65  The pool will always return the same String object when asked for a string that matches it.
66  */
67  String getPooledString (StringRef original);
68 
69  /** Returns a pointer to a copy of the string that is passed in.
70  The pool will always return the same String object when asked for a string that matches it.
71  */
72  String getPooledString (String::CharPointerType start, String::CharPointerType end);
73 
74  //==============================================================================
75  /** Scans the pool, and removes any strings that are unreferenced.
76  You don't generally need to call this - it'll be called automatically when the pool grows
77  large enough to warrant it.
78  */
79  void garbageCollect();
80 
81  /** Returns a shared global pool which is used for things like Identifiers, XML parsing. */
82  static StringPool& getGlobalPool() noexcept;
83 
84 private:
85  Array<String> strings;
86  CriticalSection lock;
87  uint32 lastGarbageCollectionTime;
88 
89  void garbageCollectIfNeeded();
90 
91  JUCE_DECLARE_NON_COPYABLE (StringPool)
92 };
93 
94 } // namespace juce
95 
96 /** @}*/
#define JUCE_API
This macro is added to all JUCE public class declarations.
A simple class for holding temporary references to a string literal or String.
The JUCE String class!
Definition: juce_String.h:42
A StringPool holds a set of shared strings, which reduces storage overheads and improves comparison s...
Holds a resizable array of primitive or copy-by-value objects.
Definition: juce_Array.h:59
A re-entrant mutex.
Wraps a pointer to a null-terminated UTF-8 character string, and provides various methods to operate ...