Coverage Report

Created: 2025-12-31 07:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/x86_64-unknown-linux-gnu/include/ebml/EbmlMaster.h
Line
Count
Source
1
/****************************************************************************
2
** libebml : parse EBML files, see http://embl.sourceforge.net/
3
**
4
** <file/class description>
5
**
6
** Copyright (C) 2002-2010 Steve Lhomme.  All rights reserved.
7
**
8
** This file is part of libebml.
9
**
10
** This library is free software; you can redistribute it and/or
11
** modify it under the terms of the GNU Lesser General Public
12
** License as published by the Free Software Foundation; either
13
** version 2.1 of the License, or (at your option) any later version.
14
**
15
** This library is distributed in the hope that it will be useful,
16
** but WITHOUT ANY WARRANTY; without even the implied warranty of
17
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
** Lesser General Public License for more details.
19
**
20
** You should have received a copy of the GNU Lesser General Public
21
** License along with this library; if not, write to the Free Software
22
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
**
24
** See http://www.gnu.org/licenses/lgpl-2.1.html for LGPL licensing information.
25
**
26
** Contact license@matroska.org if any conditions of this licensing are
27
** not clear to you.
28
**
29
**********************************************************************/
30
31
/*!
32
  \file
33
  \version \$Id: EbmlMaster.h 1232 2005-10-15 15:56:52Z robux4 $
34
  \author Steve Lhomme     <robux4 @ users.sf.net>
35
*/
36
#ifndef LIBEBML_MASTER_H
37
#define LIBEBML_MASTER_H
38
39
#include <string>
40
#include <vector>
41
42
#include "EbmlTypes.h"
43
#include "EbmlElement.h"
44
#include "EbmlCrc32.h"
45
46
#define EBML_MASTER_ITERATOR  std::vector<EbmlElement *>::iterator
47
#define EBML_MASTER_CONST_ITERATOR  std::vector<EbmlElement *>::const_iterator
48
#define EBML_MASTER_RITERATOR std::vector<EbmlElement *>::reverse_iterator
49
#define EBML_MASTER_CONST_RITERATOR std::vector<EbmlElement *>::const_reverse_iterator
50
51
namespace libebml {
52
53
const bool bChecksumUsedByDefault = false;
54
55
/*!
56
    \class EbmlMaster
57
    \brief Handle all operations on an EBML element that contains other EBML elements
58
*/
59
class EBML_DLL_API EbmlMaster : public EbmlElement {
60
  public:
61
    EbmlMaster(const EbmlSemanticContext & aContext, bool bSizeIsKnown = true);
62
    EbmlMaster(const EbmlMaster & ElementToClone);
63
0
    bool ValidateSize() const override {return true;}
64
    /*!
65
      \warning be carefull to clear the memory allocated in the ElementList elsewhere
66
    */
67
    ~EbmlMaster() override;
68
69
    filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override;
70
    filepos_t ReadData(IOCallback & input, ScopeMode ReadFully) override;
71
    filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override;
72
73
    /*!
74
      \brief Set wether the size is finite (size is known in advance when writing, or infinite size is not known on writing)
75
    */
76
0
    bool SetSizeInfinite(bool aIsInfinite = true) override {SetSizeIsFinite(!aIsInfinite); return true;}
77
78
    bool PushElement(EbmlElement & element);
79
0
    uint64 GetSize() const override {
80
0
      if (IsFiniteSize())
81
0
        return EbmlElement::GetSize();
82
0
      return (0-1);
83
0
    }
84
85
4.59k
    uint64 GetDataStart() const {
86
4.59k
      return GetElementPosition() + EBML_ID_LENGTH((const EbmlId&)*this) + CodedSizeLength(EbmlElement::GetSize(), GetSizeLength(), IsFiniteSize());
87
4.59k
    }
88
89
    /*!
90
      \brief find the element corresponding to the ID of the element, NULL if not found
91
    */
92
    EbmlElement *FindElt(const EbmlCallbacks & Callbacks) const;
93
    /*!
94
      \brief find the first element corresponding to the ID of the element
95
    */
96
    EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks, bool bCreateIfNull);
97
    EbmlElement *FindFirstElt(const EbmlCallbacks & Callbacks) const;
98
99
    /*!
100
      \brief find the element of the same type of PasElt following in the list of elements
101
    */
102
    EbmlElement *FindNextElt(const EbmlElement & PastElt, bool bCreateIfNull);
103
    EbmlElement *FindNextElt(const EbmlElement & PastElt) const;
104
    EbmlElement *AddNewElt(const EbmlCallbacks & Callbacks);
105
106
    /*!
107
      \brief add an element at a specified location
108
    */
109
    bool InsertElement(EbmlElement & element, size_t position = 0);
110
    bool InsertElement(EbmlElement & element, const EbmlElement & before);
111
112
    /*!
113
      \brief Read the data and keep the known children
114
    */
115
    void Read(EbmlStream & inDataStream, const EbmlSemanticContext & Context, int & UpperEltFound, EbmlElement * & FoundElt, bool AllowDummyElt, ScopeMode ReadFully = SCOPE_ALL_DATA) override;
116
117
    /*!
118
      \brief sort Data when they can
119
    */
120
    void Sort();
121
122
127
    size_t ListSize() const {return ElementList.size();}
123
0
    std::vector<EbmlElement *> const &GetElementList() const {return ElementList;}
124
0
    std::vector<EbmlElement *> &GetElementList() {return ElementList;}
125
126
19.7k
        inline EBML_MASTER_ITERATOR begin() {return ElementList.begin();}
127
19.7k
        inline EBML_MASTER_ITERATOR end() {return ElementList.end();}
128
0
        inline EBML_MASTER_RITERATOR rbegin() {return ElementList.rbegin();}
129
0
        inline EBML_MASTER_RITERATOR rend() {return ElementList.rend();}
130
11.1k
        inline EBML_MASTER_CONST_ITERATOR begin() const {return ElementList.begin();}
131
11.1k
        inline EBML_MASTER_CONST_ITERATOR end() const {return ElementList.end();}
132
0
        inline EBML_MASTER_CONST_RITERATOR rbegin() const {return ElementList.rbegin();}
133
0
        inline EBML_MASTER_CONST_RITERATOR rend() const {return ElementList.rend();}
134
135
0
    EbmlElement * operator[](unsigned int position) {return ElementList[position];}
136
0
    const EbmlElement * operator[](unsigned int position) const {return ElementList[position];}
137
138
0
    bool IsDefaultValue() const override {
139
0
      return (ElementList.empty());
140
0
    }
141
0
    bool IsMaster() const override {return true;}
142
143
    /*!
144
      \brief verify that all mandatory elements are present
145
      \note usefull after reading or before writing
146
    */
147
    bool CheckMandatory() const;
148
149
    /*!
150
      \brief Remove an element from the list of the master
151
    */
152
    void Remove(size_t Index);
153
    void Remove(EBML_MASTER_ITERATOR & Itr);
154
    void Remove(EBML_MASTER_RITERATOR & Itr);
155
156
    /*!
157
      \brief remove all elements, even the mandatory ones
158
    */
159
0
    void RemoveAll() {ElementList.clear();}
160
161
    /*!
162
      \brief facility for Master elements to write only the head and force the size later
163
    */
164
    filepos_t WriteHead(IOCallback & output, int SizeLength, bool bWithDefault = false);
165
166
0
    void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; }
167
0
    bool HasChecksum() const {return bChecksumUsed;}
168
    bool VerifyChecksum() const;
169
0
    uint32 GetCrc32() const {return Checksum.GetCrc32();}
170
0
    void ForceChecksum(uint32 NewChecksum) {
171
0
      Checksum.ForceCrc32(NewChecksum);
172
0
      bChecksumUsed = true;
173
0
    }
174
175
    /*!
176
      \brief drill down all sub-elements, finding any missing elements
177
    */
178
    std::vector<std::string> FindAllMissingElements();
179
180
#if defined(EBML_STRICT_API)
181
    private:
182
#else
183
    protected:
184
#endif
185
    std::vector<EbmlElement *> ElementList;
186
187
    const EbmlSemanticContext & Context;
188
189
    bool      bChecksumUsed;
190
    EbmlCrc32 Checksum;
191
192
  private:
193
    /*!
194
      \brief Add all the mandatory elements to the list
195
    */
196
    bool ProcessMandatory();
197
};
198
199
///< \todo add a restriction to only elements legal in the context
200
template <typename Type>
201
Type & GetChild(EbmlMaster & Master)
202
7.64k
{
203
7.64k
  return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true)));
204
7.64k
}
libebml::EDocType& libebml::GetChild<libebml::EDocType>(libebml::EbmlMaster&)
Line
Count
Source
202
3.83k
{
203
3.83k
  return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true)));
204
3.83k
}
libebml::EDocTypeReadVersion& libebml::GetChild<libebml::EDocTypeReadVersion>(libebml::EbmlMaster&)
Line
Count
Source
202
3.81k
{
203
3.81k
  return *(static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), true)));
204
3.81k
}
205
// call with
206
// MyDocType = GetChild<EDocType>(TestHead);
207
208
template <typename Type>
209
Type * FindChild(EbmlMaster & Master)
210
41
{
211
41
  return static_cast<Type *>(Master.FindFirstElt(EBML_INFO(Type), false));
212
41
}
213
214
template <typename Type>
215
Type & GetNextChild(EbmlMaster & Master, const Type & PastElt)
216
{
217
  return *(static_cast<Type *>(Master.FindNextElt(PastElt, true)));
218
}
219
220
template <typename Type>
221
Type * FindNextChild(EbmlMaster & Master, const Type & PastElt)
222
18
{
223
18
  return static_cast<Type *>(Master.FindNextElt(PastElt, false));
224
18
}
225
226
template <typename Type>
227
Type & AddNewChild(EbmlMaster & Master)
228
{
229
  return *(static_cast<Type *>(Master.AddNewElt(EBML_INFO(Type))));
230
}
231
232
} // namespace libebml
233
234
#endif // LIBEBML_MASTER_H