The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the juce_core module of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software Ltd.
  5. Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. or without fee is hereby granted, provided that the above copyright notice and this
  7. permission notice appear in all copies.
  8. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  9. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  10. NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  11. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  12. IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. ------------------------------------------------------------------------------
  15. NOTE! This permissive ISC license applies ONLY to files within the juce_core module!
  16. All other JUCE modules are covered by a dual GPL/commercial license, so if you are
  17. using any other modules, be sure to check that you also comply with their license.
  18. For more details, visit www.juce.com
  19. ==============================================================================
  20. */
  21. #ifndef JUCE_STRINGPOOL_H_INCLUDED
  22. #define JUCE_STRINGPOOL_H_INCLUDED
  23. //==============================================================================
  24. /**
  25. A StringPool holds a set of shared strings, which reduces storage overheads and improves
  26. comparison speed when dealing with many duplicate strings.
  27. When you add a string to a pool using getPooledString, it'll return a character
  28. array containing the same string. This array is owned by the pool, and the same array
  29. is returned every time a matching string is asked for. This means that it's trivial to
  30. compare two pooled strings for equality, as you can simply compare their pointers. It
  31. also cuts down on storage if you're using many copies of the same string.
  32. */
  33. class JUCE_API StringPool
  34. {
  35. public:
  36. //==============================================================================
  37. /** Creates an empty pool. */
  38. StringPool() noexcept;
  39. /** Destructor */
  40. ~StringPool();
  41. //==============================================================================
  42. /** Returns a pointer to a copy of the string that is passed in.
  43. The pool will always return the same pointer when asked for a string that matches it.
  44. The pool will own all the pointers that it returns, deleting them when the pool itself
  45. is deleted.
  46. */
  47. String::CharPointerType getPooledString (const String& original);
  48. /** Returns a pointer to a copy of the string that is passed in.
  49. The pool will always return the same pointer when asked for a string that matches it.
  50. The pool will own all the pointers that it returns, deleting them when the pool itself
  51. is deleted.
  52. */
  53. String::CharPointerType getPooledString (const char* original);
  54. /** Returns a pointer to a copy of the string that is passed in.
  55. The pool will always return the same pointer when asked for a string that matches it.
  56. The pool will own all the pointers that it returns, deleting them when the pool itself
  57. is deleted.
  58. */
  59. String::CharPointerType getPooledString (const wchar_t* original);
  60. //==============================================================================
  61. /** Returns the number of strings in the pool. */
  62. int size() const noexcept;
  63. /** Returns one of the strings in the pool, by index. */
  64. String::CharPointerType operator[] (int index) const noexcept;
  65. private:
  66. Array <String> strings;
  67. CriticalSection lock;
  68. };
  69. #endif // JUCE_STRINGPOOL_H_INCLUDED