Simplifiying the cluster types handling

This commit is contained in:
emeric
2018-05-06 17:14:15 +02:00
parent a4969c134b
commit 57e745b460
9 changed files with 38 additions and 48 deletions
+4 -4
View File
@@ -30,8 +30,8 @@
namespace MetaData
{
AvFormat::AvFormat(const std::map<std::string, std::string>& clusterMap)
: _clusterMap(clusterMap)
AvFormat::AvFormat(const ClusterTypes& clusterTypes)
: Parser(clusterTypes)
{
}
@@ -155,13 +155,13 @@ AvFormat::parse(const boost::filesystem::path& p)
{
items.insert( std::make_pair(MetaData::Type::AcoustID, stringTrim(value)) );
}
else if (_clusterMap.find(tag) != _clusterMap.end())
else if (_clusterTypes.find(tag) != _clusterTypes.end())
{
std::vector<std::string> clusterNames = splitString(value, ";,\\");
if (!clusterNames.empty())
{
clusters[_clusterMap[tag]] = std::set<std::string>(clusterNames.begin(), clusterNames.end());
clusters[tag] = std::set<std::string>(clusterNames.begin(), clusterNames.end());
}
}
+1 -10
View File
@@ -32,18 +32,9 @@ class AvFormat : public Parser
{
public:
AvFormat(const std::map<std::string, std::string>& clusterMap
= {
{"GENRE", "Genre" },
{"ALBUMGROUPING", "Group" }
});
AvFormat(const ClusterTypes& clusterTypes = defaultClusterTypes);
boost::optional<Items> parse(const boost::filesystem::path& p);
private:
std::map<std::string,std::string> _clusterMap;
};
} // namespace MetaData
+14 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013 Emeric Poupon
* Copyright (C) 2018 Emeric Poupon
*
* This file is part of LMS.
*
@@ -17,8 +17,7 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef METADATA_HPP
#define METADATA_HPP
#pragma once
#include <map>
#include <set>
@@ -63,17 +62,26 @@ namespace MetaData
// Type and associated data
// See enum Type's comments
using Items = std::map<Type, boost::any>;
using Clusters = std::map<std::string, std::set<std::string>>;
using Clusters = std::map<std::string /* type */, std::set<std::string> /* names */>;
using ClusterTypes = std::set<std::string>;
class Parser
{
public:
static const ClusterTypes defaultClusterTypes;
// Provide a map for tag name -> Cluster name
Parser(const ClusterTypes& clusterTypes) : _clusterTypes(clusterTypes) {}
virtual boost::optional<Items> parse(const boost::filesystem::path& p) = 0;
void updateClusterTypes(const ClusterTypes& clusterTypes) { _clusterTypes = clusterTypes; }
const ClusterTypes& getClusterTypes() const { return _clusterTypes; }
bool isClusterTypeSupported(const std::string& clusterType) const { return _clusterTypes.find(clusterType) != _clusterTypes.end(); }
protected:
ClusterTypes _clusterTypes;
};
} // namespace MetaData
#endif
+4 -4
View File
@@ -32,8 +32,8 @@
namespace MetaData
{
TagLibParser::TagLibParser(const std::map<std::string, std::string>& clusterMap)
: _clusterMap(clusterMap)
TagLibParser::TagLibParser(const ClusterTypes& clusterTypes)
: Parser(clusterTypes)
{
}
@@ -188,14 +188,14 @@ TagLibParser::parse(const boost::filesystem::path& p)
items.insert( std::make_pair(MetaData::Type::HasCover, true));
}
// Check if a hit a cluster tag
else if (_clusterMap.find(tag) != _clusterMap.end())
else if (_clusterTypes.find(tag) != _clusterTypes.end())
{
std::set<std::string> clusterNames;
for (const auto& value : values)
clusterNames.insert(value.to8Bit(true));
if (!clusterNames.empty())
clusters[_clusterMap[tag]] = clusterNames;
clusters[tag] = clusterNames;
}
}
+1 -10
View File
@@ -32,18 +32,9 @@ class TagLibParser : public Parser
{
public:
// Provide a map for TagLib name -> Cluster name
TagLibParser(const std::map<std::string, std::string>& clusterMap
= {
{"GENRE", "Genre" },
{"ALBUMGROUPING", "Group" }
});
TagLibParser(const ClusterTypes& clusterTypes = defaultClusterTypes);
boost::optional<Items> parse(const boost::filesystem::path& p);
private:
std::map<std::string,std::string> _clusterMap;
};
} // namespace MetaData