5 #include "../exceptions.h" 7 #include <c++utilities/io/binarywriter.h> 25 MatroskaTagField::MatroskaTagField()
32 MatroskaTagField::MatroskaTagField(
const string &
id,
const TagValue &value)
49 string context(
"parsing Matroska tag field");
50 simpleTagElement.
parse(diag);
51 bool tagDefaultFound =
false;
56 diag.emplace_back(
DiagLevel::Critical,
"Unable to parse children of \"SimpleTag\"-element.", context);
59 switch (child->id()) {
62 setId(child->readString());
63 context =
"parsing Matroska tag field " +
id();
66 "\"SimpleTag\"-element contains multiple \"TagName\"-elements. Surplus TagName elements will be ignored.", context);
71 if (
value().isEmpty()) {
72 unique_ptr<char[]> buffer = make_unique<char[]>(child->dataSize());
73 child->stream().seekg(child->dataOffset());
74 child->stream().read(buffer.get(), child->dataSize());
75 switch (child->id()) {
85 "\"SimpleTag\"-element contains multiple \"TagString\"/\"TagBinary\"-elements. Surplus \"TagName\"/\"TagBinary\"-elements will " 92 string lng = child->readString();
98 "\"SimpleTag\"-element contains multiple \"TagLanguage\"-elements. Surplus \"TagLanguage\"-elements will be ignored.", context);
102 if (!tagDefaultFound) {
104 tagDefaultFound =
true;
107 "\"SimpleTag\"-element contains multiple \"TagDefault\" elements. Surplus \"TagDefault\"-elements will be ignored.", context);
111 if (parseNestedFields) {
116 "Nested fields are currently not supported. Nested tags can not be displayed and will be discarded when rewriting the file.",
126 "\"SimpleTag\"-element contains unknown element ", child->idToString(),
" at ", child->startOffset(),
". It will be ignored."),
144 static const string context(
"making Matroska \"SimpleTag\" element.");
147 diag.emplace_back(
DiagLevel::Critical,
"Can not make \"SimpleTag\" element with empty \"TagName\".", context);
152 }
catch (
const ConversionException &) {
153 diag.emplace_back(
DiagLevel::Critical,
"The assigned tag value can not be converted to be written appropriately.", context);
185 m_stringValue = m_field.value().toString();
186 }
catch (
const ConversionException &) {
188 "The assigned tag value can not be converted to a string and is treated as binary value (which is likely not what you want since " 189 "official Matroska specifiecation doesn't list any binary fields).",
190 "making Matroska \"SimpleTag\" element.");
193 size_t languageSize = m_field.value().language().size();
200 + m_field.id().size()
211 m_nestedMaker.emplace_back(nestedField.prepareMaking(diag));
212 m_simpleTagSize += m_nestedMaker.back().m_totalSize;
226 BinaryWriter writer(&stream);
231 stream.write(buff, sizeDenotationLen);
235 stream.write(buff, sizeDenotationLen);
236 stream.write(m_field.
id().c_str(), m_field.
id().size());
240 stream.put(static_cast<ostream::char_type>(0x80 | 3));
241 stream.write(
"und", 3);
244 stream.write(buff, sizeDenotationLen);
249 stream.put(static_cast<ostream::char_type>(0x80 | 1));
255 stream.write(buff, sizeDenotationLen);
260 stream.write(buff, sizeDenotationLen);
261 stream.write(m_stringValue.data(), m_stringValue.size());
264 for (
const auto &maker : m_nestedMaker) {
TAG_PARSER_EXPORT const char * language()
MatroskaTagFieldMaker prepareMaking(Diagnostics &diag)
Prepares making.
const std::vector< MatroskaTagField > & nestedFields() const
Returns the nested fields.
ImplementationType * firstChild()
Returns the first child of the element.
static byte calculateSizeDenotationLength(uint64 size)
Returns the length of the size denotation for the specified size in byte.
std::size_t dataSize() const
Returns the size of the assigned value in bytes.
void make(std::ostream &stream) const
Saves the field (specified when constructing the object) to the specified stream (makes a "SimpleTag"...
void setDefault(bool isDefault)
Sets whether the field is labeled as default.
Contains utility classes helping to read and write streams.
void parse(Diagnostics &diag)
Parses the header information of the element which is read from the related stream at the start offse...
const std::string & language() const
Returns the language.
static byte makeSizeDenotation(uint64 size, char *buff)
Makes the size denotation for the specified size and stores it to buff.
The TagField class is used by FieldMapBasedTag to store the fields.
void setLanguage(const std::string &language)
Sets the language.
char * dataPointer()
Returns a pointer to the raw data assigned to the current instance.
const IdentifierType & id() const
Returns the id of the current TagField.
void make(std::ostream &stream, Diagnostics &diag)
Saves the field to the specified stream (makes a "SimpleTag" element).
bool isDefault() const
Returns an indication whether the field is labeled as default.
void assignData(const char *data, size_t length, TagDataType type=TagDataType::Binary, TagTextEncoding encoding=TagTextEncoding::Latin1)
Assigns a copy of the given data.
void reparse(EbmlElement &simpleTagElement, Diagnostics &diag, bool parseNestedFields=true)
Parses field information from the specified EbmlElement.
void setId(const IdentifierType &id)
Sets the id of the current Tag Field.
TagValue & value()
Returns the value of the current TagField.