MetaString.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * MetaString.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class CreatureID;
  13. class CStackBasicDescriptor;
  14. using TQuantity = si32;
  15. class DLL_LINKAGE MetaString
  16. {
  17. private:
  18. enum EMessage {TEXACT_STRING, TLOCAL_STRING, TNUMBER, TREPLACE_ESTRING, TREPLACE_LSTRING, TREPLACE_NUMBER, TREPLACE_PLUSNUMBER};
  19. public:
  20. enum {GENERAL_TXT=1, OBJ_NAMES, RES_NAMES, ART_NAMES, ARRAY_TXT, CRE_PL_NAMES, CREGENS, MINE_NAMES,
  21. MINE_EVNTS, ADVOB_TXT, ART_EVNTS, SPELL_NAME, SEC_SKILL_NAME, CRE_SING_NAMES, CREGENS4, COLOR, ART_DESCR, JK_TXT};
  22. std::vector<ui8> message; //vector of EMessage
  23. std::vector<std::pair<ui8,ui32> > localStrings;
  24. std::vector<std::string> exactStrings;
  25. std::vector<int64_t> numbers;
  26. template <typename Handler> void serialize(Handler & h, const int version)
  27. {
  28. h & exactStrings;
  29. h & localStrings;
  30. h & message;
  31. h & numbers;
  32. }
  33. void addTxt(ui8 type, ui32 serial)
  34. {
  35. message.push_back(TLOCAL_STRING);
  36. localStrings.emplace_back(type, serial);
  37. }
  38. void addRawString(std::string value)
  39. {
  40. message.push_back(TEXACT_STRING);
  41. exactStrings.push_back(value);
  42. }
  43. void appendNumber(int64_t value)
  44. {
  45. message.push_back(TNUMBER);
  46. numbers.push_back(value);
  47. }
  48. void addReplacement(ui8 type, ui32 serial)
  49. {
  50. message.push_back(TREPLACE_LSTRING);
  51. localStrings.emplace_back(type, serial);
  52. }
  53. void addReplacement(const std::string &txt)
  54. {
  55. message.push_back(TREPLACE_ESTRING);
  56. exactStrings.push_back(txt);
  57. }
  58. void addReplacement(int64_t txt)
  59. {
  60. message.push_back(TREPLACE_NUMBER);
  61. numbers.push_back(txt);
  62. }
  63. void addReplacement2(int64_t txt)
  64. {
  65. message.push_back(TREPLACE_PLUSNUMBER);
  66. numbers.push_back(txt);
  67. }
  68. void addCreReplacement(const CreatureID & id, TQuantity count); //adds sing or plural name;
  69. void addReplacement(const CStackBasicDescriptor &stack); //adds sing or plural name;
  70. std::string buildList () const;
  71. void clear()
  72. {
  73. exactStrings.clear();
  74. localStrings.clear();
  75. message.clear();
  76. numbers.clear();
  77. }
  78. void toString(std::string &dst) const;
  79. std::string toString() const;
  80. void getLocalString(const std::pair<ui8, ui32> & txt, std::string & dst) const;
  81. };
  82. VCMI_LIB_NAMESPACE_END