MetadataEditorChain.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #pragma once
  2. #include "metadata/ifc_metadata_editor.h"
  3. template <class metadata_t>
  4. class MetadataEditorChain : public metadata_t
  5. {
  6. public:
  7. MetadataEditorChain()
  8. {
  9. parent_metadata=0;
  10. }
  11. ~MetadataEditorChain()
  12. {
  13. if (parent_metadata)
  14. parent_metadata->Release();
  15. }
  16. static bool Unhandled(ns_error_t ret)
  17. {
  18. return (ret == NErr_NotImplemented || ret == NErr_Empty || ret == NErr_Unknown);
  19. }
  20. ns_error_t SetParentMetadata(ifc_metadata_editor *new_parent_metadata)
  21. {
  22. if (parent_metadata)
  23. parent_metadata->Release();
  24. parent_metadata=new_parent_metadata;
  25. if (parent_metadata)
  26. parent_metadata->Retain();
  27. return NErr_Success;
  28. }
  29. protected:
  30. ifc_metadata_editor *parent_metadata;
  31. private:
  32. int WASABICALL MetadataEditor_Save()
  33. {
  34. if (parent_metadata)
  35. return parent_metadata->Save();
  36. else
  37. return NErr_NotImplemented;
  38. }
  39. int WASABICALL MetadataEditor_SetField(int field, unsigned int index, nx_string_t value)
  40. {
  41. bool known=false;
  42. if (parent_metadata && parent_metadata->SetField(field, index, value) == NErr_Success)
  43. known=true;
  44. if (metadata_t::MetadataEditor_SetField(field, index, value) == NErr_Success)
  45. known=true;
  46. if (known)
  47. return NErr_Success;
  48. else
  49. return NErr_Unknown;
  50. }
  51. int WASABICALL MetadataEditor_SetInteger(int field, unsigned int index, int64_t value)
  52. {
  53. bool known=false;
  54. if (parent_metadata && parent_metadata->SetInteger(field, index, value) == NErr_Success)
  55. known=true;
  56. if (metadata_t::MetadataEditor_SetInteger(field, index, value) == NErr_Success)
  57. known=true;
  58. if (known)
  59. return NErr_Success;
  60. else
  61. return NErr_Unknown;
  62. }
  63. int WASABICALL MetadataEditor_SetReal(int field, unsigned int index, double value)
  64. {
  65. bool known=false;
  66. if (parent_metadata && parent_metadata->SetReal(field, index, value) == NErr_Success)
  67. known=true;
  68. if (metadata_t::MetadataEditor_SetReal(field, index, value) == NErr_Success)
  69. known=true;
  70. if (known)
  71. return NErr_Success;
  72. else
  73. return NErr_Unknown;
  74. }
  75. int WASABICALL MetadataEditor_SetArtwork(int field, unsigned int index, artwork_t *data, data_flags_t flags)
  76. {
  77. bool known=false;
  78. if (parent_metadata && parent_metadata->SetArtwork(field, index, data, flags) == NErr_Success)
  79. known=true;
  80. if (metadata_t::MetadataEditor_SetArtwork(field, index, data, flags) == NErr_Success)
  81. known=true;
  82. if (known)
  83. return NErr_Success;
  84. else
  85. return NErr_Unknown;
  86. }
  87. };