BsHString.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. namespace bs
  5. {
  6. /** @addtogroup Localization
  7. * @{
  8. */
  9. /**
  10. * String handle. Provides a wrapper around an Unicode string, primarily for localization purposes.
  11. *
  12. * Actual value for this string is looked up in a global string table based on the provided identifier string and
  13. * currently active language. If such value doesn't exist then the identifier is used as is.
  14. *
  15. * Use {0}, {1}, etc. in the string value for values that might change dynamically.
  16. */
  17. class BS_CORE_EXPORT HString
  18. {
  19. public:
  20. /**
  21. * Creates a new localized string with the specified identifier. If the identifier doesn't previously exist in the
  22. * string table, identifier value will also be used for initializing the default language version of the string.
  23. *
  24. * @param[in] identifier String you can use for later referencing the localized string.
  25. * @param[in] stringTableId Unique identifier of the string table to retrieve the string from.
  26. */
  27. explicit HString(const WString& identifier, UINT32 stringTableId = 0);
  28. /**
  29. * Creates a new localized string with the specified identifier and sets the default language version of the
  30. * string. If a string with that identifier already exists default language string will be updated.
  31. *
  32. * @param[in] identifier String you can use for later referencing the localized string.
  33. * @param[in] defaultString Default string to assign to the specified identifier. Language to which it will be
  34. * assigned depends on the StringTable::DEFAULT_LANGUAGE value.
  35. * @param[in] stringTableId Unique identifier of the string table to retrieve the string from.
  36. */
  37. explicit HString(const WString& identifier, const WString& defaultString, UINT32 stringTableId = 0);
  38. /**
  39. * Creates a new empty localized string.
  40. *
  41. * @param[in] stringTableId Unique identifier of the string table to retrieve the string from.
  42. */
  43. HString(UINT32 stringTableId = 0);
  44. HString(const HString& copy);
  45. ~HString();
  46. HString& operator=(const HString& rhs);
  47. operator const WString& () const;
  48. const WString& getValue() const;
  49. /**
  50. * Sets a value of a string parameter. Parameters are specified as bracketed values within the string itself
  51. * (for example {0}, {1}) etc. Use ^ as an escape character.
  52. *
  53. * @note This is useful for strings that have dynamically changing values, like numbers, embedded in them.
  54. */
  55. void setParameter(UINT32 idx, const WString& value);
  56. /** Returns an empty string. */
  57. static const HString& dummy();
  58. private:
  59. SPtr<LocalizedStringData> mStringData;
  60. WString* mParameters;
  61. mutable bool mIsDirty;
  62. mutable WString mCachedString;
  63. mutable WString* mStringPtr;
  64. };
  65. /** @} */
  66. }