Coverage Report

Created: 2025-11-14 06:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/x86_64-unknown-linux-gnu/include/ebml/EbmlCrc32.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$
34
  \author Steve Lhomme     <robux4 @ users.sf.net>
35
  \author Jory Stone       <jcsston @ toughguy.net>
36
*/
37
#ifndef LIBEBML_CRC32_H
38
#define LIBEBML_CRC32_H
39
40
#include <cassert>
41
42
#include "EbmlTypes.h"
43
#include "EbmlBinary.h"
44
45
namespace libebml {
46
47
DECLARE_EBML_BINARY(EbmlCrc32)
48
  public:
49
    EbmlCrc32(const EbmlCrc32 & ElementToClone);
50
    EbmlCrc32 &operator =(const EbmlCrc32 &) = default;
51
0
    bool ValidateSize() const override {return IsFiniteSize() && (GetSize() == 4);}
52
    filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override;
53
    filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override;
54
//    filepos_t UpdateSize(bool bWithDefault = false);
55
56
0
    bool IsDefaultValue() const override {
57
0
      return false;
58
0
    }
59
60
    void AddElementCRC32(EbmlElement &ElementToCRC);
61
    bool CheckElementCRC32(EbmlElement &ElementToCRC);
62
63
    /*!
64
      Use this to quickly check a CRC32 with some data
65
      \return True if inputCRC matches CRC32 generated from input data
66
    */
67
    static bool CheckCRC(uint32 inputCRC, const binary *input, uint32 length);
68
    /*!
69
      Calls Update() and Finalize(), use to create a CRC32 in one go
70
    */
71
    void FillCRC32(const binary *input, uint32 length);
72
    /*!
73
      Add data to the CRC table, in other words process some data bit by bit
74
    */
75
    void Update(const binary *input, uint32 length);
76
    /*!
77
      Use this with Update() to Finalize() or Complete the CRC32
78
    */
79
    void Finalize();
80
    /*!
81
      Returns a uint32 that has the value of the CRC32
82
    */
83
0
    uint32 GetCrc32() const {
84
0
      return m_crc_final;
85
0
    }
86
87
0
    void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();}
88
89
#if defined(EBML_STRICT_API)
90
    private:
91
#else
92
    protected:
93
#endif
94
    void ResetCRC();
95
    void UpdateByte(binary b);
96
97
    static const uint32 m_tab[256];
98
    uint32 m_crc;
99
    uint32 m_crc_final;
100
101
        EBML_CONCRETE_CLASS(EbmlCrc32)
102
};
103
104
template <class T>
105
inline unsigned int GetAlignment(T * /* dummy */=nullptr) // VC60 workaround
106
{
107
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
108
  return __alignof(T);
109
#elif defined(__GNUC__)
110
  return __alignof__(T);
111
#else
112
  return sizeof(T);
113
#endif
114
}
115
116
template <class T>
117
inline bool IsPowerOf2(T n)
118
0
{
119
0
  return n > 0 && (n & (n-1)) == 0;
120
0
}
121
122
template <class T1, class T2>
123
inline T2 ModPowerOf2(T1 a, T2 b)
124
0
{
125
0
  assert(IsPowerOf2(b));
126
0
  return static_cast<T2>(a) & (b-1);
127
0
}
128
129
inline bool IsAlignedOn(const void *p, unsigned int alignment)
130
0
{
131
0
  return IsPowerOf2(alignment) ? ModPowerOf2(reinterpret_cast<uintptr_t>(p), alignment) == 0 : reinterpret_cast<uintptr_t>(p) % alignment == 0;
132
0
}
133
134
template <class T>
135
inline bool IsAligned(const void *p, T * /* dummy */=nullptr)  // VC60 workaround
136
{
137
  return IsAlignedOn(p, GetAlignment<T>());
138
}
139
140
} // namespace libebml
141
142
#endif // LIBEBML_CRC32_H