From 9a5cf1be5446b7323425049c24d754c711a66693 Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Fri, 29 Dec 2023 09:23:38 +0100 Subject: [PATCH] use assignment by reference instead of pointers No need to dereference a pointer. --- src/KaxBlockData.cpp | 2 +- src/KaxCues.cpp | 2 +- src/KaxCuesData.cpp | 20 ++++++------- src/KaxSeekHead.cpp | 2 +- src/KaxTracks.cpp | 2 +- test/ebml/test00.cpp | 6 ++-- test/mux/test6.cpp | 70 ++++++++++++++++++++++---------------------- test/tags/test9.cpp | 24 +++++++-------- 8 files changed, 64 insertions(+), 64 deletions(-) diff --git a/src/KaxBlockData.cpp b/src/KaxBlockData.cpp index 0713c145..21cecdbd 100644 --- a/src/KaxBlockData.cpp +++ b/src/KaxBlockData.cpp @@ -73,7 +73,7 @@ void KaxReferenceBlock::SetReferencedBlock(const KaxBlockGroup & aRefdBlock) { FreeBlob(); auto block_blob = new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE); - block_blob->SetBlockGroup(*const_cast(&aRefdBlock)); + block_blob->SetBlockGroup(const_cast(aRefdBlock)); RefdBlock = block_blob; bOurBlob = true; SetValueIsSet(); diff --git a/src/KaxCues.cpp b/src/KaxCues.cpp index 3bcfe5a5..c1d5b18b 100644 --- a/src/KaxCues.cpp +++ b/src/KaxCues.cpp @@ -27,7 +27,7 @@ bool KaxCues::AddBlockGroup(const KaxBlockGroup & BlockRef) // Do not add the element if it's already present. std::vector::iterator ListIdx; KaxBlockBlob *BlockReference = new KaxBlockBlob(BLOCK_BLOB_NO_SIMPLE); - BlockReference->SetBlockGroup(*const_cast(&BlockRef)); + BlockReference->SetBlockGroup(const_cast(BlockRef)); for (ListIdx = myTempReferences.begin(); ListIdx != myTempReferences.end(); ListIdx++) if (&(KaxBlockGroup&)*ListIdx == &BlockRef) { diff --git a/src/KaxCuesData.cpp b/src/KaxCuesData.cpp index d713e5e6..4b185a0d 100644 --- a/src/KaxCuesData.cpp +++ b/src/KaxCuesData.cpp @@ -26,14 +26,14 @@ void KaxCuePoint::PositionSet(const KaxBlockGroup & BlockReference, std::uint64_ { // fill me auto & NewTime = GetChild(*this); - *static_cast(&NewTime) = BlockReference.GlobalTimecode() / GlobalTimecodeScale; + static_cast(NewTime) = BlockReference.GlobalTimecode() / GlobalTimecodeScale; auto & NewPositions = AddNewChild(*this); auto & TheTrack = GetChild(NewPositions); - *static_cast(&TheTrack) = BlockReference.TrackNumber(); + static_cast(TheTrack) = BlockReference.TrackNumber(); auto & TheClustPos = GetChild(NewPositions); - *static_cast(&TheClustPos) = BlockReference.ClusterPosition(); + static_cast(TheClustPos) = BlockReference.ClusterPosition(); // handle reference use if (BlockReference.ReferenceCount() != 0) { @@ -46,7 +46,7 @@ void KaxCuePoint::PositionSet(const KaxBlockGroup & BlockReference, std::uint64_ auto CodecState = static_cast(BlockReference.FindFirstElt(EBML_INFO(KaxCodecState))); if (CodecState) { auto &CueCodecState = AddNewChild(NewPositions); - *static_cast(&CueCodecState) = BlockReference.GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()); + static_cast(CueCodecState) = BlockReference.GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()); } SetValueIsSet(); @@ -73,14 +73,14 @@ void KaxCuePoint::PositionSet(const KaxInternalBlock & BlockReference, const Kax { // fill me auto & NewTime = GetChild(*this); - *static_cast(&NewTime) = BlockReference.GlobalTimecode() / GlobalTimecodeScale; + static_cast(NewTime) = BlockReference.GlobalTimecode() / GlobalTimecodeScale; auto & NewPositions = AddNewChild(*this); auto & TheTrack = GetChild(NewPositions); - *static_cast(&TheTrack) = BlockReference.TrackNum(); + static_cast(TheTrack) = BlockReference.TrackNum(); auto & TheClustPos = GetChild(NewPositions); - *static_cast(&TheClustPos) = BlockReference.ClusterPosition(); + static_cast(TheClustPos) = BlockReference.ClusterPosition(); #if 0 // MATROSKA_VERSION >= 2 // handle reference use @@ -97,7 +97,7 @@ void KaxCuePoint::PositionSet(const KaxInternalBlock & BlockReference, const Kax const auto CodecState = static_cast(BlockGroup->FindFirstElt(EBML_INFO(KaxCodecState))); if (CodecState) { auto &CueCodecState = AddNewChild(NewPositions); - *static_cast(&CueCodecState) = BlockGroup->GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()); + static_cast(CueCodecState) = BlockGroup->GetParentCluster()->GetParentSegment()->GetRelativePosition(CodecState->GetElementPosition()); } } @@ -111,10 +111,10 @@ void KaxCueReference::AddReference(const KaxBlockBlob & BlockReference, std::uin { auto& theBlock = static_cast(BlockReference); auto& NewTime = GetChild(*this); - *static_cast(&NewTime) = theBlock.GlobalTimecode() / GlobalTimecodeScale; + static_cast(NewTime) = theBlock.GlobalTimecode() / GlobalTimecodeScale; auto & TheClustPos = GetChild(*this); - *static_cast(&TheClustPos) = theBlock.ClusterPosition(); + static_cast(TheClustPos) = theBlock.ClusterPosition(); } bool KaxCuePoint::IsSmallerThan(const EbmlElement * Cmp) const diff --git a/src/KaxSeekHead.cpp b/src/KaxSeekHead.cpp index ff77c851..359bad91 100644 --- a/src/KaxSeekHead.cpp +++ b/src/KaxSeekHead.cpp @@ -26,7 +26,7 @@ KaxSeek * KaxSeekHead::IndexThis(const EbmlElement & aElt, const KaxSegment & Pa // add the informations to this element auto & aNewPos = GetChild(aNewPoint); - *static_cast(&aNewPos) = ParentSegment.GetRelativePosition(aElt); + static_cast(aNewPos) = ParentSegment.GetRelativePosition(aElt); auto & aNewID = GetChild(aNewPoint); binary ID[4]; diff --git a/src/KaxTracks.cpp b/src/KaxTracks.cpp index 90bacaab..7e6a7939 100644 --- a/src/KaxTracks.cpp +++ b/src/KaxTracks.cpp @@ -20,7 +20,7 @@ KaxTrackEntry::KaxTrackEntry() void KaxTrackEntry::EnableLacing(bool bEnable) { auto & myLacing = GetChild(*this); - *(static_cast(&myLacing)) = bEnable ? 1 : 0; + static_cast(myLacing) = bEnable ? 1 : 0; } } // namespace libmatroska diff --git a/test/ebml/test00.cpp b/test/ebml/test00.cpp index c6fb4c2e..17661f6e 100644 --- a/test/ebml/test00.cpp +++ b/test/ebml/test00.cpp @@ -46,13 +46,13 @@ int main(void) printf("Write EBML + Matroska elements\n"); EDocType & MyDocType = GetChild(TestHead); - *static_cast(&MyDocType) = "matroska"; + static_cast(MyDocType) = "matroska"; EDocTypeVersion & MyDocTypeVer = GetChild(TestHead); - *(static_cast(&MyDocTypeVer)) = 1; + static_cast(MyDocTypeVer) = 1; EDocTypeReadVersion & MyDocTypeReadVer = GetChild(TestHead); - *(static_cast(&MyDocTypeReadVer)) = 1; + static_cast(MyDocTypeReadVer) = 1; TestHead.Render(Ebml_file); diff --git a/test/mux/test6.cpp b/test/mux/test6.cpp index 1ed34776..bc06a039 100644 --- a/test/mux/test6.cpp +++ b/test/mux/test6.cpp @@ -52,13 +52,13 @@ int main(int argc, char **argv) EbmlHead FileHead; EDocType & MyDocType = GetChild(FileHead); - *static_cast(&MyDocType) = "matroska"; + static_cast(MyDocType) = "matroska"; EDocTypeVersion & MyDocTypeVer = GetChild(FileHead); - *(static_cast(&MyDocTypeVer)) = 2; + static_cast(MyDocTypeVer) = 2; EDocTypeReadVersion & MyDocTypeReadVer = GetChild(FileHead); - *(static_cast(&MyDocTypeReadVer)) = 1; + static_cast(MyDocTypeReadVer) = 1; FileHead.Render(out_file, bWriteDefaultValues); @@ -79,10 +79,10 @@ int main(int argc, char **argv) // fill the mandatory Info section KaxInfo & MyInfos = GetChild(FileSegment); KaxTimecodeScale & TimeScale = GetChild(MyInfos); - *(static_cast(&TimeScale)) = TIMECODE_SCALE; + static_cast(TimeScale) = TIMECODE_SCALE; KaxDuration & SegDuration = GetChild(MyInfos); - *(static_cast(&SegDuration)) = 0.0; + static_cast(SegDuration) = 0.0; *((EbmlUnicodeString *)&GetChild(MyInfos)) = UTFstring{L"libmatroska 0.5.0"}; *((EbmlUnicodeString *)&GetChild(MyInfos)) = UTFstring{L"����"}; @@ -96,34 +96,34 @@ int main(int argc, char **argv) MyTrack1.SetGlobalTimecodeScale(TIMECODE_SCALE); KaxTrackNumber & MyTrack1Number = GetChild(MyTrack1); - *(static_cast(&MyTrack1Number)) = 1; + static_cast(MyTrack1Number) = 1; KaxTrackUID & MyTrack1UID = GetChild(MyTrack1); - *(static_cast(&MyTrack1UID)) = 7; + static_cast(MyTrack1UID) = 7; - *(static_cast(&GetChild(MyTrack1))) = track_audio; + static_cast(GetChild(MyTrack1)) = track_audio; KaxCodecID & MyTrack1CodecID = GetChild(MyTrack1); - *static_cast(&MyTrack1CodecID) = "Dummy Audio Codec"; + static_cast(MyTrack1CodecID) = "Dummy Audio Codec"; MyTrack1.EnableLacing(true); // Test the new ContentEncoding elements KaxContentEncodings &cencodings = GetChild(MyTrack1); KaxContentEncoding &cencoding = GetChild(cencodings); - *(static_cast(&GetChild(cencoding))) = 10; - *(static_cast(&GetChild(cencoding))) = 11; - *(static_cast(&GetChild(cencoding))) = 12; + static_cast(GetChild(cencoding)) = 10; + static_cast(GetChild(cencoding)) = 11; + static_cast(GetChild(cencoding)) = 12; KaxContentCompression &ccompression = GetChild(cencoding); - *(static_cast(&GetChild(ccompression))) = 13; + static_cast(GetChild(ccompression)) = 13; GetChild(ccompression).CopyBuffer((const binary *)"hello1", 6); KaxContentEncryption &cencryption = GetChild(cencoding); - *(static_cast(&GetChild(cencryption))) = 14; + static_cast(GetChild(cencryption)) = 14; GetChild(cencryption).CopyBuffer((const binary *)"hello2", 6); - *(static_cast(&GetChild(cencryption))) = 15; - *(static_cast(&GetChild(cencryption))) = 16; + static_cast(GetChild(cencryption)) = 15; + static_cast(GetChild(cencryption)) = 16; GetChild(cencryption).CopyBuffer((const binary *)"hello3", 6); GetChild(cencryption).CopyBuffer((const binary *)"hello4", 6); @@ -131,7 +131,7 @@ int main(int argc, char **argv) KaxTrackAudio & MyTrack1Audio = GetChild(MyTrack1); KaxAudioSamplingFreq & MyTrack1Freq = GetChild(MyTrack1Audio); - *(static_cast(&MyTrack1Freq)) = 44100.0; + static_cast(MyTrack1Freq) = 44100.0; MyTrack1Freq.ValidateSize(); KaxAudioPosition & MyTrack1Pos = GetChild(MyTrack1Audio); @@ -144,22 +144,22 @@ int main(int argc, char **argv) MyTrack1Pos.SetBuffer(_Pos, 5); KaxAudioChannels & MyTrack1Channels = GetChild(MyTrack1Audio); - *(static_cast(&MyTrack1Channels)) = 2; + static_cast(MyTrack1Channels) = 2; // fill track 2 params KaxTrackEntry & MyTrack2 = GetNextChild(MyTracks, MyTrack1); MyTrack2.SetGlobalTimecodeScale(TIMECODE_SCALE); KaxTrackNumber & MyTrack2Number = GetChild(MyTrack2); - *(static_cast(&MyTrack2Number)) = 200; + static_cast(MyTrack2Number) = 200; KaxTrackUID & MyTrack2UID = GetChild(MyTrack2); - *(static_cast(&MyTrack2UID)) = 13; + static_cast(MyTrack2UID) = 13; - *(static_cast(&GetChild(MyTrack2))) = track_video; + static_cast(GetChild(MyTrack2)) = track_video; KaxCodecID & MyTrack2CodecID = GetChild(MyTrack2); - *static_cast(&MyTrack2CodecID) = "Dummy Video Codec"; + static_cast(MyTrack2CodecID) = "Dummy Video Codec"; MyTrack2.EnableLacing(false); @@ -167,10 +167,10 @@ int main(int argc, char **argv) KaxTrackVideo & MyTrack2Video = GetChild(MyTrack2); KaxVideoPixelHeight & MyTrack2PHeight = GetChild(MyTrack2Video); - *(static_cast(&MyTrack2PHeight)) = 200; + static_cast(MyTrack2PHeight) = 200; KaxVideoPixelWidth & MyTrack2PWidth = GetChild(MyTrack2Video); - *(static_cast(&MyTrack2PWidth)) = 320; + static_cast(MyTrack2PWidth) = 320; std::uint64_t TrackSize = MyTracks.Render(out_file, bWriteDefaultValues); @@ -279,27 +279,27 @@ int main(int argc, char **argv) KaxEditionEntry & aEdition = GetChild(Chapters); KaxChapterAtom & aAtom = GetChild(aEdition); KaxChapterUID & aUID = GetChild(aAtom); - *static_cast(&aUID) = 0x67890; + static_cast(aUID) = 0x67890; KaxChapterTimeStart & aChapStart = GetChild(aAtom); - *static_cast(&aChapStart) = 0; + static_cast(aChapStart) = 0; KaxChapterTimeEnd & aChapEnd = GetChild(aAtom); - *static_cast(&aChapEnd) = 300 * TIMECODE_SCALE; + static_cast(aChapEnd) = 300 * TIMECODE_SCALE; KaxChapterDisplay & aDisplay = GetChild(aAtom); KaxChapterString & aChapString = GetChild(aDisplay); - *static_cast(&aChapString) = UTFstring{L"Le film r�duit � un chapitre"}; + static_cast(aChapString) = UTFstring{L"Le film r�duit � un chapitre"}; KaxChapterLanguage & aChapLang = GetChild(aDisplay); - *static_cast(&aChapLang) = "fra"; + static_cast(aChapLang) = "fra"; KaxChapterDisplay & aDisplay2 = GetNextChild(aAtom, aDisplay); KaxChapterString & aChapString2 = GetChild(aDisplay2); - *static_cast(&aChapString2) = UTFstring{L"The movie in one chapter"}; + static_cast(aChapString2) = UTFstring{L"The movie in one chapter"}; KaxChapterLanguage & aChapLang2 = GetChild(aDisplay2); - *static_cast(&aChapLang2) = "eng"; + static_cast(aChapLang2) = "eng"; filepos_t ChapterSize = Chapters.Render(out_file, bWriteDefaultValues); MetaSeek.IndexThis(Chapters, FileSegment); @@ -312,16 +312,16 @@ int main(int argc, char **argv) KaxTagSimple & TagSimple = GetChild(aTag); KaxTagTrackUID & TrackUID = GetChild(Targets); - *static_cast(&TrackUID) = 0x12345; + static_cast(TrackUID) = 0x12345; KaxTagChapterUID & ChapterUID = GetChild(Targets); - *static_cast(&ChapterUID) = 0x67890; + static_cast(ChapterUID) = 0x67890; KaxTagName & aTagName = GetChild(TagSimple); - *static_cast(&aTagName) = UTFstring{L"NAME"}; + static_cast(aTagName) = UTFstring{L"NAME"}; KaxTagString & aTagtring = GetChild(TagSimple); - *static_cast(&aTagtring) = UTFstring{L"Test�123"}; + static_cast(aTagtring) = UTFstring{L"Test�123"}; filepos_t TagsSize = AllTags.Render(out_file, bWriteDefaultValues); MetaSeek.IndexThis(AllTags, FileSegment); diff --git a/test/tags/test9.cpp b/test/tags/test9.cpp index 130d05eb..8dc32342 100644 --- a/test/tags/test9.cpp +++ b/test/tags/test9.cpp @@ -38,18 +38,18 @@ int main() { StdIOCallback out("test.mkv", MODE_CREATE); EDocType &doc_type = GetChild(head); - *static_cast(&doc_type) = "matroska"; + static_cast(doc_type) = "matroska"; EDocTypeVersion &doc_type_ver = GetChild(head); - *(static_cast(&doc_type_ver)) = 1; + static_cast(doc_type_ver) = 1; EDocTypeReadVersion &doc_type_read_ver = GetChild(head); - *(static_cast(&doc_type_read_ver)) = 1; + static_cast(doc_type_read_ver) = 1; head.Render(out); KaxInfo &info = GetChild(segment); KaxTimecodeScale &time_scale = GetChild(info); - *(static_cast(&time_scale)) = 1000000; + static_cast(time_scale) = 1000000; segment.WriteHead(out, 5); @@ -59,29 +59,29 @@ int main() { KaxTag &tag = GetChild(tags); KaxTagTargets &targets = GetChild(tag); - *(static_cast(&GetChild(targets))) = + static_cast(GetChild(targets)) = 1234; KaxTagSimple &stag_l1 = GetChild(tag); - *(static_cast(&GetChild(stag_l1))) = + static_cast(GetChild(stag_l1)) = UTFstring{L"SIMPLE_TAG_NAME_LEVEL1_1"}; - *(static_cast(&GetChild(stag_l1))) = + static_cast(GetChild(stag_l1)) = UTFstring{L"SIMPLE_TAG_STRING_LEVEL1_1"}; KaxTagSimple &stag_l1_2 = GetNextChild(tag, stag_l1); - *(static_cast(&GetChild(stag_l1_2))) = + static_cast(GetChild(stag_l1_2)) = UTFstring{L"SIMPLE_TAG_NAME_LEVEL1_2"}; KaxTagBinary &tbin = GetChild(stag_l1_2); tbin.CopyBuffer((binary *)"SIMPLE_TAG_BINARY_LEVEL1_2", strlen("SIMPLE_TAG_BINARY_LEVEL1_2")); KaxTagSimple &stag_l2 = GetChild(stag_l1); - *(static_cast(&GetChild(stag_l2))) = + static_cast(GetChild(stag_l2)) = UTFstring{L"SIMPLE_TAG_NAME_LEVEL2"}; - *(static_cast(&GetChild(stag_l2))) = + static_cast(GetChild(stag_l2)) = UTFstring{L"SIMPLE_TAG_STRING_LEVEL2"}; KaxTagSimple &stag_l3 = GetChild(stag_l2); - *(static_cast(&GetChild(stag_l3))) = + static_cast(GetChild(stag_l3)) = UTFstring{L"SIMPLE_TAG_NAME_LEVEL3"}; - *(static_cast(&GetChild(stag_l3))) = + static_cast(GetChild(stag_l3)) = UTFstring{L"SIMPLE_TAG_STRING_LEVEL3"}; tags.Render(out);