StringStorage.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETCORESTRINGSTORAGE_H
  28. #define ROCKETCORESTRINGSTORAGE_H
  29. #include <stddef.h>
  30. namespace Rocket {
  31. namespace Core {
  32. /**
  33. Storage interface for StringBase
  34. @author Lloyd Weehuizen
  35. */
  36. class ROCKETCORE_API StringStorage
  37. {
  38. public:
  39. typedef void* StringID;
  40. static char* empty_string;
  41. /// Clears all shared strings from the string pools.
  42. static void ClearPools();
  43. /// Alloc/Realloc a string
  44. static char* ReallocString(char* string, size_t old_length, size_t new_length, size_t character_size);
  45. /// Release a previously allocated string
  46. static void ReleaseString(char* string, size_t length);
  47. /// Adds or increases the reference count on the given string
  48. /// @param string[in,out] String to add to the storage, returns new address of string
  49. /// @param string_length The length of the new string
  50. /// @param character_size Number of bytes of an individual parameter
  51. static StringID AddString(const char* &string, size_t string_length, size_t character_size);
  52. /// Adds a reference to the given string id
  53. /// @param id Id of the string to add a reference to
  54. static void AddReference(StringID id);
  55. /// Removes a reference from the given string id
  56. /// @param id Id of the string to remove a reference from
  57. static void RemoveReference(StringID id);
  58. private:
  59. /// Shutdown the storage pool
  60. static void OnLibraryShutdown();
  61. friend class LibraryMain;
  62. };
  63. }
  64. }
  65. #endif