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.

92 lines
3.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_STRINGPOOL_JUCEHEADER__
  19. #define __JUCE_STRINGPOOL_JUCEHEADER__
  20. #include "juce_String.h"
  21. #include "../containers/juce_Array.h"
  22. //==============================================================================
  23. /**
  24. A StringPool holds a set of shared strings, which reduces storage overheads and improves
  25. comparison speed when dealing with many duplicate strings.
  26. When you add a string to a pool using getPooledString, it'll return a character
  27. array containing the same string. This array is owned by the pool, and the same array
  28. is returned every time a matching string is asked for. This means that it's trivial to
  29. compare two pooled strings for equality, as you can simply compare their pointers. It
  30. also cuts down on storage if you're using many copies of the same string.
  31. */
  32. class JUCE_API StringPool
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates an empty pool. */
  37. StringPool() noexcept;
  38. /** Destructor */
  39. ~StringPool();
  40. //==============================================================================
  41. /** Returns a pointer to a copy of the string that is passed in.
  42. The pool will always return the same pointer when asked for a string that matches it.
  43. The pool will own all the pointers that it returns, deleting them when the pool itself
  44. is deleted.
  45. */
  46. const String::CharPointerType getPooledString (const String& original);
  47. /** Returns a pointer to a copy of the string that is passed in.
  48. The pool will always return the same pointer when asked for a string that matches it.
  49. The pool will own all the pointers that it returns, deleting them when the pool itself
  50. is deleted.
  51. */
  52. const String::CharPointerType getPooledString (const char* original);
  53. /** Returns a pointer to a copy of the string that is passed in.
  54. The pool will always return the same pointer when asked for a string that matches it.
  55. The pool will own all the pointers that it returns, deleting them when the pool itself
  56. is deleted.
  57. */
  58. const String::CharPointerType getPooledString (const wchar_t* original);
  59. //==============================================================================
  60. /** Returns the number of strings in the pool. */
  61. int size() const noexcept;
  62. /** Returns one of the strings in the pool, by index. */
  63. const String::CharPointerType operator[] (int index) const noexcept;
  64. private:
  65. Array <String> strings;
  66. };
  67. #endif // __JUCE_STRINGPOOL_JUCEHEADER__