Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use std:: types instead of custom integers #121

Merged
merged 6 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ set(libebml_PUBLIC_HEADERS
ebml/SafeReadIOCallback.h
ebml/StdIOCallback.h)

set(libebml_C_PUBLIC_HEADERS ebml/c/libebml_t.h)

add_library(ebml ${libebml_SOURCES} ${libebml_PUBLIC_HEADERS} ${libebml_C_PUBLIC_HEADERS})
add_library(ebml ${libebml_SOURCES} ${libebml_PUBLIC_HEADERS})
if(WIN32)
include(CheckIncludeFile)
check_include_file(winapifamily.h HAVE_WINAPIFAMILY_H)
Expand Down Expand Up @@ -115,7 +113,6 @@ install(TARGETS ebml
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES ${libebml_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ebml)
install(FILES ${libebml_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ebml/c)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ebml_export.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ebml)

if(NOT DISABLE_PKGCONFIG)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
exceeded 4 GB.
* Bumped the library's soname to 6 due to ABI breaking changes that
already happened in 1.4.3.
* Remove libebml_t.h.

# Version 1.4.3 2022-09-30

Expand Down
4 changes: 2 additions & 2 deletions ebml/EbmlBinary.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ class EBML_DLL_API EbmlBinary : public EbmlElement {
filepos_t ReadData(IOCallback & input, ScopeMode ReadFully = SCOPE_ALL_DATA) override;
filepos_t UpdateSize(bool bWithDefault = false, bool bForceRender = false) override;

void SetBuffer(const binary *Buffer, const uint32 BufferSize) {
void SetBuffer(const binary *Buffer, const std::uint32_t BufferSize) {
Data = const_cast<binary *>(Buffer);
SetSize_(BufferSize);
SetValueIsSet();
}

binary *GetBuffer() const {return Data;}

void CopyBuffer(const binary *Buffer, const uint32 BufferSize) {
void CopyBuffer(const binary *Buffer, const std::uint32_t BufferSize) {
if (Data != nullptr)
free(Data);
Data = static_cast<binary *>(malloc(BufferSize * sizeof(binary)));
Expand Down
18 changes: 9 additions & 9 deletions ebml/EbmlCrc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,27 @@ DECLARE_EBML_BINARY(EbmlCrc32)
Use this to quickly check a CRC32 with some data
\return True if inputCRC matches CRC32 generated from input data
*/
static bool CheckCRC(uint32 inputCRC, const binary *input, uint32 length);
static bool CheckCRC(std::uint32_t inputCRC, const binary *input, std::uint32_t length);
/*!
Calls Update() and Finalize(), use to create a CRC32 in one go
*/
void FillCRC32(const binary *input, uint32 length);
void FillCRC32(const binary *input, std::uint32_t length);
/*!
Add data to the CRC table, in other words process some data bit by bit
*/
void Update(const binary *input, uint32 length);
void Update(const binary *input, std::uint32_t length);
/*!
Use this with Update() to Finalize() or Complete the CRC32
*/
void Finalize();
/*!
Returns a uint32 that has the value of the CRC32
Returns a std::uint32_t that has the value of the CRC32
*/
uint32 GetCrc32() const {
std::uint32_t GetCrc32() const {
return m_crc_final;
}

void ForceCrc32(uint32 NewValue) { m_crc_final = NewValue; SetValueIsSet();}
void ForceCrc32(std::uint32_t NewValue) { m_crc_final = NewValue; SetValueIsSet();}

#if defined(EBML_STRICT_API)
private:
Expand All @@ -93,9 +93,9 @@ DECLARE_EBML_BINARY(EbmlCrc32)
void ResetCRC();
void UpdateByte(binary b);

static const std::array<uint32, 256> m_tab;
uint32 m_crc;
uint32 m_crc_final{0};
static const std::array<std::uint32_t, 256> m_tab;
std::uint32_t m_crc;
std::uint32_t m_crc_final{0};

EBML_CONCRETE_CLASS(EbmlCrc32)
};
Expand Down
12 changes: 6 additions & 6 deletions ebml/EbmlDate.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class EBML_DLL_API EbmlDate : public EbmlElement {
\brief set the date with a UNIX/C/EPOCH form
\param NewDate UNIX/C date in UTC (no timezone)
*/
void SetEpochDate(int64 NewDate) {myDate = (NewDate - UnixEpochDelay) * 1000000000; SetValueIsSet();}
EbmlDate &SetValue(int64 NewValue) {SetEpochDate(NewValue); return *this;}
void SetEpochDate(std::int64_t NewDate) {myDate = (NewDate - UnixEpochDelay) * 1000000000; SetValueIsSet();}
EbmlDate &SetValue(std::int64_t NewValue) {SetEpochDate(NewValue); return *this;}

/*!
\brief get the date with a UNIX/C/EPOCH form
\note the date is in UTC (no timezone)
*/
int64 GetEpochDate() const {return static_cast<int64>(myDate/1000000000 + UnixEpochDelay);}
int64 GetValue() const {return GetEpochDate();}
std::int64_t GetEpochDate() const {return static_cast<std::int64_t>(myDate/1000000000 + UnixEpochDelay);}
std::int64_t GetValue() const {return GetEpochDate();}

bool ValidateSize() const override {return IsFiniteSize() && ((GetSize() == 8) || (GetSize() == 0));}

Expand Down Expand Up @@ -89,9 +89,9 @@ class EBML_DLL_API EbmlDate : public EbmlElement {
#endif
filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override;

int64 myDate{0}; ///< internal format of the date
std::int64_t myDate{0}; ///< internal format of the date

static const uint64 UnixEpochDelay = 978307200; // 2001/01/01 00:00:00 UTC
static const std::uint64_t UnixEpochDelay = 978307200; // 2001/01/01 00:00:00 UTC
};

} // namespace libebml
Expand Down
56 changes: 28 additions & 28 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ namespace libebml {
/*!
\brief The size of the EBML-coded length
*/
int EBML_DLL_API CodedSizeLength(uint64 Length, unsigned int SizeLength, bool bSizeIsFinite = true);
int EBML_DLL_API CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsFinite = true);

/*!
\brief The coded value of the EBML-coded length
\note The size of OutBuffer must be 8 octets at least
*/
int EBML_DLL_API CodedValueLength(uint64 Length, int CodedSize, binary * OutBuffer);
int EBML_DLL_API CodedValueLength(std::uint64_t Length, int CodedSize, binary * OutBuffer);

/*!
\brief Read an EBML-coded value from a buffer
\return the value read
*/
uint64 EBML_DLL_API ReadCodedSizeValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown);
std::uint64_t EBML_DLL_API ReadCodedSizeValue(const binary * InBuffer, std::uint32_t & BufferSize, std::uint64_t & SizeUnknown);

/*!
\brief The size of the EBML-coded signed length
*/
int EBML_DLL_API CodedSizeLengthSigned(int64 Length, unsigned int SizeLength);
int EBML_DLL_API CodedSizeLengthSigned(std::int64_t Length, unsigned int SizeLength);

/*!
\brief The coded value of the EBML-coded signed length
\note the size of OutBuffer must be 8 octets at least
*/
int EBML_DLL_API CodedValueLengthSigned(int64 Length, int CodedSize, binary * OutBuffer);
int EBML_DLL_API CodedValueLengthSigned(std::int64_t Length, int CodedSize, binary * OutBuffer);

/*!
\brief Read a signed EBML-coded value from a buffer
\return the value read
*/
int64 EBML_DLL_API ReadCodedSizeSignedValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown);
std::int64_t EBML_DLL_API ReadCodedSizeSignedValue(const binary * InBuffer, std::uint32_t & BufferSize, std::uint64_t & SizeUnknown);

class EbmlStream;
class EbmlSemanticContext;
Expand Down Expand Up @@ -332,7 +332,7 @@ using _GetSemanticContext = const class EbmlSemanticContext &(*)();
*/
class EBML_DLL_API EbmlSemanticContext {
public:
EbmlSemanticContext(size_t aSize,
EbmlSemanticContext(std::size_t aSize,
const EbmlSemantic *aMyTable,
const EbmlSemanticContext *aUpTable,
const _GetSemanticContext aGetGlobalContext,
Expand All @@ -346,18 +346,18 @@ class EBML_DLL_API EbmlSemanticContext {
(MasterElt != aElt.MasterElt));
}

inline size_t GetSize() const { return Size; }
inline std::size_t GetSize() const { return Size; }
inline const EbmlCallbacks* GetMaster() const { return MasterElt; }
inline const EbmlSemanticContext* Parent() const { return UpTable; }
const EbmlSemantic & GetSemantic(size_t i) const;
const EbmlSemantic & GetSemantic(std::size_t i) const;

const _GetSemanticContext GetGlobalContext; ///< global elements supported at this level

#if defined(EBML_STRICT_API)
private:
#endif
const EbmlSemantic *MyTable; ///< First element in the table
size_t Size; ///< number of elements in the table
std::size_t Size; ///< number of elements in the table
const EbmlSemanticContext *UpTable; ///< Parent element
/// \todo replace with the global context directly
const EbmlCallbacks *MasterElt;
Expand All @@ -369,20 +369,20 @@ class EBML_DLL_API EbmlSemanticContext {
*/
class EBML_DLL_API EbmlElement {
public:
explicit EbmlElement(uint64 aDefaultSize, bool bValueSet = false);
explicit EbmlElement(std::uint64_t aDefaultSize, bool bValueSet = false);
virtual ~EbmlElement();

/// Set the minimum length that will be used to write the element size (-1 = optimal)
void SetSizeLength(int NewSizeLength) {SizeLength = NewSizeLength;}
int GetSizeLength() const {return SizeLength;}

static EbmlElement * FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
static EbmlElement * FindNextID(IOCallback & DataStream, const EbmlCallbacks & ClassInfos, uint64 MaxDataSize);
static EbmlElement * FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, std::uint64_t MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1);
static EbmlElement * FindNextID(IOCallback & DataStream, const EbmlCallbacks & ClassInfos, std::uint64_t MaxDataSize);

/*!
\brief find the next element with the same ID
*/
EbmlElement * FindNext(IOCallback & DataStream, uint64 MaxDataSize);
EbmlElement * FindNext(IOCallback & DataStream, std::uint64_t MaxDataSize);

EbmlElement * SkipData(EbmlStream & DataStream, const EbmlSemanticContext & Context, EbmlElement * TestReadElt = nullptr, bool AllowDummyElt = false);

Expand All @@ -407,11 +407,11 @@ class EBML_DLL_API EbmlElement {

virtual bool ValidateSize() const = 0;

uint64 GetElementPosition() const {
std::uint64_t GetElementPosition() const {
return ElementPosition;
}

uint64 ElementSize(bool bWithDefault = false) const; /// return the size of the header+data, before writing
std::uint64_t ElementSize(bool bWithDefault = false) const; /// return the size of the header+data, before writing

filepos_t Render(IOCallback & output, bool bWithDefault = false, bool bKeepPosition = false, bool bForceRender = false);

Expand All @@ -433,23 +433,23 @@ class EBML_DLL_API EbmlElement {
virtual bool IsDummy() const {return false;}
virtual bool IsMaster() const {return false;}

size_t HeadSize() const {
std::size_t HeadSize() const {
return EBML_ID_LENGTH((const EbmlId&)*this) + CodedSizeLength(Size, SizeLength, bSizeIsFinite);
} /// return the size of the head, on reading/writing

/*!
\brief Force the size of an element
\warning only possible if the size is "undefined"
*/
bool ForceSize(uint64 NewSize);
bool ForceSize(std::uint64_t NewSize);

filepos_t OverwriteHead(IOCallback & output, bool bKeepPosition = false);
filepos_t OverwriteData(IOCallback & output, bool bKeepPosition = false);

/*!
\brief void the content of the element (replace by EbmlVoid)
*/
uint64 VoidMe(IOCallback & output, bool bWithDefault = false) const;
std::uint64_t VoidMe(IOCallback & output, bool bWithDefault = false) const;

bool DefaultISset() const {return DefaultIsSet;}
void ForceNoDefault() {SetDefaultIsSet(false);}
Expand All @@ -459,11 +459,11 @@ class EBML_DLL_API EbmlElement {
/*!
\brief set the default size of an element
*/
virtual void SetDefaultSize(uint64 aDefaultSize) {DefaultSize = aDefaultSize;}
virtual void SetDefaultSize(std::uint64_t aDefaultSize) {DefaultSize = aDefaultSize;}

bool ValueIsSet() const {return bValueIsSet;}

inline uint64 GetEndPosition() const {
inline std::uint64_t GetEndPosition() const {
assert(bSizeIsFinite); // we don't know where the end is
return SizePosition + CodedSizeLength(Size, SizeLength, bSizeIsFinite) + Size;
}
Expand All @@ -488,22 +488,22 @@ class EBML_DLL_API EbmlElement {
*/
EbmlElement(const EbmlElement & ElementToClone) = default;

inline uint64 GetDefaultSize() const {return DefaultSize;}
inline void SetSize_(uint64 aSize) {Size = aSize;}
inline std::uint64_t GetDefaultSize() const {return DefaultSize;}
inline void SetSize_(std::uint64_t aSize) {Size = aSize;}
inline void SetValueIsSet(bool Set = true) {bValueIsSet = Set;}
inline void SetDefaultIsSet(bool Set = true) {DefaultIsSet = Set;}
inline void SetSizeIsFinite(bool Set = true) {bSizeIsFinite = Set;}
inline uint64 GetSizePosition() const {return SizePosition;}
inline std::uint64_t GetSizePosition() const {return SizePosition;}

#if defined(EBML_STRICT_API)
private:
#endif
uint64 Size; ///< the size of the data to write
uint64 DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal)
std::uint64_t Size; ///< the size of the data to write
std::uint64_t DefaultSize; ///< Minimum data size to fill on rendering (0 = optimal)
int SizeLength{0}; /// the minimum size on which the size will be written (0 = optimal)
bool bSizeIsFinite{true};
uint64 ElementPosition{0};
uint64 SizePosition{0};
std::uint64_t ElementPosition{0};
std::uint64_t SizePosition{0};
bool bValueIsSet;
bool DefaultIsSet{false};
bool bLocked{false};
Expand Down
6 changes: 3 additions & 3 deletions ebml/EbmlEndian.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template<class TYPE, endianess ENDIAN> class Endian
inline operator const TYPE&() const { return platform_value; }
// inline TYPE endian() const { return endian_value; }
inline const TYPE &endian() const { return endian_value; }
inline size_t size() const { return sizeof(TYPE); }
inline std::size_t size() const { return sizeof(TYPE); }
inline bool operator!=(const binary *buffer) const {return *(reinterpret_cast<TYPE*>(buffer)) == platform_value;}

#if defined(EBML_STRICT_API)
Expand All @@ -102,7 +102,7 @@ template<class TYPE, endianess ENDIAN> class Endian
#else // _ENDIANESS_
if (ENDIAN == big_endian)
#endif // _ENDIANESS_
std::reverse(reinterpret_cast<uint8*>(&endian_value),reinterpret_cast<uint8*>(&endian_value+1));
std::reverse(reinterpret_cast<std::uint8_t*>(&endian_value),reinterpret_cast<std::uint8_t*>(&endian_value+1));
}

inline void process_platform()
Expand All @@ -113,7 +113,7 @@ template<class TYPE, endianess ENDIAN> class Endian
#else // _ENDIANESS_
if (ENDIAN == big_endian)
#endif // _ENDIANESS_
std::reverse(reinterpret_cast<uint8*>(&platform_value),reinterpret_cast<uint8*>(&platform_value+1));
std::reverse(reinterpret_cast<std::uint8_t*>(&platform_value),reinterpret_cast<std::uint8_t*>(&platform_value+1));
}
};

Expand Down
10 changes: 5 additions & 5 deletions ebml/EbmlId.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class EBML_DLL_API EbmlId {
}
}

EbmlId(const uint32 aValue, const unsigned int aLength)
EbmlId(const std::uint32_t aValue, const unsigned int aLength)
:Value(aValue), Length(aLength) {}

inline bool operator==(const EbmlId & TestId) const
Expand All @@ -84,14 +84,14 @@ class EBML_DLL_API EbmlId {
}
}

inline size_t GetLength() const { return Length; }
inline uint32 GetValue() const { return Value; }
inline std::size_t GetLength() const { return Length; }
inline std::uint32_t GetValue() const { return Value; }

#if defined(EBML_STRICT_API)
private:
#endif
uint32 Value;
size_t Length;
std::uint32_t Value;
std::size_t Length;
};

} // namespace libebml
Expand Down
Loading