Skip to content

Commit 917040a

Browse files
committed
clazy: remove some non-POD statics
Signed-off-by: Rosen Penev <[email protected]>
1 parent 0191235 commit 917040a

File tree

3 files changed

+99
-77
lines changed

3 files changed

+99
-77
lines changed

src/asfvideo.cpp

Lines changed: 73 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,67 +10,17 @@
1010
#include "helper_functions.hpp"
1111
#include "image_int.hpp"
1212

13-
// *****************************************************************************
14-
// class member definitions
15-
namespace Exiv2 {
16-
17-
/*!
18-
Look-up list for ASF Type Video Files
19-
Associates the GUID with its Name(i.e. Human Readable Form)
20-
Tags have been differentiated into Various Categories.
21-
The categories have been listed above Groups
22-
see :
23-
- https://fr.wikipedia.org/wiki/Advanced_Systems_Format
24-
- https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf
25-
*/
26-
/*
27-
* @class GUID_struct
28-
*
29-
* @brief A class to represent a globally unique identifier (GUID) structure
30-
*
31-
* This class represents a globally unique identifier (GUID) structure which is used to identify objects in a
32-
* distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to
33-
* identify an object across different systems. The GUID structure is comprised of four 32-bit values and an
34-
* array of 8 bytes.
35-
*
36-
* @note The byte order of the GUID structure is in little endian.
37-
*
38-
* @see https://en.wikipedia.org/wiki/Globally_unique_identifier
39-
*
40-
*/
41-
42-
bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const {
43-
return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_;
44-
}
13+
namespace {
14+
constexpr Exiv2::AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C});
4515

46-
AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
47-
data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian);
48-
data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian);
49-
data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian);
50-
std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin());
51-
}
16+
constexpr struct tags {
17+
Exiv2::AsfVideo::GUIDTag first;
18+
std::string_view second;
5219

53-
std::string AsfVideo::GUIDTag::to_string() const {
54-
// Concatenate all strings into a single string
55-
// Convert the string to uppercase
56-
// Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E
57-
return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_,
58-
data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]);
59-
}
60-
61-
bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const {
62-
if (data1_ != other.data1_)
63-
return data1_ < other.data1_;
64-
if (data2_ != other.data2_)
65-
return data2_ < other.data2_;
66-
if (data3_ != other.data3_)
67-
return data3_ < other.data3_;
68-
return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end());
69-
}
70-
71-
constexpr AsfVideo::GUIDTag Header(0x75B22630, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C});
72-
73-
const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = {
20+
bool operator==(const Exiv2::DataBuf& tag) const {
21+
return Exiv2::AsfVideo::GUIDTag(tag.c_data()) == first;
22+
};
23+
} GUIDReferenceTags[] = {
7424
//!< Top-level ASF object GUIDS
7525
{Header, "Header"},
7626
{{0x75B22636, 0x668E, 0x11CF, {0xA6, 0xD9, 0x00, 0xAA, 0x00, 0x62, 0xCE, 0x6C}}, "Data"},
@@ -175,8 +125,68 @@ const std::map<AsfVideo::GUIDTag, std::string> GUIDReferenceTags = {
175125
@param buf Exiv2 byte buffer
176126
@return Returns true if the buffer data is equivalent to Header GUID.
177127
*/
178-
static bool isASFType(const byte buf[]) {
179-
return Header == AsfVideo::GUIDTag(buf);
128+
bool isASFType(const Exiv2::byte buf[]) {
129+
return Header == Exiv2::AsfVideo::GUIDTag(buf);
130+
}
131+
132+
} // namespace
133+
134+
// *****************************************************************************
135+
// class member definitions
136+
namespace Exiv2 {
137+
138+
/*!
139+
Look-up list for ASF Type Video Files
140+
Associates the GUID with its Name(i.e. Human Readable Form)
141+
Tags have been differentiated into Various Categories.
142+
The categories have been listed above Groups
143+
see :
144+
- https://fr.wikipedia.org/wiki/Advanced_Systems_Format
145+
- https://exse.eyewated.com/fls/54b3ed95bbfb1a92.pdf
146+
*/
147+
/*
148+
* @class GUID_struct
149+
*
150+
* @brief A class to represent a globally unique identifier (GUID) structure
151+
*
152+
* This class represents a globally unique identifier (GUID) structure which is used to identify objects in a
153+
* distributed environment. A GUID is a unique identifier that is generated on a computer and can be used to
154+
* identify an object across different systems. The GUID structure is comprised of four 32-bit values and an
155+
* array of 8 bytes.
156+
*
157+
* @note The byte order of the GUID structure is in little endian.
158+
*
159+
* @see https://en.wikipedia.org/wiki/Globally_unique_identifier
160+
*
161+
*/
162+
163+
bool AsfVideo::GUIDTag::operator==(const AsfVideo::GUIDTag& other) const {
164+
return data1_ == other.data1_ && data2_ == other.data2_ && data3_ == other.data3_ && data4_ == other.data4_;
165+
}
166+
167+
AsfVideo::GUIDTag::GUIDTag(const uint8_t* bytes) {
168+
data1_ = Exiv2::getULong(bytes, ByteOrder::littleEndian);
169+
data2_ = Exiv2::getUShort(bytes + DWORD, ByteOrder::littleEndian);
170+
data3_ = Exiv2::getUShort(bytes + DWORD + WORD, ByteOrder::littleEndian);
171+
std::copy(bytes + QWORD, bytes + (2 * QWORD), data4_.begin());
172+
}
173+
174+
std::string AsfVideo::GUIDTag::to_string() const {
175+
// Concatenate all strings into a single string
176+
// Convert the string to uppercase
177+
// Example of output 399595EC-8667-4E2D-8FDB-98814CE76C1E
178+
return stringFormat("{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}", data1_, data2_, data3_,
179+
data4_[0], data4_[1], data4_[2], data4_[3], data4_[4], data4_[5], data4_[6], data4_[7]);
180+
}
181+
182+
bool AsfVideo::GUIDTag::operator<(const GUIDTag& other) const {
183+
if (data1_ != other.data1_)
184+
return data1_ < other.data1_;
185+
if (data2_ != other.data2_)
186+
return data2_ < other.data2_;
187+
if (data3_ != other.data3_)
188+
return data3_ < other.data3_;
189+
return std::lexicographical_compare(data4_.begin(), data4_.end(), other.data4_.begin(), other.data4_.end());
180190
}
181191

182192
AsfVideo::AsfVideo(BasicIo::UniquePtr io) : Image(ImageType::asf, mdNone, std::move(io)) {
@@ -231,9 +241,8 @@ void AsfVideo::decodeBlock() {
231241
<< "\tsize= " << objectHeader.getSize() << "\t " << io_->tell() << "/" << io_->size() << '\n';
232242
#endif
233243
Internal::enforce(objectHeader.getSize() <= io_->size() - io_->tell(), Exiv2::ErrorCode::kerCorruptedMetadata);
234-
auto tag = GUIDReferenceTags.find(GUIDTag(objectHeader.getId().data()));
235244

236-
if (tag != GUIDReferenceTags.end()) {
245+
if (auto tag = Exiv2::find(GUIDReferenceTags, objectHeader.getId())) {
237246
if (tag->second == "Header")
238247
decodeHeader();
239248
else if (tag->second == "File_Properties")
@@ -339,8 +348,7 @@ void AsfVideo::streamProperties() {
339348
enum class streamTypeInfo { Audio = 1, Video = 2 };
340349
auto stream = streamTypeInfo{0};
341350

342-
auto tag_stream_type = GUIDReferenceTags.find(GUIDTag(streamTypedBuf.data()));
343-
if (tag_stream_type != GUIDReferenceTags.end()) {
351+
if (auto tag_stream_type = Exiv2::find(GUIDReferenceTags, streamTypedBuf)) {
344352
if (tag_stream_type->second == "Audio_Media")
345353
stream = streamTypeInfo::Audio;
346354
else if (tag_stream_type->second == "Video_Media")

src/image.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ std::string pathOfFileUrl(const std::string& url) {
129129
}
130130
#endif
131131

132+
bool typeValid(uint16_t type) {
133+
return type >= 1 && type <= 13;
134+
}
135+
136+
std::set<size_t> visits; // #547
137+
132138
} // namespace
133139

134140
// *****************************************************************************
@@ -305,12 +311,6 @@ const char* Image::typeName(uint16_t tag) {
305311
return result;
306312
}
307313

308-
static bool typeValid(uint16_t type) {
309-
return type >= 1 && type <= 13;
310-
}
311-
312-
static std::set<size_t> visits; // #547
313-
314314
void Image::printIFDStructure(BasicIo& io, std::ostream& out, Exiv2::PrintStructureOption option, size_t start,
315315
bool bSwap, char c, size_t depth) {
316316
if (depth == 1)

src/riffvideo.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@
1616

1717
#include <array>
1818

19-
namespace Exiv2::Internal {
19+
namespace {
2020

21-
const std::map<std::string, std::string> infoTags = {
21+
constexpr struct tags {
22+
std::string_view first;
23+
const char* second;
24+
25+
bool operator==(std::string_view tag) const {
26+
return tag == first;
27+
};
28+
} infoTags[] = {
2229
{"AGES", "Xmp.video.Rated"},
2330
{"CMNT", "Xmp.video.Comment"},
2431
{"CODE", "Xmp.video.EncodedBy"},
@@ -105,7 +112,14 @@ const std::map<std::string, std::string> infoTags = {
105112
{"YEAR", "Xmp.video.Year"},
106113
};
107114

108-
const std::map<uint16_t, std::string> audioEncodingValues = {
115+
constexpr struct encoding {
116+
uint16_t first;
117+
std::string_view second;
118+
119+
bool operator==(uint16_t tag) const {
120+
return tag == first;
121+
};
122+
} audioEncodingValues[] = {
109123
{0x1, "Microsoft PCM"},
110124
{0x2, "Microsoft ADPCM"},
111125
{0x3, "Microsoft IEEE float"},
@@ -351,7 +365,7 @@ const std::map<uint16_t, std::string> audioEncodingValues = {
351365
{0xffff, "Development"},
352366
};
353367

354-
} // namespace Exiv2::Internal
368+
} // namespace
355369
// *****************************************************************************
356370
// class member definitions
357371

@@ -625,7 +639,7 @@ void RiffVideo::readStreamFormat(uint64_t size_) {
625639
xmpData_["Xmp.video.NumIfImpColours"] = "All";
626640
} else if (streamType_ == Audio) {
627641
uint16_t format_tag = readWORDTag(io_);
628-
if (auto it = Internal::audioEncodingValues.find(format_tag); it != Internal::audioEncodingValues.end())
642+
if (auto it = Exiv2::find(audioEncodingValues, format_tag))
629643
xmpData_["Xmp.audio.Compressor"] = it->second;
630644
else
631645
xmpData_["Xmp.audio.Compressor"] = format_tag;
@@ -657,7 +671,7 @@ void RiffVideo::readInfoListChunk(uint64_t size_) {
657671
std::string type = readStringTag(io_);
658672
size_t size = readDWORDTag(io_);
659673
std::string content = readStringTag(io_, size);
660-
if (auto it = Internal::infoTags.find(type); it != Internal::infoTags.end())
674+
if (auto it = Exiv2::find(infoTags, type))
661675
xmpData_[it->second] = content;
662676
current_size += DWORD * 2;
663677
current_size += size;

0 commit comments

Comments
 (0)