MetadataChain.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "metadata/ifc_metadata.h"
  3. template <class metadata_t>
  4. class MetadataChain : public metadata_t
  5. {
  6. public:
  7. MetadataChain()
  8. {
  9. parent_metadata=0;
  10. }
  11. ~MetadataChain()
  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 *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 *parent_metadata;
  31. private:
  32. ns_error_t WASABICALL Metadata_GetField(int field, unsigned int index, nx_string_t *value)
  33. {
  34. ns_error_t ret = metadata_t::Metadata_GetField(field, index, value);
  35. if (Unhandled(ret) && parent_metadata)
  36. return parent_metadata->GetField(field, index, value);
  37. else
  38. return ret;
  39. }
  40. ns_error_t WASABICALL Metadata_GetInteger(int field, unsigned int index, int64_t *value)
  41. {
  42. ns_error_t ret = metadata_t::Metadata_GetInteger(field, index, value);
  43. if (Unhandled(ret) && parent_metadata)
  44. return parent_metadata->GetInteger(field, index, value);
  45. else
  46. return ret;
  47. }
  48. ns_error_t WASABICALL Metadata_GetReal(int field, unsigned int index, double *value)
  49. {
  50. ns_error_t ret = metadata_t::Metadata_GetReal(field, index, value);
  51. if (Unhandled(ret) && parent_metadata)
  52. return parent_metadata->GetReal(field, index, value);
  53. else
  54. return ret;
  55. }
  56. ns_error_t WASABICALL Metadata_GetArtwork(int field, unsigned int index, artwork_t *artwork, data_flags_t flags)
  57. {
  58. ns_error_t ret = metadata_t::Metadata_GetArtwork(field, index, artwork, flags);
  59. if (Unhandled(ret) && parent_metadata)
  60. return parent_metadata->GetArtwork(field, index, artwork, flags);
  61. else
  62. return ret;
  63. }
  64. ns_error_t WASABICALL Metadata_GetBinary(int field, unsigned int index, nx_data_t *data)
  65. {
  66. ns_error_t ret = metadata_t::Metadata_GetBinary(field, index, data);
  67. if (Unhandled(ret) && parent_metadata)
  68. return parent_metadata->GetBinary(field, index, data);
  69. else
  70. return ret;
  71. }
  72. ns_error_t WASABICALL Metadata_GetMetadata(int field, unsigned int index, ifc_metadata **metadata)
  73. {
  74. ns_error_t ret = metadata_t::Metadata_GetMetadata(field, index, metadata);
  75. if (Unhandled(ret) && parent_metadata)
  76. return parent_metadata->GetMetadata(field, index, metadata);
  77. else
  78. return ret;
  79. }
  80. // TODO: ns_error_t WASABICALL Metadata_Serialize(nx_data_t *data) { return NErr_NotImplemented; }
  81. };