tag/Names: convert to C++

This commit is contained in:
Max Kellermann 2023-03-06 14:25:19 +01:00
parent 148aca23be
commit a302d34f6d
21 changed files with 101 additions and 51 deletions

View File

@ -2,6 +2,7 @@
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#include "TagPrint.hxx" #include "TagPrint.hxx"
#include "tag/Names.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "tag/Settings.hxx" #include "tag/Settings.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"

View File

@ -2,6 +2,7 @@
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#include "TagSave.hxx" #include "TagSave.hxx"
#include "tag/Names.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"

View File

@ -13,6 +13,7 @@
#include "protocol/RangeArg.hxx" #include "protocol/RangeArg.hxx"
#include "client/Client.hxx" #include "client/Client.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
#include "tag/Names.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "util/Exception.hxx" #include "util/Exception.hxx"
#include "util/StringAPI.hxx" #include "util/StringAPI.hxx"

View File

@ -8,6 +8,7 @@
#include "client/Response.hxx" #include "client/Response.hxx"
#include "Partition.hxx" #include "Partition.hxx"
#include "song/LightSong.hxx" #include "song/LightSong.hxx"
#include "tag/Names.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "LightDirectory.hxx" #include "LightDirectory.hxx"
#include "PlaylistInfo.hxx" #include "PlaylistInfo.hxx"

View File

@ -7,6 +7,7 @@
#include "lib/fmt/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "io/BufferedOutputStream.hxx" #include "io/BufferedOutputStream.hxx"
#include "io/LineReader.hxx" #include "io/LineReader.hxx"
#include "tag/Names.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "tag/Settings.hxx" #include "tag/Settings.hxx"
#include "fs/Charset.hxx" #include "fs/Charset.hxx"

View File

@ -5,6 +5,7 @@
#define __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS
#include "FfmpegMetaData.hxx" #include "FfmpegMetaData.hxx"
#include "tag/Names.hxx"
#include "tag/Table.hxx" #include "tag/Table.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "tag/Id3MusicBrainz.hxx" #include "tag/Id3MusicBrainz.hxx"

View File

@ -3,6 +3,7 @@
#include "FlacEncoderPlugin.hxx" #include "FlacEncoderPlugin.hxx"
#include "../EncoderAPI.hxx" #include "../EncoderAPI.hxx"
#include "tag/Names.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "pcm/Buffer.hxx" #include "pcm/Buffer.hxx"
#include "lib/fmt/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"

View File

@ -3,6 +3,7 @@
#include "OpusEncoderPlugin.hxx" #include "OpusEncoderPlugin.hxx"
#include "OggEncoder.hxx" #include "OggEncoder.hxx"
#include "tag/Names.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "util/ByteOrder.hxx" #include "util/ByteOrder.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"

View File

@ -5,6 +5,7 @@
#include "OggEncoder.hxx" #include "OggEncoder.hxx"
#include "lib/fmt/RuntimeError.hxx" #include "lib/fmt/RuntimeError.hxx"
#include "lib/xiph/VorbisComment.hxx" #include "lib/xiph/VorbisComment.hxx"
#include "tag/Names.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"
#include "config/Domain.hxx" #include "config/Domain.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"

View File

@ -3,6 +3,7 @@
#include "ScanVorbisComment.hxx" #include "ScanVorbisComment.hxx"
#include "XiphTags.hxx" #include "XiphTags.hxx"
#include "tag/Names.hxx"
#include "tag/Table.hxx" #include "tag/Table.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "tag/VorbisComment.hxx" #include "tag/VorbisComment.hxx"

View File

@ -4,6 +4,7 @@
#include "TagSongFilter.hxx" #include "TagSongFilter.hxx"
#include "Escape.hxx" #include "Escape.hxx"
#include "LightSong.hxx" #include "LightSong.hxx"
#include "tag/Names.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "tag/Fallback.hxx" #include "tag/Fallback.hxx"

View File

@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#include "Type.h" #include "Names.hxx"
#include <cstdlib> #include <cstdlib>
#include <map> #include <map>

View File

@ -1,42 +0,0 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "Type.h"
const char *const tag_item_names[TAG_NUM_OF_ITEM_TYPES] = {
[TAG_ARTIST] = "Artist",
[TAG_ARTIST_SORT] = "ArtistSort",
[TAG_ALBUM] = "Album",
[TAG_ALBUM_SORT] = "AlbumSort",
[TAG_ALBUM_ARTIST] = "AlbumArtist",
[TAG_ALBUM_ARTIST_SORT] = "AlbumArtistSort",
[TAG_TITLE] = "Title",
[TAG_TITLE_SORT] = "TitleSort",
[TAG_TRACK] = "Track",
[TAG_NAME] = "Name",
[TAG_GENRE] = "Genre",
[TAG_MOOD] = "Mood",
[TAG_DATE] = "Date",
[TAG_ORIGINAL_DATE] = "OriginalDate",
[TAG_COMPOSER] = "Composer",
[TAG_COMPOSERSORT] = "ComposerSort",
[TAG_PERFORMER] = "Performer",
[TAG_CONDUCTOR] = "Conductor",
[TAG_WORK] = "Work",
[TAG_MOVEMENT] = "Movement",
[TAG_MOVEMENTNUMBER] = "MovementNumber",
[TAG_ENSEMBLE] = "Ensemble",
[TAG_LOCATION] = "Location",
[TAG_GROUPING] = "Grouping",
[TAG_COMMENT] = "Comment",
[TAG_DISC] = "Disc",
[TAG_LABEL] = "Label",
/* MusicBrainz tags from http://musicbrainz.org/doc/MusicBrainzTag */
[TAG_MUSICBRAINZ_ARTISTID] = "MUSICBRAINZ_ARTISTID",
[TAG_MUSICBRAINZ_ALBUMID] = "MUSICBRAINZ_ALBUMID",
[TAG_MUSICBRAINZ_ALBUMARTISTID] = "MUSICBRAINZ_ALBUMARTISTID",
[TAG_MUSICBRAINZ_TRACKID] = "MUSICBRAINZ_TRACKID",
[TAG_MUSICBRAINZ_RELEASETRACKID] = "MUSICBRAINZ_RELEASETRACKID",
[TAG_MUSICBRAINZ_WORKID] = "MUSICBRAINZ_WORKID",
};

69
src/tag/Names.cxx Normal file
View File

@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#include "Names.hxx"
#include "Table.hxx"
#include <cassert>
static constexpr struct tag_table tag_item_names_init[] = {
{"Artist", TAG_ARTIST},
{"ArtistSort", TAG_ARTIST_SORT},
{"Album", TAG_ALBUM},
{"AlbumSort", TAG_ALBUM_SORT},
{"AlbumArtist", TAG_ALBUM_ARTIST},
{"AlbumArtistSort", TAG_ALBUM_ARTIST_SORT},
{"Title", TAG_TITLE},
{"TitleSort", TAG_TITLE_SORT},
{"Track", TAG_TRACK},
{"Name", TAG_NAME},
{"Genre", TAG_GENRE},
{"Mood", TAG_MOOD},
{"Date", TAG_DATE},
{"OriginalDate", TAG_ORIGINAL_DATE},
{"Composer", TAG_COMPOSER},
{"ComposerSort", TAG_COMPOSERSORT},
{"Performer", TAG_PERFORMER},
{"Conductor", TAG_CONDUCTOR},
{"Work", TAG_WORK},
{"Movement", TAG_MOVEMENT},
{"MovementNumber", TAG_MOVEMENTNUMBER},
{"Ensemble", TAG_ENSEMBLE},
{"Location", TAG_LOCATION},
{"Grouping", TAG_GROUPING},
{"Comment", TAG_COMMENT},
{"Disc", TAG_DISC},
{"Label", TAG_LABEL},
/* MusicBrainz tags from http://musicbrainz.org/doc/MusicBrainzTag */
{"MUSICBRAINZ_ARTISTID", TAG_MUSICBRAINZ_ARTISTID},
{"MUSICBRAINZ_ALBUMID", TAG_MUSICBRAINZ_ALBUMID},
{"MUSICBRAINZ_ALBUMARTISTID", TAG_MUSICBRAINZ_ALBUMARTISTID},
{"MUSICBRAINZ_TRACKID", TAG_MUSICBRAINZ_TRACKID},
{"MUSICBRAINZ_RELEASETRACKID", TAG_MUSICBRAINZ_RELEASETRACKID},
{"MUSICBRAINZ_WORKID", TAG_MUSICBRAINZ_WORKID},
};
/**
* This function converts the #tag_item_names_init array to an
* associative array at compile time. This is a kludge because C++20
* doesn't support designated initializers for arrays, unlike C99.
*/
static constexpr auto
MakeTagNames() noexcept
{
std::array<const char *, TAG_NUM_OF_ITEM_TYPES> result{};
static_assert(std::size(tag_item_names_init) == result.size());
for (const auto &i : tag_item_names_init) {
/* no duplicates allowed */
assert(result[i.type] == nullptr);
result[i.type] = i.name;
}
return result;
}
constinit const std::array<const char *, TAG_NUM_OF_ITEM_TYPES> tag_item_names = MakeTagNames();

14
src/tag/Names.hxx Normal file
View File

@ -0,0 +1,14 @@
// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright The Music Player Daemon Project
#pragma once
#include "Type.h"
#include <array>
/**
* An array of strings, which map the #TagType to its machine
* readable name (specific to the MPD protocol).
*/
extern const std::array<const char *, TAG_NUM_OF_ITEM_TYPES> tag_item_names;

View File

@ -2,6 +2,7 @@
// Copyright The Music Player Daemon Project // Copyright The Music Player Daemon Project
#include "ParseName.hxx" #include "ParseName.hxx"
#include "Names.hxx"
#include "util/ASCII.hxx" #include "util/ASCII.hxx"
#include "util/StringCompare.hxx" #include "util/StringCompare.hxx"

View File

@ -57,10 +57,4 @@ enum TagType
TAG_NUM_OF_ITEM_TYPES TAG_NUM_OF_ITEM_TYPES
}; };
/**
* An array of strings, which map the #TagType to its machine
* readable name (specific to the MPD protocol).
*/
extern const char *const tag_item_names[];
#endif #endif

View File

@ -1,7 +1,7 @@
generate_parse_name = executable( generate_parse_name = executable(
'GenParseName', 'GenParseName',
'GenParseName.cxx', 'GenParseName.cxx',
'Names.c', 'Names.cxx',
native: true, native: true,
) )
@ -22,7 +22,7 @@ tag_sources = [
'Config.cxx', 'Config.cxx',
'ParseName.cxx', 'ParseName.cxx',
parse_name_cxx, parse_name_cxx,
'Names.c', 'Names.cxx',
'FixString.cxx', 'FixString.cxx',
'Pool.cxx', 'Pool.cxx',
'Table.cxx', 'Table.cxx',

View File

@ -4,6 +4,7 @@
#include "DumpDecoderClient.hxx" #include "DumpDecoderClient.hxx"
#include "decoder/DecoderAPI.hxx" #include "decoder/DecoderAPI.hxx"
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "tag/Names.hxx"
#include "util/StringBuffer.hxx" #include "util/StringBuffer.hxx"
#include "util/Compiler.h" #include "util/Compiler.h"

View File

@ -10,6 +10,7 @@
#include "input/InputStream.hxx" #include "input/InputStream.hxx"
#include "tag/Handler.hxx" #include "tag/Handler.hxx"
#include "tag/Generic.hxx" #include "tag/Generic.hxx"
#include "tag/Names.hxx"
#include "fs/Path.hxx" #include "fs/Path.hxx"
#include "fs/NarrowPath.hxx" #include "fs/NarrowPath.hxx"
#include "pcm/AudioFormat.hxx" #include "pcm/AudioFormat.hxx"

View File

@ -8,6 +8,7 @@
#include "SongLoader.hxx" #include "SongLoader.hxx"
#include "client/Client.hxx" #include "client/Client.hxx"
#include "tag/Builder.hxx" #include "tag/Builder.hxx"
#include "tag/Names.hxx"
#include "tag/Tag.hxx" #include "tag/Tag.hxx"
#include "util/Domain.hxx" #include "util/Domain.hxx"
#include "fs/AllocatedPath.hxx" #include "fs/AllocatedPath.hxx"