Migration to new PropertyMap ... done ape to mod.

This commit is contained in:
Michael Helmling
2012-01-21 14:52:24 +01:00
parent 18ae797df4
commit e4d955d6ef
18 changed files with 398 additions and 234 deletions

View File

@ -70,14 +70,14 @@ Mod::Properties *Mod::File::audioProperties() const
return &d->properties;
}
TagDict Mod::File::toDict() const
PropertyMap Mod::File::properties() const
{
return d->tag.toDict();
return d->tag.properties();
}
void Mod::File::fromDict(const TagDict &tagDict)
PropertyMap Mod::File::setProperties(const PropertyMap &properties)
{
d->tag.fromDict(tagDict);
return d->tag.setProperties(properties);
}
bool Mod::File::save()

View File

@ -62,16 +62,16 @@ namespace TagLib {
Mod::Tag *tag() const;
/*!
* Implements the unified tag dictionary interface -- export function.
* Forwards to Mod::Tag::toDict().
* Implements the unified property interface -- export function.
* Forwards to Mod::Tag::properties().
*/
TagDict toDict() const;
PropertyMap properties() const;
/*!
* Implements the unified tag dictionary interface -- import function.
* Forwards to Mod::Tag::fromDict().
* Implements the unified property interface -- import function.
* Forwards to Mod::Tag::setProperties().
*/
void fromDict(const TagDict &);
PropertyMap setProperties(const PropertyMap &);
/*!
* Returns the Mod::Properties for this file. If no audio properties
* were read then this will return a null pointer.

View File

@ -121,30 +121,46 @@ void Mod::Tag::setTrackerName(const String &trackerName)
d->trackerName = trackerName;
}
TagDict Mod::Tag::toDict() const
PropertyMap Mod::Tag::properties() const
{
TagDict dict;
dict["TITLE"] = d->title;
dict["COMMENT"] = d->comment;
if (!(d->trackerName == String::null))
dict["TRACKERNAME"] = d->trackerName;
return dict;
PropertyMap properties;
properties["TITLE"] = d->title;
properties["COMMENT"] = d->comment;
if(!(d->trackerName.isNull()))
properties["TRACKERNAME"] = d->trackerName;
return properties;
}
void Mod::Tag::fromDict(const TagDict &tagDict)
PropertyMap Mod::Tag::setProperties(const PropertyMap &origProps)
{
if (tagDict.contains("TITLE") && !tagDict["TITILE"].isEmpty())
d->title = tagDict["TITLE"][0];
else
PropertyMap properties(origProps);
properties.removeEmpty();
StringList oneValueSet;
if(properties.contains("TITLE")) {
d->title = properties["TITLE"].front();
oneValueSet.append("TITLE");
} else
d->title = String::null;
if (tagDict.contains("COMMENT") && !tagDict["COMMENT"].isEmpty())
d->comment = tagDict["COMMENT"][0];
else
if(properties.contains("COMMENT")) {
d->comment = properties["COMMENT"].front();
oneValueSet.append("COMMENT");
} else
d->comment = String::null;
if (tagDict.contains("TRACKERNAME") && !tagDict["TRACKERNAME"].isEmpty())
d->trackerName = tagDict["TRACKERNAME"][0];
else
if(properties.contains("TRACKERNAME")) {
d->trackerName = properties["TRACKERNAME"].front();
oneValueSet.append("TRACKERNAME");
} else
d->trackerName = String::null;
// for each tag that has been set above, remove the first entry in the corresponding
// value list. The others will be returned as unsupported by this format.
for(StringList::Iterator it = oneValueSet.begin(); it != oneValueSet.end(); ++it) {
if(properties[*it].size() == 1)
properties.erase(*it);
else
properties[*it].erase( properties[*it].begin() );
}
return properties;
}

View File

@ -160,19 +160,20 @@ namespace TagLib {
void setTrackerName(const String &trackerName);
/*!
* Implements the unified tag dictionary interface -- export function.
* Since the module tag is very limited, the exported dict is as well.
* Implements the unified property interface -- export function.
* Since the module tag is very limited, the exported map is as well.
*/
TagDict toDict() const;
PropertyMap properties() const;
/*!
* Implements the unified tag dictionary interface -- import function.
* Implements the unified property interface -- import function.
* Because of the limitations of the module file tag, any tags besides
* COMMENT, TITLE and, if it is an XM file, TRACKERNAME, will be
* ignored. Additionally, if the dict contains tags with multiple values,
* all but the first will be ignored.
* returened. Additionally, if the map contains tags with multiple values,
* all but the first will be contained in the returned map of unsupported
* properties.
*/
void fromDict(const TagDict &);
PropertyMap setProperties(const PropertyMap &);
private:
Tag(const Tag &);