musikr: remove ref map entry returns

Not needed
This commit is contained in:
Alexander Capehart 2025-02-17 18:40:34 -07:00
parent 12caac1f80
commit fc5c49081f
No known key found for this signature in database
GPG key ID: 37DBE3621FE9AD47
7 changed files with 125 additions and 111 deletions

View file

@ -7,12 +7,12 @@ namespace taglib_shim {
ItemMapEntry::ItemMapEntry(TagLib::String key, TagLib::MP4::Item value)
: key_(std::move(key)), value_(std::move(value)) {}
const TagLib::String& ItemMapEntry::key() const {
return key_;
std::unique_ptr<TagLib::String> ItemMapEntry::key() const {
return std::make_unique<TagLib::String>(key_);
}
const TagLib::MP4::Item& ItemMapEntry::value() const {
return value_;
std::unique_ptr<TagLib::MP4::Item> ItemMapEntry::value() const {
return std::make_unique<TagLib::MP4::Item>(value_);
}
std::unique_ptr<std::vector<ItemMapEntry>> ItemMap_to_entries(const TagLib::MP4::ItemMap& map) {

View file

@ -10,8 +10,8 @@ namespace taglib_shim {
class ItemMapEntry {
public:
ItemMapEntry(TagLib::String key, TagLib::MP4::Item value);
const TagLib::String& key() const;
const TagLib::MP4::Item& value() const;
std::unique_ptr<TagLib::String> key() const;
std::unique_ptr<TagLib::MP4::Item> value() const;
private:
TagLib::String key_;

View file

@ -4,14 +4,14 @@ namespace taglib_shim
{
FieldListEntry::FieldListEntry(TagLib::String key, TagLib::StringList value) : key_(key), value_(value) {}
const TagLib::String &FieldListEntry::key() const
std::unique_ptr<TagLib::String> FieldListEntry::key() const
{
return key_;
return std::make_unique<TagLib::String>(key_);
}
const TagLib::StringList &FieldListEntry::value() const
std::unique_ptr<TagLib::StringList> FieldListEntry::value() const
{
return value_;
return std::make_unique<TagLib::StringList>(value_);
}
std::unique_ptr<std::vector<FieldListEntry>> FieldListMap_to_entries(const TagLib::SimplePropertyMap &map)

View file

@ -8,8 +8,8 @@ namespace taglib_shim
struct FieldListEntry
{
FieldListEntry(TagLib::String key, TagLib::StringList value);
const TagLib::String &key() const;
const TagLib::StringList &value() const;
std::unique_ptr<TagLib::String> key() const;
std::unique_ptr<TagLib::StringList> value() const;
private:
TagLib::String key_;

View file

@ -40,6 +40,8 @@ mod bridge_impl {
include!("shim/mp4_shim.hpp");
include!("taglib/mpegfile.h");
// CORE
#[namespace = "TagLib"]
#[cxx_name = "IOStream"]
type CPPIOStream<'io_stream>;
@ -77,6 +79,8 @@ mod bridge_impl {
fn sampleRate(self: &CppAudioProperties) -> i32;
fn channels(self: &CppAudioProperties) -> i32;
// XIPH
#[namespace = "TagLib::Ogg::Vorbis"]
#[cxx_name = "File"]
type CPPVorbisFile;
@ -115,38 +119,20 @@ mod bridge_impl {
type CPPFLACPicturePointer;
fn get(self: &CPPFLACPicturePointer) -> *const CPPFLACPicture;
#[namespace = "TagLib::MPEG"]
#[cxx_name = "File"]
type CPPMPEGFile;
#[cxx_name = "ID3v1Tag"]
fn MPEGID3v1Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v1Tag;
#[cxx_name = "ID3v2Tag"]
fn MPEGID3v2Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v2Tag;
#[namespace = "TagLib::MP4"]
#[cxx_name = "File"]
type CPPMP4File;
#[cxx_name = "tag"]
fn MP4Tag(self: &CPPMP4File) -> *mut CPPMP4Tag;
#[namespace = "TagLib::RIFF::WAV"]
#[cxx_name = "File"]
type CPPWAVFile;
#[cxx_name = "ID3v2Tag"]
fn WAVID3v2Tag(self: &CPPWAVFile) -> *mut CPPID3v2Tag;
#[namespace = "TagLib::FLAC"]
#[cxx_name = "Picture"]
type CPPFLACPicture;
#[namespace = "taglib_shim"]
fn Picture_data(picture: &CPPFLACPicture) -> UniquePtr<CPPByteVector>;
// XIPHComment
#[namespace = "TagLib::Ogg"]
#[cxx_name = "XiphComment"]
type CPPXiphComment;
// Explicit lifecycle definition to state while the Pin is temporary, the CPPFieldListMap
// ref returned actually has the same lifetime as the CPPXiphComment.
fn fieldListMap<'slf, 'file_ref>(self: &'slf CPPXiphComment) -> &'file_ref CPPFieldListMap;
fn fieldListMap(self: &CPPXiphComment) -> &CPPFieldListMap;
#[namespace = "TagLib"]
#[cxx_name = "SimplePropertyMap"]
@ -159,8 +145,102 @@ mod bridge_impl {
#[namespace = "taglib_shim"]
#[cxx_name = "FieldListEntry"]
type CPPFieldListEntry;
fn key<'slf, 'file_ref>(self: &'slf CPPFieldListEntry) -> &'file_ref CPPString;
fn value<'slf, 'file_ref>(self: &'slf CPPFieldListEntry) -> &'file_ref CPPStringList;
fn key(self: &CPPFieldListEntry) -> UniquePtr<CPPString>;
fn value(self: &CPPFieldListEntry) -> UniquePtr<CPPStringList>;
// MPEG
#[namespace = "TagLib::MPEG"]
#[cxx_name = "File"]
type CPPMPEGFile;
#[cxx_name = "ID3v1Tag"]
fn MPEGID3v1Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v1Tag;
#[cxx_name = "ID3v2Tag"]
fn MPEGID3v2Tag(self: Pin<&mut CPPMPEGFile>, create: bool) -> *mut CPPID3v2Tag;
// MP4
#[namespace = "TagLib::MP4"]
#[cxx_name = "File"]
type CPPMP4File;
#[cxx_name = "tag"]
fn MP4Tag(self: &CPPMP4File) -> *mut CPPMP4Tag;
#[namespace = "TagLib::MP4"]
#[cxx_name = "Tag"]
type CPPMP4Tag;
#[namespace = "TagLib::MP4"]
#[cxx_name = "ItemMap"]
type CPPItemMap;
fn itemMap(self: &CPPMP4Tag) -> &CPPItemMap;
fn ItemMap_to_entries(map: &CPPItemMap) -> UniquePtr<CxxVector<CPPItemMapEntry>>;
#[namespace = "taglib_shim"]
#[cxx_name = "ItemMapEntry"]
type CPPItemMapEntry;
fn key(self: &CPPItemMapEntry) -> UniquePtr<CPPString>;
fn value(self: &CPPItemMapEntry) -> UniquePtr<CPPMP4Item>;
#[namespace = "TagLib::MP4"]
#[cxx_name = "Item"]
type CPPMP4Item;
fn isValid(self: &CPPMP4Item) -> bool;
fn toBool(self: &CPPMP4Item) -> bool;
fn toInt(self: &CPPMP4Item) -> i32;
fn toByte(self: &CPPMP4Item) -> u8;
fn toUInt(self: &CPPMP4Item) -> u32;
fn Item_type(item: &CPPMP4Item) -> u32;
#[namespace = "taglib_shim"]
fn Item_toIntPair(item: &CPPMP4Item) -> UniquePtr<CPPIntPair>;
#[namespace = "taglib_shim"]
fn Item_toStringList(item: &CPPMP4Item) -> UniquePtr<CPPStringList>;
#[namespace = "taglib_shim"]
fn Item_toByteVectorList(item: &CPPMP4Item) -> UniquePtr<CPPByteVectorList>;
#[namespace = "taglib_shim"]
fn Item_toCoverArtList(item: &CPPMP4Item) -> UniquePtr<CPPCoverArtList>;
#[namespace = "taglib_shim"]
fn Item_toLongLong(item: &CPPMP4Item) -> i64;
#[namespace = "taglib_shim"]
#[cxx_name = "IntPair"]
type CPPIntPair;
fn first(self: &CPPIntPair) -> i32;
fn second(self: &CPPIntPair) -> i32;
#[namespace = "taglib_shim"]
#[cxx_name = "CoverArtList"]
type CPPCoverArtList;
fn to_vector(self: &CPPCoverArtList) -> UniquePtr<CxxVector<CPPCoverArt>>;
#[namespace = "taglib_shim"]
#[cxx_name = "CoverArt"]
type CPPCoverArt;
fn format(self: &CPPCoverArt) -> u32;
fn data(self: &CPPCoverArt) -> UniquePtr<CPPByteVector>;
#[namespace = "TagLib::RIFF::WAV"]
#[cxx_name = "File"]
type CPPWAVFile;
#[cxx_name = "ID3v2Tag"]
fn WAVID3v2Tag(self: &CPPWAVFile) -> *mut CPPID3v2Tag;
// ID3v1
#[namespace = "TagLib::ID3v1"]
#[cxx_name = "Tag"]
type CPPID3v1Tag;
fn ID3v1Tag_title(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_artist(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_album(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_comment(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_genreIndex(tag: &CPPID3v1Tag) -> u32;
fn ID3v1Tag_year(tag: &CPPID3v1Tag) -> u32;
fn ID3v1Tag_track(tag: &CPPID3v1Tag) -> u32;
// ID3v2
#[namespace = "TagLib::ID3v2"]
#[cxx_name = "Tag"]
@ -247,72 +327,6 @@ mod bridge_impl {
type CPPByteVector;
fn size(self: &CPPByteVector) -> u32;
fn data(self: &CPPByteVector) -> *const c_char;
#[namespace = "TagLib::ID3v1"]
#[cxx_name = "Tag"]
type CPPID3v1Tag;
fn ID3v1Tag_title(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_artist(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_album(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_comment(tag: &CPPID3v1Tag) -> UniquePtr<CPPString>;
fn ID3v1Tag_genreIndex(tag: &CPPID3v1Tag) -> u32;
fn ID3v1Tag_year(tag: &CPPID3v1Tag) -> u32;
fn ID3v1Tag_track(tag: &CPPID3v1Tag) -> u32;
#[namespace = "TagLib::MP4"]
#[cxx_name = "Tag"]
type CPPMP4Tag;
#[namespace = "TagLib::MP4"]
#[cxx_name = "ItemMap"]
type CPPItemMap;
fn itemMap<'slf, 'file_ref>(self: &'slf CPPMP4Tag) -> &'file_ref CPPItemMap;
fn ItemMap_to_entries(map: &CPPItemMap) -> UniquePtr<CxxVector<CPPItemMapEntry>>;
#[namespace = "taglib_shim"]
#[cxx_name = "ItemMapEntry"]
type CPPItemMapEntry;
fn key<'slf, 'file_ref>(self: &'slf CPPItemMapEntry) -> &'file_ref CPPString;
fn value<'slf, 'file_ref>(self: &'slf CPPItemMapEntry) -> &'file_ref CPPMP4Item;
#[namespace = "TagLib::MP4"]
#[cxx_name = "Item"]
type CPPMP4Item;
fn isValid(self: &CPPMP4Item) -> bool;
fn toBool(self: &CPPMP4Item) -> bool;
fn toInt(self: &CPPMP4Item) -> i32;
fn toByte(self: &CPPMP4Item) -> u8;
fn toUInt(self: &CPPMP4Item) -> u32;
fn Item_type(item: &CPPMP4Item) -> u32;
#[namespace = "taglib_shim"]
fn Item_toIntPair(item: &CPPMP4Item) -> UniquePtr<CPPIntPair>;
#[namespace = "taglib_shim"]
fn Item_toStringList(item: &CPPMP4Item) -> UniquePtr<CPPStringList>;
#[namespace = "taglib_shim"]
fn Item_toByteVectorList(item: &CPPMP4Item) -> UniquePtr<CPPByteVectorList>;
#[namespace = "taglib_shim"]
fn Item_toCoverArtList(item: &CPPMP4Item) -> UniquePtr<CPPCoverArtList>;
#[namespace = "taglib_shim"]
fn Item_toLongLong(item: &CPPMP4Item) -> i64;
#[namespace = "taglib_shim"]
#[cxx_name = "IntPair"]
type CPPIntPair;
fn first(self: &CPPIntPair) -> i32;
fn second(self: &CPPIntPair) -> i32;
#[namespace = "taglib_shim"]
#[cxx_name = "CoverArtList"]
type CPPCoverArtList;
fn to_vector(self: &CPPCoverArtList) -> UniquePtr<CxxVector<CPPCoverArt>>;
#[namespace = "taglib_shim"]
#[cxx_name = "CoverArt"]
type CPPCoverArt;
fn format(self: &CPPCoverArt) -> u32;
fn data(self: &CPPCoverArt) -> UniquePtr<CPPByteVector>;
}
}

View file

@ -35,7 +35,7 @@ impl<'file_ref> MP4Tag<'file_ref> {
Self { this }
}
pub fn item_map(&self) -> ItemMap<'file_ref> {
pub fn item_map(&'file_ref self) -> ItemMap<'file_ref> {
let map: &'file_ref CPPItemMap = self.this.as_ref().itemMap();
let map_this = unsafe { RefThis::new(map) };
ItemMap::new(map_this)
@ -63,11 +63,11 @@ impl<'file_ref> ItemMap<'file_ref> {
// - The values returned are copied and thus not dependent on the address
// of self.
let key_ref = property.key();
let key_this = unsafe { RefThis::new(key_ref) };
let key_this = unsafe { OwnedThis::new(key_ref) }.unwrap();
let key = tk::String::new(key_this).to_string();
let value_ref = property.value();
let value_this = unsafe { RefThis::new(value_ref) };
let value_this = unsafe { OwnedThis::new(value_ref) }.unwrap();
let value = MP4Item::new(value_this);
(key, value)
@ -79,11 +79,11 @@ impl<'file_ref> ItemMap<'file_ref> {
}
pub struct MP4Item<'file_ref> {
this: RefThis<'file_ref, CPPMP4Item>,
this: OwnedThis<'file_ref, CPPMP4Item>,
}
impl<'file_ref> MP4Item<'file_ref> {
pub fn new(this: RefThis<'file_ref, CPPMP4Item>) -> Self {
pub fn new(this: OwnedThis<'file_ref, CPPMP4Item>) -> Self {
Self { this }
}

View file

@ -15,7 +15,7 @@ impl<'file_ref> XiphComment<'file_ref> {
Self { this }
}
pub fn field_list_map(&self) -> FieldListMap<'file_ref> {
pub fn field_list_map(&'file_ref self) -> FieldListMap<'file_ref> {
let map: &'file_ref CPPFieldListMap = self.this.as_ref().fieldListMap();
let map_this = unsafe { RefThis::new(map) };
FieldListMap::new(map_this)
@ -39,7 +39,7 @@ impl<'file_ref> FieldListMap<'file_ref> {
}
impl<'file_ref> FieldListMap<'file_ref> {
pub fn to_hashmap(&self) -> HashMap<String, tk::RefStringList<'file_ref>> {
pub fn to_hashmap(&self) -> HashMap<String, tk::OwnedStringList<'file_ref>> {
let cxx_vec = FieldListMap_to_entries(self.this.as_ref());
cxx_vec
.iter()
@ -51,10 +51,10 @@ impl<'file_ref> FieldListMap<'file_ref> {
// - The values returned are copied and thus not dependent on the address
// of self.
let key_ref = property.key();
let key_this = unsafe { RefThis::new(key_ref) };
let key_this = unsafe { OwnedThis::new(key_ref) }.unwrap();
let key = tk::String::new(key_this).to_string();
let value_ref = property.value();
let value_this = unsafe { RefThis::new(value_ref) };
let value_this = unsafe { OwnedThis::new(value_ref) }.unwrap();
let value = tk::StringList::new(value_this);
(key, value)
})