diff --git a/CMakeLists.txt b/CMakeLists.txt index e3283b2a..cfdb788b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) diff --git a/NEWS.md b/NEWS.md index c9bf0ff7..a0746f5a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/ebml/EbmlBinary.h b/ebml/EbmlBinary.h index f106f2c8..d3714448 100644 --- a/ebml/EbmlBinary.h +++ b/ebml/EbmlBinary.h @@ -70,7 +70,7 @@ 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(Buffer); SetSize_(BufferSize); SetValueIsSet(); @@ -78,7 +78,7 @@ class EBML_DLL_API EbmlBinary : public EbmlElement { 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(malloc(BufferSize * sizeof(binary))); diff --git a/ebml/EbmlCrc32.h b/ebml/EbmlCrc32.h index ae862ce2..008c403b 100644 --- a/ebml/EbmlCrc32.h +++ b/ebml/EbmlCrc32.h @@ -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: @@ -93,9 +93,9 @@ DECLARE_EBML_BINARY(EbmlCrc32) void ResetCRC(); void UpdateByte(binary b); - static const std::array m_tab; - uint32 m_crc; - uint32 m_crc_final{0}; + static const std::array m_tab; + std::uint32_t m_crc; + std::uint32_t m_crc_final{0}; EBML_CONCRETE_CLASS(EbmlCrc32) }; diff --git a/ebml/EbmlDate.h b/ebml/EbmlDate.h index 40be5a37..38c2f7d7 100644 --- a/ebml/EbmlDate.h +++ b/ebml/EbmlDate.h @@ -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(myDate/1000000000 + UnixEpochDelay);} - int64 GetValue() const {return GetEpochDate();} + std::int64_t GetEpochDate() const {return static_cast(myDate/1000000000 + UnixEpochDelay);} + std::int64_t GetValue() const {return GetEpochDate();} bool ValidateSize() const override {return IsFiniteSize() && ((GetSize() == 8) || (GetSize() == 0));} @@ -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 diff --git a/ebml/EbmlElement.h b/ebml/EbmlElement.h index 10d4d737..4328a262 100644 --- a/ebml/EbmlElement.h +++ b/ebml/EbmlElement.h @@ -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; @@ -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, @@ -346,10 +346,10 @@ 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 @@ -357,7 +357,7 @@ class EBML_DLL_API EbmlSemanticContext { 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; @@ -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); @@ -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); @@ -433,7 +433,7 @@ 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 @@ -441,7 +441,7 @@ class EBML_DLL_API EbmlElement { \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); @@ -449,7 +449,7 @@ class EBML_DLL_API EbmlElement { /*! \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);} @@ -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; } @@ -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}; diff --git a/ebml/EbmlEndian.h b/ebml/EbmlEndian.h index 23c0283f..16807e00 100644 --- a/ebml/EbmlEndian.h +++ b/ebml/EbmlEndian.h @@ -83,7 +83,7 @@ template 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(buffer)) == platform_value;} #if defined(EBML_STRICT_API) @@ -102,7 +102,7 @@ template class Endian #else // _ENDIANESS_ if (ENDIAN == big_endian) #endif // _ENDIANESS_ - std::reverse(reinterpret_cast(&endian_value),reinterpret_cast(&endian_value+1)); + std::reverse(reinterpret_cast(&endian_value),reinterpret_cast(&endian_value+1)); } inline void process_platform() @@ -113,7 +113,7 @@ template class Endian #else // _ENDIANESS_ if (ENDIAN == big_endian) #endif // _ENDIANESS_ - std::reverse(reinterpret_cast(&platform_value),reinterpret_cast(&platform_value+1)); + std::reverse(reinterpret_cast(&platform_value),reinterpret_cast(&platform_value+1)); } }; diff --git a/ebml/EbmlId.h b/ebml/EbmlId.h index 33847c3e..bb736281 100644 --- a/ebml/EbmlId.h +++ b/ebml/EbmlId.h @@ -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 @@ -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 diff --git a/ebml/EbmlMaster.h b/ebml/EbmlMaster.h index 83830e5b..cf3d0d78 100644 --- a/ebml/EbmlMaster.h +++ b/ebml/EbmlMaster.h @@ -76,13 +76,13 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { bool SetSizeInfinite(bool aIsInfinite = true) override {SetSizeIsFinite(!aIsInfinite); return true;} bool PushElement(EbmlElement & element); - uint64 GetSize() const override { + std::uint64_t GetSize() const override { if (IsFiniteSize()) return EbmlElement::GetSize(); return (0-1); } - uint64 GetDataStart() const { + std::uint64_t GetDataStart() const { return GetElementPosition() + EBML_ID_LENGTH((const EbmlId&)*this) + CodedSizeLength(EbmlElement::GetSize(), GetSizeLength(), IsFiniteSize()); } @@ -106,7 +106,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { /*! \brief add an element at a specified location */ - bool InsertElement(EbmlElement & element, size_t position = 0); + bool InsertElement(EbmlElement & element, std::size_t position = 0); bool InsertElement(EbmlElement & element, const EbmlElement & before); /*! @@ -119,7 +119,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { */ void Sort(); - size_t ListSize() const {return ElementList.size();} + std::size_t ListSize() const {return ElementList.size();} std::vector const &GetElementList() const {return ElementList;} std::vector &GetElementList() {return ElementList;} @@ -149,7 +149,7 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { /*! \brief Remove an element from the list of the master */ - void Remove(size_t Index); + void Remove(std::size_t Index); void Remove(EBML_MASTER_ITERATOR & Itr); void Remove(EBML_MASTER_RITERATOR & Itr); @@ -166,8 +166,8 @@ class EBML_DLL_API EbmlMaster : public EbmlElement { void EnableChecksum(bool bIsEnabled = true) { bChecksumUsed = bIsEnabled; } bool HasChecksum() const {return bChecksumUsed;} bool VerifyChecksum() const; - uint32 GetCrc32() const {return Checksum.GetCrc32();} - void ForceChecksum(uint32 NewChecksum) { + std::uint32_t GetCrc32() const {return Checksum.GetCrc32();} + void ForceChecksum(std::uint32_t NewChecksum) { Checksum.ForceCrc32(NewChecksum); bChecksumUsed = true; } diff --git a/ebml/EbmlSInteger.h b/ebml/EbmlSInteger.h index 33731199..7dc8ca9d 100644 --- a/ebml/EbmlSInteger.h +++ b/ebml/EbmlSInteger.h @@ -54,15 +54,15 @@ const int DEFAULT_INT_SIZE = 1; ///< optimal size stored class EBML_DLL_API EbmlSInteger : public EbmlElement { public: EbmlSInteger(); - explicit EbmlSInteger(int64 DefaultValue); + explicit EbmlSInteger(std::int64_t DefaultValue); EbmlSInteger(const EbmlSInteger & ElementToClone) = default; - EbmlSInteger & operator = (int64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;} + EbmlSInteger & operator = (std::int64_t NewValue) {Value = NewValue; SetValueIsSet(); return *this;} /*! Set the default size of the integer (usually 1,2,4 or 8) */ - void SetDefaultSize(uint64 nDefaultSize = DEFAULT_INT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} + void SetDefaultSize(std::uint64_t nDefaultSize = DEFAULT_INT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} bool ValidateSize() const override {return IsFiniteSize() && (GetSize() <= 8);} filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; @@ -71,17 +71,17 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement { bool IsSmallerThan(const EbmlElement *Cmp) const override; - explicit operator int8() const; - explicit operator int16() const; - explicit operator int32() const; - explicit operator int64() const; + explicit operator std::int8_t() const; + explicit operator std::int16_t() const; + explicit operator std::int32_t() const; + explicit operator std::int64_t() const; - EbmlSInteger &SetValue(int64 NewValue); - int64 GetValue() const; + EbmlSInteger &SetValue(std::int64_t NewValue); + std::int64_t GetValue() const; - void SetDefaultValue(int64 aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} + void SetDefaultValue(std::int64_t aValue) {assert(!DefaultISset()); DefaultValue = aValue; SetDefaultIsSet();} - int64 DefaultVal() const {assert(DefaultISset()); return DefaultValue;} + std::int64_t DefaultVal() const {assert(DefaultISset()); return DefaultValue;} bool IsDefaultValue() const override { return (DefaultISset() && Value == DefaultValue); @@ -92,8 +92,8 @@ class EBML_DLL_API EbmlSInteger : public EbmlElement { #else protected: #endif - int64 Value; /// The actual value of the element - int64 DefaultValue; + std::int64_t Value; /// The actual value of the element + std::int64_t DefaultValue; }; } // namespace libebml diff --git a/ebml/EbmlStream.h b/ebml/EbmlStream.h index c79c7fd7..0c919418 100644 --- a/ebml/EbmlStream.h +++ b/ebml/EbmlStream.h @@ -56,9 +56,9 @@ class EBML_DLL_API EbmlStream { \param MaxDataSize The maximum possible of the data in the element (for sanity checks) \note the user will have to delete that element later */ - EbmlElement * FindNextID(const EbmlCallbacks & ClassInfos, uint64 MaxDataSize); + EbmlElement * FindNextID(const EbmlCallbacks & ClassInfos, std::uint64_t MaxDataSize); - EbmlElement * FindNextElement(const EbmlSemanticContext & Context, int & UpperLevel, uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1); + EbmlElement * FindNextElement(const EbmlSemanticContext & Context, int & UpperLevel, std::uint64_t MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel = 1); inline IOCallback & I_O() {return Stream;} operator IOCallback &() {return Stream;} diff --git a/ebml/EbmlTypes.h b/ebml/EbmlTypes.h index f73403a8..ffd9cbc4 100644 --- a/ebml/EbmlTypes.h +++ b/ebml/EbmlTypes.h @@ -33,31 +33,51 @@ #ifndef LIBEBML_TYPES_H #define LIBEBML_TYPES_H -#include "ebml/c/libebml_t.h" +#include + #include "ebml/EbmlConfig.h" + +using int64 = std::int64_t; +using int32 = std::int32_t; +using int16 = std::int16_t; +using int8 = std::int8_t; +using uint64 = std::uint64_t; +using uint32 = std::uint32_t; +using uint16 = std::uint16_t; +using uint8 = std::uint8_t; +using binary = std::uint8_t; +using filepos_t = std::uint64_t; + +enum open_mode { + MODE_READ, + MODE_WRITE, + MODE_CREATE, + MODE_SAFE +}; + #include "EbmlEndian.h" // binary needs to be defined namespace libebml { using utf16 = wchar_t; -using utf32 = uint32; +using utf32 = std::uint32_t; using utf8 = char; using bits80 = binary[10]; -using lil_int16 = Endian; -using lil_int32 = Endian; -using lil_int64 = Endian; -using lil_uint16 = Endian; -using lil_uint32 = Endian; -using lil_uint64 = Endian; -using big_int16 = Endian; -using big_int32 = Endian; -using big_int64 = Endian; -using big_uint16 = Endian; -using big_uint32 = Endian; -using big_uint64 = Endian; -using checksum = Endian; +using lil_int16 = Endian; +using lil_int32 = Endian; +using lil_int64 = Endian; +using lil_uint16 = Endian; +using lil_uint32 = Endian; +using lil_uint64 = Endian; +using big_int16 = Endian; +using big_int32 = Endian; +using big_int64 = Endian; +using big_uint16 = Endian; +using big_uint32 = Endian; +using big_uint64 = Endian; +using checksum = Endian; using big_80bits = Endian; diff --git a/ebml/EbmlUInteger.h b/ebml/EbmlUInteger.h index 80beb532..5f05b11b 100644 --- a/ebml/EbmlUInteger.h +++ b/ebml/EbmlUInteger.h @@ -52,15 +52,15 @@ const int DEFAULT_UINT_SIZE = 0; ///< optimal size stored class EBML_DLL_API EbmlUInteger : public EbmlElement { public: EbmlUInteger(); - explicit EbmlUInteger(uint64 DefaultValue); + explicit EbmlUInteger(std::uint64_t DefaultValue); EbmlUInteger(const EbmlUInteger & ElementToClone) = default; - EbmlUInteger & operator=(uint64 NewValue) {Value = NewValue; SetValueIsSet(); return *this;} + EbmlUInteger & operator=(std::uint64_t NewValue) {Value = NewValue; SetValueIsSet(); return *this;} /*! Set the default size of the integer (usually 1,2,4 or 8) */ - void SetDefaultSize(uint64 nDefaultSize = DEFAULT_UINT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} + void SetDefaultSize(std::uint64_t nDefaultSize = DEFAULT_UINT_SIZE) override {EbmlElement::SetDefaultSize(nDefaultSize); SetSize_(nDefaultSize);} bool ValidateSize() const override {return IsFiniteSize() && (GetSize() <= 8);} filepos_t RenderData(IOCallback & output, bool bForceRender, bool bWithDefault = false) override; @@ -69,17 +69,17 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement { bool IsSmallerThan(const EbmlElement *Cmp) const override; - explicit operator uint8() const; - explicit operator uint16() const; - explicit operator uint32() const; - explicit operator uint64() const; + explicit operator std::uint8_t() const; + explicit operator std::uint16_t() const; + explicit operator std::uint32_t() const; + explicit operator std::uint64_t() const; - EbmlUInteger &SetValue(uint64 NewValue); - uint64 GetValue() const; + EbmlUInteger &SetValue(std::uint64_t NewValue); + std::uint64_t GetValue() const; - void SetDefaultValue(uint64); + void SetDefaultValue(std::uint64_t); - uint64 DefaultVal() const; + std::uint64_t DefaultVal() const; bool IsDefaultValue() const override { return (DefaultISset() && Value == DefaultValue); @@ -90,8 +90,8 @@ class EBML_DLL_API EbmlUInteger : public EbmlElement { #else protected: #endif - uint64 Value; /// The actual value of the element - uint64 DefaultValue; + std::uint64_t Value; /// The actual value of the element + std::uint64_t DefaultValue; }; } // namespace libebml diff --git a/ebml/EbmlUnicodeString.h b/ebml/EbmlUnicodeString.h index 910b9801..28699837 100644 --- a/ebml/EbmlUnicodeString.h +++ b/ebml/EbmlUnicodeString.h @@ -70,7 +70,7 @@ class EBML_DLL_API UTFstring { UTFstring & operator=(wchar_t); /// Return length of string - size_t length() const {return _Length;} + std::size_t length() const {return _Length;} explicit operator const wchar_t*() const; const wchar_t* c_str() const {return _Data;} @@ -83,7 +83,7 @@ class EBML_DLL_API UTFstring { #else protected: #endif - size_t _Length{0}; ///< length of the UCS string excluding the \0 + std::size_t _Length{0}; ///< length of the UCS string excluding the \0 wchar_t* _Data{nullptr}; ///< internal UCS representation std::string UTF8string; static bool wcscmp_internal(const wchar_t *str1, const wchar_t *str2); diff --git a/ebml/EbmlVoid.h b/ebml/EbmlVoid.h index f35957b6..04226997 100644 --- a/ebml/EbmlVoid.h +++ b/ebml/EbmlVoid.h @@ -48,7 +48,7 @@ DECLARE_EBML_BINARY(EbmlVoid) /*! \brief Set the size of the data (not the complete size of the element) */ - void SetSize(uint64 aSize) {SetSize_(aSize);} + void SetSize(std::uint64_t aSize) {SetSize_(aSize);} /*! \note overwrite to write fake data @@ -58,12 +58,12 @@ DECLARE_EBML_BINARY(EbmlVoid) /*! \brief Replace the void element content (written) with this one */ - uint64 ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); + std::uint64_t ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); /*! \brief Void the content of an element */ - uint64 Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); + std::uint64_t Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward = true, bool bWithDefault = false); EBML_CONCRETE_CLASS(EbmlVoid) }; diff --git a/ebml/IOCallback.h b/ebml/IOCallback.h index db8a5629..bef80f1d 100644 --- a/ebml/IOCallback.h +++ b/ebml/IOCallback.h @@ -59,22 +59,22 @@ class EBML_DLL_API IOCallback // file, the buffer and the size and the function returns the bytes read. // If an error occurs or the file pointer points to the end of the file 0 is returned. // Users are encouraged to throw a descriptive exception, when an error occurs. - virtual size_t read(void*Buffer,size_t Size)=0; + virtual std::size_t read(void*Buffer,std::size_t Size)=0; // Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR // or SEEK_END. The callback should return true(1) if the seek operation succeeded // or false (0), when the seek fails. - virtual void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning)=0; + virtual void setFilePointer(std::int64_t Offset,seek_mode Mode=seek_beginning)=0; // This callback just works like its read pendant. It returns the number of bytes written. - virtual size_t write(const void*Buffer,size_t Size)=0; + virtual std::size_t write(const void*Buffer,std::size_t Size)=0; // Although the position is always positive, the return value of this callback is signed to // easily allow negative values for returning errors. When an error occurs, the implementor // should return -1 and the file pointer otherwise. // // If an error occurs, an exception should be thrown. - virtual uint64 getFilePointer()=0; + virtual std::uint64_t getFilePointer()=0; // The close callback flushes the file buffers to disk and closes the file. When using the stdio // library, this is equivalent to calling fclose. When the close is not successful, an exception @@ -85,11 +85,11 @@ class EBML_DLL_API IOCallback // The readFully is made virtual to allow derived classes to use another // implementation for this method, which e.g. does not read any data // unlike this does - void readFully(void*Buffer,size_t Size); + void readFully(void*Buffer,std::size_t Size); template void readStruct(STRUCT&Struct){readFully(&Struct,sizeof(Struct));} - void writeFully(const void*Buffer,size_t Size); + void writeFully(const void*Buffer,std::size_t Size); template void writeStruct(const STRUCT&Struct){writeFully(&Struct,sizeof(Struct));} }; diff --git a/ebml/MemIOCallback.h b/ebml/MemIOCallback.h index 961074b9..43064385 100644 --- a/ebml/MemIOCallback.h +++ b/ebml/MemIOCallback.h @@ -48,25 +48,25 @@ namespace libebml { class EBML_DLL_API MemIOCallback : public IOCallback { public: - explicit MemIOCallback(uint64 DefaultSize = 128); + explicit MemIOCallback(std::uint64_t DefaultSize = 128); ~MemIOCallback() override; /*! Use this to copy some data to the Buffer from this classes data */ - size_t read(void *Buffer, size_t Size) override; + std::size_t read(void *Buffer, std::size_t Size) override; /*! Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR or SEEK_END. The callback should return true(1) if the seek operation succeeded or false (0), when the seek fails. */ - void setFilePointer(int64 Offset, seek_mode Mode=seek_beginning) override; + void setFilePointer(std::int64_t Offset, seek_mode Mode=seek_beginning) override; /*! This callback just works like its read pendant. It returns the number of bytes written. */ - size_t write(const void *Buffer, size_t Size) override; + std::size_t write(const void *Buffer, std::size_t Size) override; /*! Although the position is always positive, the return value of this callback is signed to @@ -75,7 +75,7 @@ class EBML_DLL_API MemIOCallback : public IOCallback If an error occurs, an exception should be thrown. */ - uint64 getFilePointer() override {return dataBufferPos;} + std::uint64_t getFilePointer() override {return dataBufferPos;} /*! The close callback flushes the file buffers to disk and closes the file. When using the stdio @@ -85,12 +85,12 @@ class EBML_DLL_API MemIOCallback : public IOCallback void close() override {} binary *GetDataBuffer() const {return dataBuffer;} - uint64 GetDataBufferSize() const {return dataBufferTotalSize;} - void SetDataBufferSize(uint64 newDataBufferSize) {dataBufferTotalSize = newDataBufferSize;} + std::uint64_t GetDataBufferSize() const {return dataBufferTotalSize;} + void SetDataBufferSize(std::uint64_t newDataBufferSize) {dataBufferTotalSize = newDataBufferSize;} /*! Use this to write some data from another IOCallback */ - uint32 write(IOCallback & IOToRead, size_t Size); + std::uint32_t write(IOCallback & IOToRead, std::size_t Size); bool IsOk() const { return mOk; } const std::string &GetLastErrorStr() { return mLastErrorStr; } @@ -102,15 +102,15 @@ class EBML_DLL_API MemIOCallback : public IOCallback /*! Postion where we start 'writing' to the dataBuffer */ - uint64 dataBufferPos; + std::uint64_t dataBufferPos; /*! Size of the data in the dataBuffer */ - uint64 dataBufferTotalSize; + std::uint64_t dataBufferTotalSize; /*! Size of the memory malloc()/realloc() */ - uint64 dataBufferMemorySize; + std::uint64_t dataBufferMemorySize; }; } // namespace libebml diff --git a/ebml/MemReadIOCallback.h b/ebml/MemReadIOCallback.h index ebb67601..6b101c6a 100644 --- a/ebml/MemReadIOCallback.h +++ b/ebml/MemReadIOCallback.h @@ -40,24 +40,24 @@ namespace libebml { class EBML_DLL_API MemReadIOCallback : public IOCallback { protected: - uint8 const *mStart, *mEnd, *mPtr; + std::uint8_t const *mStart, *mEnd, *mPtr; public: - MemReadIOCallback(void const *Ptr, size_t Size); + MemReadIOCallback(void const *Ptr, std::size_t Size); explicit MemReadIOCallback(EbmlBinary const &Binary); MemReadIOCallback(MemReadIOCallback const &Mem); ~MemReadIOCallback() override = default; - size_t read(void *Buffer, size_t Size) override; - void setFilePointer(int64 Offset, seek_mode Mode = seek_beginning) override; - size_t write(void const *, size_t) override { return 0; } - uint64 getFilePointer() override { return mPtr - mStart; } + std::size_t read(void *Buffer, std::size_t Size) override; + void setFilePointer(std::int64_t Offset, seek_mode Mode = seek_beginning) override; + std::size_t write(void const *, std::size_t) override { return 0; } + std::uint64_t getFilePointer() override { return mPtr - mStart; } void close() override {} binary const *GetDataBuffer() const { return mPtr; } - uint64 GetDataBufferSize() const { return mEnd - mStart; } + std::uint64_t GetDataBufferSize() const { return mEnd - mStart; } protected: - void Init(void const *Ptr, size_t Size); + void Init(void const *Ptr, std::size_t Size); }; } // namespace libebml diff --git a/ebml/SafeReadIOCallback.h b/ebml/SafeReadIOCallback.h index c925393b..e0dab4ab 100644 --- a/ebml/SafeReadIOCallback.h +++ b/ebml/SafeReadIOCallback.h @@ -46,37 +46,37 @@ class EBML_DLL_API SafeReadIOCallback : public std::exception { public: class EBML_DLL_API EndOfStreamX : public std::exception { public: - size_t mMissingBytes; + std::size_t mMissingBytes; explicit EndOfStreamX(std::size_t MissingBytes); }; private: IOCallback *mIO; bool mDeleteIO; - size_t mSize; + std::size_t mSize; public: SafeReadIOCallback(IOCallback *IO, bool DeleteIO); - SafeReadIOCallback(void const *Mem, size_t Size); + SafeReadIOCallback(void const *Mem, std::size_t Size); explicit SafeReadIOCallback(EbmlBinary const &Binary); ~SafeReadIOCallback() override; - size_t GetPosition() const; - size_t GetSize() const; - size_t GetRemainingBytes() const; + std::size_t GetPosition() const; + std::size_t GetSize() const; + std::size_t GetRemainingBytes() const; bool IsEmpty() const; - uint8 GetUInt8(); - uint64 GetUIntBE(size_t NumBytes); - uint16 GetUInt16BE(); - uint32 GetUInt24BE(); - uint32 GetUInt32BE(); - uint64 GetUInt64BE(); + std::uint8_t GetUInt8(); + std::uint64_t GetUIntBE(std::size_t NumBytes); + std::uint16_t GetUInt16BE(); + std::uint32_t GetUInt24BE(); + std::uint32_t GetUInt32BE(); + std::uint64_t GetUInt64BE(); - void Read(void *Dst, size_t Count); + void Read(void *Dst, std::size_t Count); - void Skip(size_t Count); - void Seek(size_t Position); + void Skip(std::size_t Count); + void Seek(std::size_t Position); private: SafeReadIOCallback(SafeReadIOCallback const &) { } diff --git a/ebml/StdIOCallback.h b/ebml/StdIOCallback.h index 771ab8f5..363872f8 100644 --- a/ebml/StdIOCallback.h +++ b/ebml/StdIOCallback.h @@ -66,29 +66,29 @@ class EBML_DLL_API StdIOCallback:public IOCallback { private: FILE*File; - uint64 mCurrentPosition; + std::uint64_t mCurrentPosition; public: // StdIOCallback(const char*Path,const char*Mode); StdIOCallback(const char*Path, open_mode Mode); ~StdIOCallback() noexcept override; - size_t read(void*Buffer,size_t Size) override; + std::size_t read(void*Buffer,std::size_t Size) override; // Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR // or SEEK_END. The callback should return true(1) if the seek operation succeeded // or false (0), when the seek fails. - void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning) override; + void setFilePointer(std::int64_t Offset,seek_mode Mode=seek_beginning) override; // This callback just works like its read pendant. It returns the number of bytes written. - size_t write(const void*Buffer,size_t Size) override; + std::size_t write(const void*Buffer,std::size_t Size) override; // Although the position is always positive, the return value of this callback is signed to // easily allow negative values for returning errors. When an error occurs, the implementor // should return -1 and the file pointer otherwise. // // If an error occurs, an exception should be thrown. - uint64 getFilePointer() override; + std::uint64_t getFilePointer() override; // The close callback flushes the file buffers to disk and closes the file. When using the stdio // library, this is equivalent to calling fclose. When the close is not successful, an exception diff --git a/ebml/c/libebml_t.h b/ebml/c/libebml_t.h deleted file mode 100644 index b124369f..00000000 --- a/ebml/c/libebml_t.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** LIBEBML : parse EBML files, see http://ebml.sourceforge.net/ -** -** -** -** Copyright (C) 2002-2003 Steve Lhomme. All rights reserved. -** -** This file is part of LIBEBML. -** -** This library is free software; you can redistribute it and/or -** modify it under the terms of the GNU Lesser General Public -** License as published by the Free Software Foundation; either -** version 2.1 of the License, or (at your option) any later version. -** -** This library is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -** Lesser General Public License for more details. -** -** You should have received a copy of the GNU Lesser General Public -** License along with this library; if not, write to the Free Software -** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -** -** See http://www.gnu.org/licenses/lgpl-2.1.html for LGPL licensing information. -** -** Contact license@matroska.org if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ - -/*! - \file libebml_t.h - \version \$Id: libebml_t.h 1298 2008-02-21 22:14:18Z mosu $ - \author Steve Lhomme - \author Ingo Ralf Blum - \author Moritz Bunkus - - \brief Misc type definitions for the C API of LIBEBML - - \note These types should be compiler/language independant (just platform dependant) - \todo recover the sized types (uint16, int32, etc) here too (or maybe here only) -*/ - -#ifndef _LIBEBML_T_H_INCLUDED_ -#define _LIBEBML_T_H_INCLUDED_ - -#ifdef __cplusplus -extern "C" { -#endif - -// Changed char is unsigned now (signedness was causing trouble in endil) -#if defined(_WIN32) -# if !defined(__GNUC__) // Microsoft Visual C++ - typedef signed __int64 int64; - typedef signed __int32 int32; - typedef signed __int16 int16; - typedef signed __int8 int8; - typedef __int8 character; - typedef unsigned __int64 uint64; - typedef unsigned __int32 uint32; - typedef unsigned __int16 uint16; - typedef unsigned __int8 uint8; -# else // __GNUC__, this is mingw -# include - typedef int64_t int64; - typedef int32_t int32; - typedef int16_t int16; - typedef int8_t int8; - typedef int8_t character; - typedef uint64_t uint64; - typedef uint32_t uint32; - typedef uint16_t uint16; - typedef uint8_t uint8; -# endif // __GNUC__ -#elif defined(__BEOS__) || defined(__HAIKU__) -#include -#elif defined(DJGPP) /* SL : DJGPP doesn't support POSIX types ???? */ - typedef signed long long int64; - typedef signed long int32; - typedef signed short int16; - typedef signed char int8; - typedef char character; - typedef unsigned long long uint64; - typedef unsigned long uint32; - typedef unsigned short uint16; - typedef unsigned char uint8; -#elif defined(__sun) && (defined(__svr4__) || defined(__SVR4)) // SOLARIS -# include -# ifdef _NO_LONGLONG -# error This compiler does not support 64bit integers. -# endif - typedef int64_t int64; - typedef int32_t int32; - typedef int16_t int16; - typedef int8_t int8; - typedef int8_t character; - typedef uint64_t uint64; - typedef uint32_t uint32; - typedef uint16_t uint16; - typedef uint8_t uint8; -#elif defined(__BEOS__) || defined(__HAIKU__) -# include -#else // anything else (Linux, BSD, ...) -# include -# include - typedef int64_t int64; - typedef int32_t int32; - typedef int16_t int16; - typedef int8_t int8; - typedef int8_t character; - typedef uint64_t uint64; - typedef uint32_t uint32; - typedef uint16_t uint16; - typedef uint8_t uint8; -#endif /* anything else */ - -typedef uint8 binary; -typedef uint64 filepos_t; - -typedef enum open_mode { - MODE_READ, - MODE_WRITE, - MODE_CREATE, - MODE_SAFE -} open_mode; - -#define EBML_MIN(x,y) ((x)<(y) ? (x) : (y)) - -#ifdef __cplusplus -} -#endif - -#endif /* _LIBEBML_T_H_INCLUDED_ */ diff --git a/src/EbmlBinary.cpp b/src/EbmlBinary.cpp index c631105b..fcb4eaa7 100644 --- a/src/EbmlBinary.cpp +++ b/src/EbmlBinary.cpp @@ -88,7 +88,7 @@ filepos_t EbmlBinary::RenderData(IOCallback & output, bool /* bForceRender */, b /*! \note no Default binary value handled */ -uint64 EbmlBinary::UpdateSize(bool /* bWithDefault */, bool /* bForceRender */) +std::uint64_t EbmlBinary::UpdateSize(bool /* bWithDefault */, bool /* bForceRender */) { return GetSize(); } @@ -109,7 +109,7 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully) return 0; } - Data = (GetSize() < std::numeric_limits::max()) ? static_cast(malloc(GetSize())) : nullptr; + Data = (GetSize() < std::numeric_limits::max()) ? static_cast(malloc(GetSize())) : nullptr; if (Data == nullptr) throw CRTError(std::string("Error allocating data")); SetValueIsSet(); diff --git a/src/EbmlCrc32.cpp b/src/EbmlCrc32.cpp index 14f43f4d..75d8e8ea 100644 --- a/src/EbmlCrc32.cpp +++ b/src/EbmlCrc32.cpp @@ -48,13 +48,13 @@ static constexpr uint32_t CRC32_INDEX(uint32_t c) { return c & 0xFF; } static constexpr uint32_t CRC32_SHIFTED(uint32_t c) { return c >> 8; } #endif -static constexpr uint32 CRC32_NEGL = 0xffffffffL; +static constexpr std::uint32_t CRC32_NEGL = 0xffffffffL; namespace libebml { DEFINE_EBML_CLASS_GLOBAL(EbmlCrc32, 0xBF, 1, "EBMLCrc32\0ratamadabapa") -constexpr std::array EbmlCrc32::m_tab { +constexpr std::array EbmlCrc32::m_tab { #ifdef WORDS_BIGENDIAN 0x00000000L, 0x96300777L, 0x2c610eeeL, 0xba510999L, 0x19c46d07L, 0x8ff46a70L, 0x35a563e9L, 0xa395649eL, 0x3288db0eL, 0xa4b8dc79L, @@ -188,11 +188,11 @@ void EbmlCrc32::AddElementCRC32(EbmlElement &ElementToCRC) MemIOCallback memoryBuffer; ElementToCRC.Render(memoryBuffer, true, true); - const uint64 memSize = memoryBuffer.GetDataBufferSize(); - if (memSize > std::numeric_limits::max()) + const std::uint64_t memSize = memoryBuffer.GetDataBufferSize(); + if (memSize > std::numeric_limits::max()) return; - Update(memoryBuffer.GetDataBuffer(), static_cast(memSize)); + Update(memoryBuffer.GetDataBuffer(), static_cast(memSize)); // Finalize(); } @@ -201,11 +201,11 @@ bool EbmlCrc32::CheckElementCRC32(EbmlElement &ElementToCRC) const MemIOCallback memoryBuffer; ElementToCRC.Render(memoryBuffer); - const uint64 memSize = memoryBuffer.GetDataBufferSize(); - if (memSize > std::numeric_limits::max()) + const std::uint64_t memSize = memoryBuffer.GetDataBufferSize(); + if (memSize > std::numeric_limits::max()) return false; - return CheckCRC(m_crc_final, memoryBuffer.GetDataBuffer(), static_cast(memSize)); + return CheckCRC(m_crc_final, memoryBuffer.GetDataBuffer(), static_cast(memSize)); } filepos_t EbmlCrc32::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) @@ -248,15 +248,15 @@ filepos_t EbmlCrc32::ReadData(IOCallback & input, ScopeMode ReadFully) return GetSize(); } -bool EbmlCrc32::CheckCRC(uint32 inputCRC, const binary *input, uint32 length) +bool EbmlCrc32::CheckCRC(std::uint32_t inputCRC, const binary *input, std::uint32_t length) { - uint32 crc = CRC32_NEGL; + std::uint32_t crc = CRC32_NEGL; - for(; !IsAligned(input) && length > 0; length--) + for(; !IsAligned(input) && length > 0; length--) crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); while (length >= 4) { - crc ^= *reinterpret_cast(input); + crc ^= *reinterpret_cast(input); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); @@ -274,20 +274,20 @@ bool EbmlCrc32::CheckCRC(uint32 inputCRC, const binary *input, uint32 length) return crc == inputCRC; } -void EbmlCrc32::FillCRC32(const binary *input, uint32 length) +void EbmlCrc32::FillCRC32(const binary *input, std::uint32_t length) { ResetCRC(); Update(input, length); Finalize(); - /*uint32 crc = CRC32_NEGL; + /*std::uint32_t crc = CRC32_NEGL; - for(; !IsAligned(s) && n > 0; n--) + for(; !IsAligned(s) && n > 0; n--) crc = m_tab.at(CRC32_INDEX(crc) ^ *s++) ^ CRC32_SHIFTED(crc); while (n >= 4) { - crc ^= *(const uint32 *)s; + crc ^= *(const std::uint32_t *)s; crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); @@ -308,15 +308,15 @@ void EbmlCrc32::FillCRC32(const binary *input, uint32 length) } -void EbmlCrc32::Update(const binary *input, uint32 length) +void EbmlCrc32::Update(const binary *input, std::uint32_t length) { - uint32 crc = m_crc; + std::uint32_t crc = m_crc; - for(; !IsAligned(input) && length > 0; length--) + for(; !IsAligned(input) && length > 0; length--) crc = m_tab.at(CRC32_INDEX(crc) ^ *input++) ^ CRC32_SHIFTED(crc); while (length >= 4) { - crc ^= *reinterpret_cast(input); + crc ^= *reinterpret_cast(input); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); crc = m_tab.at(CRC32_INDEX(crc)) ^ CRC32_SHIFTED(crc); diff --git a/src/EbmlElement.cpp b/src/EbmlElement.cpp index b9c4ca84..c6a78739 100644 --- a/src/EbmlElement.cpp +++ b/src/EbmlElement.cpp @@ -52,7 +52,7 @@ namespace libebml { /*! \todo handle more than CodedSize of 5 */ -int CodedSizeLength(uint64 Length, unsigned int SizeLength, bool bSizeIsFinite) +int CodedSizeLength(std::uint64_t Length, unsigned int SizeLength, bool bSizeIsFinite) { unsigned int CodedSize; if (bSizeIsFinite) { @@ -90,7 +90,7 @@ int CodedSizeLength(uint64 Length, unsigned int SizeLength, bool bSizeIsFinite) /*! \todo handle more than CodedSize of 5 */ -int CodedSizeLengthSigned(int64 Length, unsigned int SizeLength) +int CodedSizeLengthSigned(std::int64_t Length, unsigned int SizeLength) { unsigned int CodedSize; // prepare the head of the size (000...01xxxxxx) @@ -113,7 +113,7 @@ int CodedSizeLengthSigned(int64 Length, unsigned int SizeLength) return static_cast(CodedSize); } -int CodedValueLength(uint64 Length, int CodedSize, binary * OutBuffer) +int CodedValueLength(std::uint64_t Length, int CodedSize, binary * OutBuffer) { int _SizeMask = 0xFF; OutBuffer[0] = 1 << (8 - CodedSize); @@ -127,7 +127,7 @@ int CodedValueLength(uint64 Length, int CodedSize, binary * OutBuffer) return CodedSize; } -int CodedValueLengthSigned(int64 Length, int CodedSize, binary * OutBuffer) +int CodedValueLengthSigned(std::int64_t Length, int CodedSize, binary * OutBuffer) { if (Length > -64 && Length < 64) // 2^6 Length += 63; @@ -141,10 +141,10 @@ int CodedValueLengthSigned(int64 Length, int CodedSize, binary * OutBuffer) return CodedValueLength(Length, CodedSize, OutBuffer); } -uint64 ReadCodedSizeValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown) +std::uint64_t ReadCodedSizeValue(const binary * InBuffer, std::uint32_t & BufferSize, std::uint64_t & SizeUnknown) { binary SizeBitMask = 1 << 7; - uint64 Result = 0x7F; + std::uint64_t Result = 0x7F; unsigned int SizeIdx, PossibleSizeLength = 0; std::array PossibleSize = {}; @@ -186,9 +186,9 @@ uint64 ReadCodedSizeValue(const binary * InBuffer, uint32 & BufferSize, uint64 & return 0; } -int64 ReadCodedSizeSignedValue(const binary * InBuffer, uint32 & BufferSize, uint64 & SizeUnknown) +std::int64_t ReadCodedSizeSignedValue(const binary * InBuffer, std::uint32_t & BufferSize, std::uint64_t & SizeUnknown) { - int64 Result = ReadCodedSizeValue(InBuffer, BufferSize, SizeUnknown); + std::int64_t Result = ReadCodedSizeValue(InBuffer, BufferSize, SizeUnknown); if (BufferSize != 0) { switch (BufferSize) { @@ -220,7 +220,7 @@ EbmlCallbacks::EbmlCallbacks(EbmlElement & (*Creator)(), const EbmlId & aGlobalI assert((Create!=nullptr) || !strcmp(aDebugName, "DummyElement")); } -const EbmlSemantic & EbmlSemanticContext::GetSemantic(size_t i) const +const EbmlSemantic & EbmlSemanticContext::GetSemantic(std::size_t i) const { assert(i PossibleId; int PossibleID_Length = 0; std::array PossibleSize; // we don't support size stored in more than 64 bits - uint32 PossibleSizeLength = 0; - uint64 SizeUnknown = 0; - uint64 SizeFound = 0; + std::uint32_t PossibleSizeLength = 0; + std::uint64_t SizeUnknown = 0; + std::uint64_t SizeFound = 0; bool bElementFound = false; binary BitMask; - uint64 aElementPosition = 0, aSizePosition = 0; + std::uint64_t aElementPosition = 0, aSizePosition = 0; while (!bElementFound) { // read ID aElementPosition = DataStream.getFilePointer(); - uint32 ReadSize = 0; + std::uint32_t ReadSize = 0; BitMask = 1 << 7; while (PossibleID_Length < 4) { if (!DataStream.read(&PossibleId.at(PossibleID_Length), 1)) @@ -291,7 +291,7 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac // read the data size aSizePosition = DataStream.getFilePointer(); - uint32 _SizeLength; + std::uint32_t _SizeLength; do { if (PossibleSizeLength >= 8) // Size is larger than 8 bytes @@ -343,19 +343,19 @@ EbmlElement * EbmlElement::FindNextID(IOCallback & DataStream, const EbmlCallbac \param LowLevel Will be returned with the level of the element found compared to the context given */ EbmlElement * EbmlElement::FindNextElement(IOCallback & DataStream, const EbmlSemanticContext & Context, int & UpperLevel, - uint64 MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel) + std::uint64_t MaxDataSize, bool AllowDummyElt, unsigned int MaxLowerLevel) { int PossibleID_Length = 0; std::array PossibleIdNSize; int PossibleSizeLength; - uint64 SizeUnknown; + std::uint64_t SizeUnknown; int ReadIndex = 0; // trick for the algo, start index at 0 - uint32 ReadSize = 0, IdStart = 0; - uint64 SizeFound; + std::uint32_t ReadSize = 0, IdStart = 0; + std::uint64_t SizeFound; int SizeIdx; bool bFound; const int UpperLevel_original = UpperLevel; - const uint64 ParseStart = DataStream.getFilePointer(); + const std::uint64_t ParseStart = DataStream.getFilePointer(); do { // read a potential ID @@ -401,7 +401,7 @@ EbmlElement * EbmlElement::FindNextElement(IOCallback & DataStream, const EbmlSe ReadIndex -= PossibleID_Length; // read the data size - uint32 _SizeLength; + std::uint32_t _SizeLength; PossibleSizeLength = ReadIndex; while (true) { _SizeLength = PossibleSizeLength; @@ -586,12 +586,12 @@ filepos_t EbmlElement::Render(IOCallback & output, bool bWithDefault, bool bKeep return 0; } #if defined(LIBEBML_DEBUG) - uint64 SupposedSize = UpdateSize(bWithDefault, bForceRender); + std::uint64_t SupposedSize = UpdateSize(bWithDefault, bForceRender); #endif // LIBEBML_DEBUG filepos_t result = RenderHead(output, bForceRender, bWithDefault, bKeepPosition); - const uint64 WrittenSize = RenderData(output, bForceRender, bWithDefault); + const std::uint64_t WrittenSize = RenderData(output, bForceRender, bWithDefault); #if defined(LIBEBML_DEBUG) - if (static_cast(SupposedSize) != (0-1)) + if (static_cast(SupposedSize) != (0-1)) assert(WrittenSize == SupposedSize); #endif // LIBEBML_DEBUG result += WrittenSize; @@ -616,7 +616,7 @@ filepos_t EbmlElement::RenderHead(IOCallback & output, bool bForceRender, bool b filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition) { std::array FinalHead; // Class D + 64 bits coded size - size_t FinalHeadSize; + std::size_t FinalHeadSize; FinalHeadSize = EBML_ID_LENGTH((const EbmlId&)*this); EbmlId(*this).Fill(FinalHead.data()); @@ -634,7 +634,7 @@ filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition) return FinalHeadSize; } -uint64 EbmlElement::ElementSize(bool bWithDefault) const +std::uint64_t EbmlElement::ElementSize(bool bWithDefault) const { if (!bWithDefault && IsDefaultValue()) return 0; // won't be saved @@ -659,14 +659,14 @@ void EbmlElement::Read(EbmlStream & inDataStream, const EbmlSemanticContext & /* ReadData(inDataStream.I_O(), ReadFully); } -bool EbmlElement::ForceSize(uint64 NewSize) +bool EbmlElement::ForceSize(std::uint64_t NewSize) { if (bSizeIsFinite) { return false; } const int OldSizeLen = CodedSizeLength(Size, SizeLength, bSizeIsFinite); - const uint64 OldSize = Size; + const std::uint64_t OldSize = Size; Size = NewSize; @@ -685,7 +685,7 @@ filepos_t EbmlElement::OverwriteHead(IOCallback & output, bool bKeepPosition) return 0; // the element has not been written } - const uint64 CurrentPosition = output.getFilePointer(); + const std::uint64_t CurrentPosition = output.getFilePointer(); output.setFilePointer(GetElementPosition()); const filepos_t Result = MakeRenderHead(output, bKeepPosition); output.setFilePointer(CurrentPosition); @@ -712,7 +712,7 @@ filepos_t EbmlElement::OverwriteData(IOCallback & output, bool bKeepPosition) } -uint64 EbmlElement::VoidMe(IOCallback & output, bool bWithDefault) const +std::uint64_t EbmlElement::VoidMe(IOCallback & output, bool bWithDefault) const { if (ElementPosition == 0) { return 0; // the element has not been written diff --git a/src/EbmlFloat.cpp b/src/EbmlFloat.cpp index 44330563..23eb2235 100644 --- a/src/EbmlFloat.cpp +++ b/src/EbmlFloat.cpp @@ -91,7 +91,7 @@ filepos_t EbmlFloat::RenderData(IOCallback & output, bool /* bForceRender */, bo output.writeFully(&TmpToWrite.endian(), GetSize()); } else if (GetSize() == 8) { double val = Value; - int64 Tmp; + std::int64_t Tmp; memcpy(&Tmp, &val, 8); const auto TmpToWrite = big_int64(Tmp); output.writeFully(&TmpToWrite.endian(), GetSize()); @@ -100,7 +100,7 @@ filepos_t EbmlFloat::RenderData(IOCallback & output, bool /* bForceRender */, bo return GetSize(); } -uint64 EbmlFloat::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlFloat::UpdateSize(bool bWithDefault, bool /* bForceRender */) { if (!bWithDefault && IsDefaultValue()) return 0; @@ -128,7 +128,7 @@ filepos_t EbmlFloat::ReadData(IOCallback & input, ScopeMode ReadFully) if (GetSize() == 4) { big_int32 TmpRead; TmpRead.Eval(Buffer); - auto tmpp = static_cast(TmpRead); + auto tmpp = static_cast(TmpRead); float val; memcpy(&val, &tmpp, 4); Value = static_cast(val); @@ -136,7 +136,7 @@ filepos_t EbmlFloat::ReadData(IOCallback & input, ScopeMode ReadFully) } else { big_int64 TmpRead; TmpRead.Eval(Buffer); - auto tmpp = static_cast(TmpRead); + auto tmpp = static_cast(TmpRead); double val; memcpy(&val, &tmpp, 8); Value = val; diff --git a/src/EbmlMaster.cpp b/src/EbmlMaster.cpp index c0689733..87e9b4ae 100644 --- a/src/EbmlMaster.cpp +++ b/src/EbmlMaster.cpp @@ -101,10 +101,10 @@ filepos_t EbmlMaster::RenderData(IOCallback & output, bool bForceRender, bool bW continue; Element->Render(TmpBuf, bWithDefault, false ,bForceRender); } - uint64 memSize = TmpBuf.GetDataBufferSize(); + std::uint64_t memSize = TmpBuf.GetDataBufferSize(); binary *memStart = TmpBuf.GetDataBuffer(); while (memSize != 0) { - const uint32 fillSize = static_cast(std::min(std::numeric_limits::max(), memSize)); + const std::uint32_t fillSize = static_cast(std::min(std::numeric_limits::max(), memSize)); Checksum.FillCRC32(memStart, fillSize); memStart += fillSize; memSize -= fillSize; @@ -126,7 +126,7 @@ bool EbmlMaster::PushElement(EbmlElement & element) return true; } -uint64 EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) +std::uint64_t EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) { SetSize_(0); @@ -141,9 +141,9 @@ uint64 EbmlMaster::UpdateSize(bool bWithDefault, bool bForceRender) if (!bWithDefault && Element->IsDefaultValue()) continue; Element->UpdateSize(bWithDefault, bForceRender); - const uint64 SizeToAdd = Element->ElementSize(bWithDefault); + const std::uint64_t SizeToAdd = Element->ElementSize(bWithDefault); #if defined(LIBEBML_DEBUG) - if (static_cast(SizeToAdd) == (0-1)) + if (static_cast(SizeToAdd) == (0-1)) return (0-1); #endif // LIBEBML_DEBUG SetSize_(GetSize() + SizeToAdd); @@ -382,7 +382,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo } } ElementList.clear(); - uint64 MaxSizeToRead; + std::uint64_t MaxSizeToRead; if (IsFiniteSize()) MaxSizeToRead = GetSize(); @@ -493,7 +493,7 @@ void EbmlMaster::Read(EbmlStream & inDataStream, const EbmlSemanticContext & sCo SetValueIsSet(); } -void EbmlMaster::Remove(size_t Index) +void EbmlMaster::Remove(std::size_t Index) { if (Index < ElementList.size()) { ElementList.erase(ElementList.begin() + Index); @@ -522,10 +522,10 @@ bool EbmlMaster::VerifyChecksum() const for (auto Element : ElementList) { Element->Render(TmpBuf, true, false, true); } - uint64 memSize = TmpBuf.GetDataBufferSize(); + std::uint64_t memSize = TmpBuf.GetDataBufferSize(); binary *memStart = TmpBuf.GetDataBuffer(); while (memSize != 0) { - const uint32 fillSize = static_cast(std::min(std::numeric_limits::max(), memSize)); + const std::uint32_t fillSize = static_cast(std::min(std::numeric_limits::max(), memSize)); aChecksum.FillCRC32(memStart, fillSize); memStart += fillSize; memSize -= fillSize; @@ -534,7 +534,7 @@ bool EbmlMaster::VerifyChecksum() const return (aChecksum.GetCrc32() == Checksum.GetCrc32()); } -bool EbmlMaster::InsertElement(EbmlElement & element, size_t position) +bool EbmlMaster::InsertElement(EbmlElement & element, std::size_t position) { if ((ElementList.empty()) && position) return false; diff --git a/src/EbmlSInteger.cpp b/src/EbmlSInteger.cpp index 4762564e..159a9829 100644 --- a/src/EbmlSInteger.cpp +++ b/src/EbmlSInteger.cpp @@ -45,12 +45,12 @@ namespace { -int64 -ToSigned(uint64 u) { - if (u <= static_cast(std::numeric_limits::max())) - return static_cast(u); +std::int64_t +ToSigned(std::uint64_t u) { + if (u <= static_cast(std::numeric_limits::max())) + return static_cast(u); - return static_cast(u - std::numeric_limits::min()) + std::numeric_limits::min(); + return static_cast(u - std::numeric_limits::min()) + std::numeric_limits::min(); } } // namespace @@ -61,20 +61,20 @@ EbmlSInteger::EbmlSInteger() :EbmlElement(DEFAULT_INT_SIZE, false) {} -EbmlSInteger::EbmlSInteger(int64 aDefaultValue) +EbmlSInteger::EbmlSInteger(std::int64_t aDefaultValue) :EbmlElement(DEFAULT_INT_SIZE, true), Value(aDefaultValue) { SetDefaultIsSet(); } -EbmlSInteger::operator int8() const {return static_cast(Value);} -EbmlSInteger::operator int16() const {return static_cast(Value);} -EbmlSInteger::operator int32() const {return static_cast(Value);} -EbmlSInteger::operator int64() const {return Value;} +EbmlSInteger::operator std::int8_t() const {return static_cast(Value);} +EbmlSInteger::operator std::int16_t() const {return static_cast(Value);} +EbmlSInteger::operator std::int32_t() const {return static_cast(Value);} +EbmlSInteger::operator std::int64_t() const {return Value;} -int64 EbmlSInteger::GetValue() const {return Value;} +std::int64_t EbmlSInteger::GetValue() const {return Value;} -EbmlSInteger & EbmlSInteger::SetValue(int64 NewValue) { +EbmlSInteger & EbmlSInteger::SetValue(std::int64_t NewValue) { return *this = NewValue; } @@ -89,7 +89,7 @@ filepos_t EbmlSInteger::RenderData(IOCallback & output, bool /* bForceRender */, if (GetSizeLength() > 8) return 0; // integer bigger coded on more than 64 bits are not supported - int64 TempValue = Value; + std::int64_t TempValue = Value; for (i=0; i(TempValue & 0xFF); TempValue >>= 8; @@ -100,7 +100,7 @@ filepos_t EbmlSInteger::RenderData(IOCallback & output, bool /* bForceRender */, return GetSize(); } -uint64 EbmlSInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlSInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) { if (!bWithDefault && IsDefaultValue()) return 0; @@ -147,7 +147,7 @@ filepos_t EbmlSInteger::ReadData(IOCallback & input, ScopeMode ReadFully) std::array Buffer; input.readFully(Buffer.data(), GetSize()); - uint64 TempValue = Buffer[0] & 0x80 ? std::numeric_limits::max() : 0; + std::uint64_t TempValue = Buffer[0] & 0x80 ? std::numeric_limits::max() : 0; for (unsigned int i=0; i(Value); } -EbmlUInteger::operator uint16() const {return static_cast(Value);} -EbmlUInteger::operator uint32() const {return static_cast(Value);} -EbmlUInteger::operator uint64() const {return Value;} +EbmlUInteger::operator std::uint8_t() const {return static_cast(Value); } +EbmlUInteger::operator std::uint16_t() const {return static_cast(Value);} +EbmlUInteger::operator std::uint32_t() const {return static_cast(Value);} +EbmlUInteger::operator std::uint64_t() const {return Value;} -uint64 EbmlUInteger::GetValue() const {return Value;} +std::uint64_t EbmlUInteger::GetValue() const {return Value;} -EbmlUInteger & EbmlUInteger::SetValue(uint64 NewValue) { +EbmlUInteger & EbmlUInteger::SetValue(std::uint64_t NewValue) { return *this = NewValue; } @@ -85,7 +85,7 @@ filepos_t EbmlUInteger::RenderData(IOCallback & output, bool /* bForceRender */, if (GetSizeLength() > 8) return 0; // integer bigger coded on more than 64 bits are not supported - uint64 TempValue = Value; + std::uint64_t TempValue = Value; for (unsigned int i=0; i>= 8; @@ -96,7 +96,7 @@ filepos_t EbmlUInteger::RenderData(IOCallback & output, bool /* bForceRender */, return GetSize(); } -uint64 EbmlUInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlUInteger::UpdateSize(bool bWithDefault, bool /* bForceRender */) { if (!bWithDefault && IsDefaultValue()) return 0; diff --git a/src/EbmlUnicodeString.cpp b/src/EbmlUnicodeString.cpp index b242a260..5aef8b5c 100644 --- a/src/EbmlUnicodeString.cpp +++ b/src/EbmlUnicodeString.cpp @@ -85,7 +85,7 @@ UTFstring & UTFstring::operator=(const wchar_t * _aBuf) return *this; } - size_t aLen; + std::size_t aLen; for (aLen=0; _aBuf[aLen] != 0; aLen++); _Length = aLen; _Data = new wchar_t[_Length+1]; @@ -160,7 +160,7 @@ void UTFstring::UpdateFromUCS2() return; // Only convert up to the first \0 character if present. - size_t Current = 0; + std::size_t Current = 0; while ((Current < _Length) && _Data[Current]) ++Current; @@ -180,7 +180,7 @@ void UTFstring::UpdateFromUCS2() bool UTFstring::wcscmp_internal(const wchar_t *str1, const wchar_t *str2) { - size_t Index=0; + std::size_t Index=0; while (str1[Index] == str2[Index] && str1[Index] != 0) { Index++; } @@ -222,7 +222,7 @@ const UTFstring & EbmlUnicodeString::DefaultVal() const */ filepos_t EbmlUnicodeString::RenderData(IOCallback & output, bool /* bForceRender */, bool /* bWithDefault */) { - size_t Result = Value.GetUTF8().length(); + std::size_t Result = Value.GetUTF8().length(); if (Result != 0) { output.writeFully(Value.GetUTF8().c_str(), Result); @@ -273,7 +273,7 @@ std::string EbmlUnicodeString::GetValueUTF8() const { /*! \note limited to UCS-2 */ -uint64 EbmlUnicodeString::UpdateSize(bool bWithDefault, bool /* bForceRender */) +std::uint64_t EbmlUnicodeString::UpdateSize(bool bWithDefault, bool /* bForceRender */) { if (!bWithDefault && IsDefaultValue()) return 0; diff --git a/src/EbmlVoid.cpp b/src/EbmlVoid.cpp index d8587c1b..bb4854f3 100644 --- a/src/EbmlVoid.cpp +++ b/src/EbmlVoid.cpp @@ -50,7 +50,7 @@ filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, boo // write dummy data by 4KB chunks static binary DummyBuf[4*1024]; - uint64 SizeToWrite = GetSize(); + std::uint64_t SizeToWrite = GetSize(); while (SizeToWrite > 4*1024) { output.writeFully(DummyBuf, 4*1024); SizeToWrite -= 4*1024; @@ -59,7 +59,7 @@ filepos_t EbmlVoid::RenderData(IOCallback & output, bool /* bForceRender */, boo return GetSize(); } -uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) +std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) { EltToReplaceWith.UpdateSize(bWithDefault); if (HeadSize() + GetSize() < EltToReplaceWith.GetSize() + EltToReplaceWith.HeadSize()) { @@ -71,7 +71,7 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output return INVALID_FILEPOS_T; } - const uint64 CurrentPosition = output.getFilePointer(); + const std::uint64_t CurrentPosition = output.getFilePointer(); output.setFilePointer(GetElementPosition()); EltToReplaceWith.Render(output, bWithDefault); @@ -80,9 +80,9 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output // fill the rest with another void element EbmlVoid aTmp; aTmp.SetSize_(HeadSize() + GetSize() - EltToReplaceWith.GetSize() - EltToReplaceWith.HeadSize() - 1); // 1 is the length of the Void ID - const size_t HeadBefore = aTmp.HeadSize(); + const std::size_t HeadBefore = aTmp.HeadSize(); aTmp.SetSize_(aTmp.GetSize() - CodedSizeLength(aTmp.GetSize(), aTmp.GetSizeLength(), aTmp.IsFiniteSize())); - const size_t HeadAfter = aTmp.HeadSize(); + const std::size_t HeadAfter = aTmp.HeadSize(); if (HeadBefore != HeadAfter) { aTmp.SetSizeLength(CodedSizeLength(aTmp.GetSize(), aTmp.GetSizeLength(), aTmp.IsFiniteSize()) - (HeadAfter - HeadBefore)); } @@ -96,7 +96,7 @@ uint64 EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback & output return GetSize() + HeadSize(); } -uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) +std::uint64_t EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, bool ComeBackAfterward, bool bWithDefault) { // EltToVoid.UpdateSize(bWithDefault); if (EltToVoid.GetElementPosition() == 0) { @@ -108,7 +108,7 @@ uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, b return 0; } - const uint64 CurrentPosition = output.getFilePointer(); + const std::uint64_t CurrentPosition = output.getFilePointer(); output.setFilePointer(EltToVoid.GetElementPosition()); @@ -116,8 +116,8 @@ uint64 EbmlVoid::Overwrite(const EbmlElement & EltToVoid, IOCallback & output, b SetSize(EltToVoid.GetSize() + EltToVoid.HeadSize() - 1); // 1 for the ID SetSize(GetSize() - CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize())); // make sure we handle even the strange cases - //uint32 A1 = GetSize() + HeadSize(); - //uint32 A2 = EltToVoid.GetSize() + EltToVoid.HeadSize(); + //std::uint32_t A1 = GetSize() + HeadSize(); + //std::uint32_t A2 = EltToVoid.GetSize() + EltToVoid.HeadSize(); if (GetSize() + HeadSize() != EltToVoid.GetSize() + EltToVoid.HeadSize()) { SetSize(GetSize()-1); SetSizeLength(CodedSizeLength(GetSize(), GetSizeLength(), IsFiniteSize()) + 1); diff --git a/src/IOCallback.cpp b/src/IOCallback.cpp index 4fbaeeee..49f4912b 100644 --- a/src/IOCallback.cpp +++ b/src/IOCallback.cpp @@ -43,7 +43,7 @@ using namespace std; namespace libebml { -void IOCallback::writeFully(const void*Buffer,size_t Size) +void IOCallback::writeFully(const void*Buffer,std::size_t Size) { if (Size == 0) return; @@ -60,13 +60,13 @@ void IOCallback::writeFully(const void*Buffer,size_t Size) -void IOCallback::readFully(void*Buffer,size_t Size) +void IOCallback::readFully(void*Buffer,std::size_t Size) { if(Buffer == nullptr) throw; char *readBuf = static_cast(Buffer); - uint32_t readSize = static_cast(std::min(std::numeric_limits::max(), Size)); + uint32_t readSize = static_cast(std::min(std::numeric_limits::max(), Size)); while (readSize != 0) { if(read(readBuf,readSize) != readSize) { stringstream Msg; @@ -75,7 +75,7 @@ void IOCallback::readFully(void*Buffer,size_t Size) } Size -= readSize; readBuf += readSize; - readSize = static_cast(std::min(std::numeric_limits::max(), Size)); + readSize = static_cast(std::min(std::numeric_limits::max(), Size)); } } diff --git a/src/MemIOCallback.cpp b/src/MemIOCallback.cpp index 65c9058b..f76493aa 100644 --- a/src/MemIOCallback.cpp +++ b/src/MemIOCallback.cpp @@ -38,7 +38,7 @@ namespace libebml { -MemIOCallback::MemIOCallback(uint64 DefaultSize) +MemIOCallback::MemIOCallback(std::uint64_t DefaultSize) { //The default size of the buffer is 128 bytes dataBuffer = static_cast(malloc(DefaultSize)); @@ -63,7 +63,7 @@ MemIOCallback::~MemIOCallback() free(dataBuffer); } -size_t MemIOCallback::read(void *Buffer, size_t Size) +std::size_t MemIOCallback::read(void *Buffer, std::size_t Size) { if (Buffer == nullptr || Size < 1) return 0; @@ -71,7 +71,7 @@ size_t MemIOCallback::read(void *Buffer, size_t Size) if (Size + dataBufferPos > dataBufferTotalSize) { //We will only return the remaining data memcpy(Buffer, dataBuffer + dataBufferPos, dataBufferTotalSize - dataBufferPos); - const uint64 oldDataPos = dataBufferPos; + const std::uint64_t oldDataPos = dataBufferPos; dataBufferPos = dataBufferTotalSize; return dataBufferTotalSize - oldDataPos; } @@ -83,7 +83,7 @@ size_t MemIOCallback::read(void *Buffer, size_t Size) return Size; } -void MemIOCallback::setFilePointer(int64 Offset, seek_mode Mode) +void MemIOCallback::setFilePointer(std::int64_t Offset, seek_mode Mode) { if (Mode == seek_beginning) dataBufferPos = Offset; @@ -93,7 +93,7 @@ void MemIOCallback::setFilePointer(int64 Offset, seek_mode Mode) dataBufferPos = dataBufferTotalSize + Offset; } -size_t MemIOCallback::write(const void *Buffer, size_t Size) +std::size_t MemIOCallback::write(const void *Buffer, std::size_t Size) { if (dataBufferMemorySize < dataBufferPos + Size) { //We need more memory! @@ -107,7 +107,7 @@ size_t MemIOCallback::write(const void *Buffer, size_t Size) return Size; } -uint32 MemIOCallback::write(IOCallback & IOToRead, size_t Size) +std::uint32_t MemIOCallback::write(IOCallback & IOToRead, std::size_t Size) { if (dataBufferMemorySize < dataBufferPos + Size) { //We need more memory! diff --git a/src/MemReadIOCallback.cpp b/src/MemReadIOCallback.cpp index 9526ed4e..b130c216 100644 --- a/src/MemReadIOCallback.cpp +++ b/src/MemReadIOCallback.cpp @@ -42,7 +42,7 @@ namespace libebml { MemReadIOCallback::MemReadIOCallback(void const *Ptr, - size_t Size) { + std::size_t Size) { Init(Ptr, Size); } @@ -56,16 +56,16 @@ MemReadIOCallback::MemReadIOCallback(MemReadIOCallback const &Mem) { void MemReadIOCallback::Init(void const *Ptr, - size_t Size) { - mStart = reinterpret_cast(Ptr); + std::size_t Size) { + mStart = reinterpret_cast(Ptr); mEnd = mStart + Size; mPtr = mStart; } -size_t +std::size_t MemReadIOCallback::read(void *Buffer, - size_t Size) { - const size_t RemainingBytes = mEnd - mPtr; + std::size_t Size) { + const std::size_t RemainingBytes = mEnd - mPtr; if (RemainingBytes < Size) Size = RemainingBytes; @@ -76,13 +76,13 @@ MemReadIOCallback::read(void *Buffer, } void -MemReadIOCallback::setFilePointer(int64 Offset, +MemReadIOCallback::setFilePointer(std::int64_t Offset, seek_mode Mode) { - int64 NewPosition = Mode == seek_beginning ? Offset - : Mode == seek_end ? static_cast(mEnd - mStart) + Offset - : static_cast(mPtr - mStart) + Offset; + std::int64_t NewPosition = Mode == seek_beginning ? Offset + : Mode == seek_end ? static_cast(mEnd - mStart) + Offset + : static_cast(mPtr - mStart) + Offset; - NewPosition = std::min(std::max(NewPosition, 0), mEnd - mStart); + NewPosition = std::min(std::max(NewPosition, 0), mEnd - mStart); mPtr = mStart + NewPosition; } diff --git a/src/SafeReadIOCallback.cpp b/src/SafeReadIOCallback.cpp index facdc134..876f8b0f 100644 --- a/src/SafeReadIOCallback.cpp +++ b/src/SafeReadIOCallback.cpp @@ -42,7 +42,7 @@ namespace libebml { -SafeReadIOCallback::EndOfStreamX::EndOfStreamX(size_t MissingBytes) +SafeReadIOCallback::EndOfStreamX::EndOfStreamX(std::size_t MissingBytes) : mMissingBytes(MissingBytes) { } @@ -55,7 +55,7 @@ SafeReadIOCallback::SafeReadIOCallback(IOCallback *IO, } SafeReadIOCallback::SafeReadIOCallback(void const *Mem, - size_t Size) { + std::size_t Size) { Init(new MemReadIOCallback(Mem, Size), true); } @@ -73,25 +73,25 @@ SafeReadIOCallback::Init(IOCallback *IO, bool DeleteIO) { mIO = IO; mDeleteIO = DeleteIO; - const int64 PrevPosition = IO->getFilePointer(); + const std::int64_t PrevPosition = IO->getFilePointer(); IO->setFilePointer(0, seek_end); mSize = IO->getFilePointer(); IO->setFilePointer(PrevPosition); } -size_t +std::size_t SafeReadIOCallback::GetPosition() const { return mIO->getFilePointer(); } -size_t +std::size_t SafeReadIOCallback::GetSize() const { return mSize; } -size_t +std::size_t SafeReadIOCallback::GetRemainingBytes() const { return GetSize() - GetPosition(); @@ -103,70 +103,70 @@ SafeReadIOCallback::IsEmpty() return !GetRemainingBytes(); } -uint64 -SafeReadIOCallback::GetUIntBE(size_t NumBytes) { - uint8 Buffer[8]; +std::uint64_t +SafeReadIOCallback::GetUIntBE(std::size_t NumBytes) { + std::uint8_t Buffer[8]; - NumBytes = std::min(std::max(1, NumBytes), 8); - uint64 Value = 0; - uint8* Ptr = &Buffer[0]; + NumBytes = std::min(std::max(1, NumBytes), 8); + std::uint64_t Value = 0; + std::uint8_t* Ptr = &Buffer[0]; Read(Buffer, NumBytes); - for (size_t i = 0; NumBytes > i; ++i, ++Ptr) + for (std::size_t i = 0; NumBytes > i; ++i, ++Ptr) Value = (Value << 8) + *Ptr; return Value; } -uint8 +std::uint8_t SafeReadIOCallback::GetUInt8() { - return static_cast(GetUIntBE(1)); + return static_cast(GetUIntBE(1)); } -uint16 +std::uint16_t SafeReadIOCallback::GetUInt16BE() { - return static_cast(GetUIntBE(2)); + return static_cast(GetUIntBE(2)); } -uint32 +std::uint32_t SafeReadIOCallback::GetUInt24BE() { - return static_cast(GetUIntBE(3)); + return static_cast(GetUIntBE(3)); } -uint32 +std::uint32_t SafeReadIOCallback::GetUInt32BE() { - return static_cast(GetUIntBE(4)); + return static_cast(GetUIntBE(4)); } -uint64 +std::uint64_t SafeReadIOCallback::GetUInt64BE() { return GetUIntBE(8); } void -SafeReadIOCallback::Skip(size_t Count) { - const int64 PrevPosition = mIO->getFilePointer(); - const int64 ExpectedPosition = PrevPosition + Count; +SafeReadIOCallback::Skip(std::size_t Count) { + const std::int64_t PrevPosition = mIO->getFilePointer(); + const std::int64_t ExpectedPosition = PrevPosition + Count; mIO->setFilePointer(Count, seek_current); - const int64 ActualPosition = mIO->getFilePointer(); + const std::int64_t ActualPosition = mIO->getFilePointer(); if (ActualPosition != ExpectedPosition) throw SafeReadIOCallback::EndOfStreamX(ExpectedPosition - ActualPosition); } void -SafeReadIOCallback::Seek(size_t Position) { +SafeReadIOCallback::Seek(std::size_t Position) { mIO->setFilePointer(Position); - const uint64 ActualPosition = mIO->getFilePointer(); + const std::uint64_t ActualPosition = mIO->getFilePointer(); if (ActualPosition != Position) throw EndOfStreamX(ActualPosition - Position); } void SafeReadIOCallback::Read(void *Dst, - size_t Count) { - const uint64 NumRead = mIO->read(Dst, Count); + std::size_t Count) { + const std::uint64_t NumRead = mIO->read(Dst, Count); if (NumRead != Count) throw SafeReadIOCallback::EndOfStreamX(Count - NumRead); } diff --git a/src/StdIOCallback.cpp b/src/StdIOCallback.cpp index dfc53407..e3c7a5d8 100644 --- a/src/StdIOCallback.cpp +++ b/src/StdIOCallback.cpp @@ -97,16 +97,16 @@ StdIOCallback::~StdIOCallback() noexcept -size_t StdIOCallback::read(void*Buffer,size_t Size) +std::size_t StdIOCallback::read(void*Buffer,std::size_t Size) { assert(File!=nullptr); - const size_t result = fread(Buffer, 1, Size, File); + const std::size_t result = fread(Buffer, 1, Size, File); mCurrentPosition += result; return result; } -void StdIOCallback::setFilePointer(int64 Offset,seek_mode Mode) +void StdIOCallback::setFilePointer(std::int64_t Offset,seek_mode Mode) { assert(File!=nullptr); @@ -134,15 +134,15 @@ void StdIOCallback::setFilePointer(int64 Offset,seek_mode Mode) } } -size_t StdIOCallback::write(const void*Buffer,size_t Size) +std::size_t StdIOCallback::write(const void*Buffer,std::size_t Size) { assert(File!=nullptr); - const uint32 Result = fwrite(Buffer,1,Size,File); + const std::uint32_t Result = fwrite(Buffer,1,Size,File); mCurrentPosition += Result; return Result; } -uint64 StdIOCallback::getFilePointer() +std::uint64_t StdIOCallback::getFilePointer() { assert(File!=nullptr); diff --git a/src/platform/win32/WinIOCallback.cpp b/src/platform/win32/WinIOCallback.cpp index 9bb979df..21130e1b 100644 --- a/src/platform/win32/WinIOCallback.cpp +++ b/src/platform/win32/WinIOCallback.cpp @@ -203,7 +203,7 @@ void WinIOCallback::close() } } -uint64 WinIOCallback::getFilePointer() +std::uint64_t WinIOCallback::getFilePointer() { if (!mFile) { return 0; @@ -214,12 +214,12 @@ uint64 WinIOCallback::getFilePointer() LONG High = 0; DWORD Low = SetFilePointer(mFile, 0, &High, FILE_CURRENT); if ( (Low==INVALID_SET_FILE_POINTER) && (GetLastError()!=NO_ERROR) ) - return static_cast(-1); - return ((uint64(High)<<32) | Low); + return static_cast(-1); + return ((std::uint64_t(High)<<32) | Low); #endif } -void WinIOCallback::setFilePointer(int64 Offset, seek_mode Mode) +void WinIOCallback::setFilePointer(std::int64_t Offset, seek_mode Mode) { DWORD Method; switch(Mode) { @@ -242,13 +242,13 @@ void WinIOCallback::setFilePointer(int64 Offset, seek_mode Mode) if ( mCurrentPosition == INVALID_SET_FILE_POINTER ) { High = 0; DWORD Low = SetFilePointer(mFile, 0, &High, FILE_CURRENT); - mCurrentPosition = ((uint64(High)<<32) | Low); + mCurrentPosition = ((std::uint64_t(High)<<32) | Low); } else { - mCurrentPosition |= uint64(High)<<32; + mCurrentPosition |= std::uint64_t(High)<<32; } } -uint32 WinIOCallback::read(void*Buffer,size_t Size) +std::uint32_t WinIOCallback::read(void*Buffer,std::size_t Size) { DWORD BytesRead; if (!ReadFile(mFile, Buffer, Size, &BytesRead, NULL)) { @@ -258,7 +258,7 @@ uint32 WinIOCallback::read(void*Buffer,size_t Size) return BytesRead; } -size_t WinIOCallback::write(const void*Buffer,size_t Size) +std::size_t WinIOCallback::write(const void*Buffer,std::size_t Size) { DWORD BytesWriten; if (!WriteFile(mFile, Buffer, Size, &BytesWriten, NULL)) { diff --git a/src/platform/win32/WinIOCallback.h b/src/platform/win32/WinIOCallback.h index 349405e8..de52664a 100644 --- a/src/platform/win32/WinIOCallback.h +++ b/src/platform/win32/WinIOCallback.h @@ -53,10 +53,10 @@ class WinIOCallback: public IOCallback bool open(const wchar_t* Path, const open_mode Mode, DWORD dwFlags=0); bool open(const char* Path, const open_mode Mode, DWORD dwFlags=0); - virtual uint32 read(void*Buffer,size_t Size); - virtual size_t write(const void*Buffer,size_t Size); - virtual void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning); - virtual uint64 getFilePointer(); + virtual std::uint32_t read(void*Buffer,std::size_t Size); + virtual std::size_t write(const void*Buffer,std::size_t Size); + virtual void setFilePointer(std::int64_t Offset,seek_mode Mode=seek_beginning); + virtual std::uint64_t getFilePointer(); virtual void close(); bool IsOk() { return mOk; }; @@ -65,7 +65,7 @@ class WinIOCallback: public IOCallback protected: bool mOk; std::string mLastErrorStr; - uint64 mCurrentPosition; + std::uint64_t mCurrentPosition; HANDLE mFile; };