tuningcollection.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * tuningCollection.h
  3. * ------------------
  4. * Purpose: Alternative sample tuning collection class.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include "tuning.h"
  12. #include <vector>
  13. #include <string>
  14. OPENMPT_NAMESPACE_BEGIN
  15. namespace Tuning {
  16. class CTuningCollection
  17. {
  18. public:
  19. static constexpr char s_FileExtension[4] = ".tc";
  20. // OpenMPT <= 1.26 had to following limits:
  21. // * 255 built-in tunings (only 2 were ever actually provided)
  22. // * 255 local tunings
  23. // * 255 tune-specific tunings
  24. // As 1.27 copies all used tunings into the module, the limit of 255 is no
  25. // longer sufficient. In the worst case scenario, the module contains 255
  26. // unused tunings and uses 255 local ones. In addition to that, allow the
  27. // user to additionally import both built-in tunings.
  28. // Older OpenMPT versions will silently skip loading tunings beyond index
  29. // 255.
  30. static constexpr size_t s_nMaxTuningCount = 255 + 255 + 2 ;
  31. public:
  32. // returns observer ptr if successful
  33. CTuning* AddTuning(std::unique_ptr<CTuning> pT);
  34. CTuning* AddTuning(std::istream &inStrm, mpt::Charset defaultCharset);
  35. bool Remove(const std::size_t i);
  36. bool Remove(const CTuning *pT);
  37. std::size_t GetNumTunings() const
  38. {
  39. return m_Tunings.size();
  40. }
  41. CTuning* GetTuning(std::size_t i)
  42. {
  43. if(i >= m_Tunings.size())
  44. {
  45. return nullptr;
  46. }
  47. return m_Tunings[i].get();
  48. }
  49. const CTuning* GetTuning(std::size_t i) const
  50. {
  51. if (i >= m_Tunings.size())
  52. {
  53. return nullptr;
  54. }
  55. return m_Tunings[i].get();
  56. }
  57. CTuning* GetTuning(const mpt::ustring &name);
  58. const CTuning* GetTuning(const mpt::ustring &name) const;
  59. Tuning::SerializationResult Serialize(std::ostream &oStrm, const mpt::ustring &name) const;
  60. Tuning::SerializationResult Deserialize(std::istream &iStrm, mpt::ustring &name, mpt::Charset defaultCharset);
  61. auto begin() { return m_Tunings.begin(); }
  62. auto begin() const { return m_Tunings.begin(); }
  63. auto cbegin() { return m_Tunings.cbegin(); }
  64. auto end() { return m_Tunings.end(); }
  65. auto end() const { return m_Tunings.end(); }
  66. auto cend() { return m_Tunings.cend(); }
  67. private:
  68. std::vector<std::unique_ptr<CTuning> > m_Tunings;
  69. private:
  70. Tuning::SerializationResult DeserializeOLD(std::istream &inStrm, mpt::ustring &uname, mpt::Charset defaultCharset);
  71. };
  72. #ifdef MODPLUG_TRACKER
  73. bool UnpackTuningCollection(const CTuningCollection &tc, const mpt::PathString &prefix);
  74. #endif
  75. } // namespace Tuning
  76. typedef Tuning::CTuningCollection CTuningCollection;
  77. OPENMPT_NAMESPACE_END