BsHString.h 2.7 KB

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