-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathtagtarget.cpp
101 lines (92 loc) · 2.93 KB
/
tagtarget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include "./tagtarget.h"
#include "./matroska/matroskatagid.h"
#include <c++utilities/conversion/stringconversion.h>
#include <list>
using namespace std;
using namespace CppUtilities;
namespace TagParser {
/*!
* \brief Returns a string representation for the specified \a tagTargetLevel.
*/
std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
{
switch (tagTargetLevel) {
case TagTargetLevel::Shot:
return "shot";
case TagTargetLevel::Subtrack:
return "subtrack, part, movement, scene";
case TagTargetLevel::Track:
return "track, song, chapter";
case TagTargetLevel::Part:
return "part, session";
case TagTargetLevel::Album:
return "album, opera, concert, movie, episode";
case TagTargetLevel::Edition:
return "edition, issue, volume, opus, season, sequel";
case TagTargetLevel::Collection:
return "collection";
default:
return std::string_view();
}
}
/*!
* \class TagParser::TagTarget
* \brief The TagTarget class specifies the target of a tag.
*
* Tags might only target a specific track, chapter, ...
*
* Specifying a target is currently only fully supported by Matroska.
*
* Since Ogg saves tags at stream level, the stream can be specified
* by passing a TagTarget instance to OggContainer::createTag().
* However, only the first track in the tracks() array is considered
* and any other values are just ignored.
*
* In any other tag formats, the specified target is (currently)
* completely ignored.
*/
/*!
* \brief Returns the string representation of the current instance.
* \remarks Uses the specified \a tagTargetLevel if no levelName() is assigned.
*/
std::string TagTarget::toString(TagTargetLevel tagTargetLevel) const
{
auto levelString = std::string();
if (level()) {
levelString += "level ";
levelString += numberToString(level());
}
auto defaultLevelName = std::string_view();
if (!levelName().empty() || !(defaultLevelName = tagTargetLevelName(tagTargetLevel)).empty()) {
if (!levelString.empty()) {
levelString += ' ';
}
levelString += '\'';
if (!levelName().empty()) {
levelString += levelName();
} else {
levelString += defaultLevelName;
}
levelString += '\'';
}
list<string> parts;
if (levelString.empty()) {
parts.emplace_back("undefined target");
} else {
parts.emplace_back(std::move(levelString));
}
for (auto v : tracks()) {
parts.emplace_back("track " + numberToString(v));
}
for (auto v : chapters()) {
parts.emplace_back("chapter " + numberToString(v));
}
for (auto v : editions()) {
parts.emplace_back("edition " + numberToString(v));
}
for (auto v : attachments()) {
parts.emplace_back("attachment " + numberToString(v));
}
return joinStrings(parts, ", ");
}
} // namespace TagParser