tag.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma once
  2. #include "foundation/types.h"
  3. #include "nu/PtrDeque.h"
  4. #include "item.h"
  5. #include "flags.h"
  6. #include "header.h"
  7. namespace APEv2
  8. {
  9. class Tag
  10. {
  11. public:
  12. Tag();
  13. ~Tag();
  14. /* Parsing */
  15. int Parse(const APEv2::Header *header, const void *data, size_t len);
  16. /* Retrieving Data */
  17. int GetItem(const char *key, unsigned int index, Item **item, int compare=ITEM_KEY_COMPARE_CASE_INSENSITIVE) const;
  18. int GetItemAtIndex(unsigned int index, Item **) const;
  19. int GetData(const char *tag, unsigned int index, const void **data, size_t *data_len, int compare=ITEM_KEY_COMPARE_CASE_INSENSITIVE) const;
  20. int EnumerateItems(const Item *start, Item **item) const;
  21. int FindItemByKey(const char *key, Item **item, int compare=ITEM_KEY_COMPARE_CASE_INSENSITIVE) const;
  22. bool IsReadOnly() const;
  23. int GetItemCount(size_t *count) const;
  24. int GetFlags(uint32_t *flags) const;
  25. /* Setting Data */
  26. int AddItem(APEv2::Item *new_item);
  27. int SetFlags(uint32_t flags, uint32_t mask);
  28. /* Removing Data */
  29. void Clear();
  30. void Remove(const char *key, unsigned int starting_index, int compare=ITEM_KEY_COMPARE_CASE_INSENSITIVE); // removes all items matching a key, but skips the first 'starting_index' items
  31. void RemoveItem(Item *item);
  32. /* Serializing */
  33. size_t EncodeSize() const;
  34. int Encode(void *data, size_t len) const;
  35. private: /* methods */
  36. int ParseData(const void *data, size_t len); /* helper function, call with data pointing to beginning of items block (skip header), and length without footer. */
  37. private: /* data */
  38. typedef nu::PtrDeque<Item> ItemList;
  39. ItemList items;
  40. uint32_t flags;
  41. };
  42. }