BsHString.h 2.6 KB

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