Skip to content

Commit

Permalink
use std::size_t instead of size_t
Browse files Browse the repository at this point in the history
They are supposed to be the same but it's more C++ friendly.
  • Loading branch information
robUx4 committed Oct 15, 2022
1 parent 827f0f7 commit 701f7b2
Show file tree
Hide file tree
Showing 22 changed files with 77 additions and 77 deletions.
10 changes: 5 additions & 5 deletions ebml/EbmlElement.h
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion 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 Down
4 changes: 2 additions & 2 deletions ebml/EbmlId.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ class EBML_DLL_API EbmlId {
}
}

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

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

} // namespace libebml
Expand Down
6 changes: 3 additions & 3 deletions ebml/EbmlMaster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*!
Expand All @@ -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<EbmlElement *> const &GetElementList() const {return ElementList;}
std::vector<EbmlElement *> &GetElementList() {return ElementList;}

Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions ebml/EbmlUnicodeString.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;}
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions ebml/IOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ 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(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
Expand All @@ -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<class STRUCT> 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<class STRUCT> void writeStruct(const STRUCT&Struct){writeFully(&Struct,sizeof(Struct));}
};
Expand Down
6 changes: 3 additions & 3 deletions ebml/MemIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class EBML_DLL_API MemIOCallback : public IOCallback
/*!
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
Expand All @@ -66,7 +66,7 @@ class EBML_DLL_API MemIOCallback : public IOCallback
/*!
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
Expand All @@ -90,7 +90,7 @@ class EBML_DLL_API MemIOCallback : public IOCallback
/*!
Use this to write some data from another IOCallback
*/
std::uint32_t 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; }
Expand Down
8 changes: 4 additions & 4 deletions ebml/MemReadIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ class EBML_DLL_API MemReadIOCallback : public IOCallback {
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;
std::size_t read(void *Buffer, std::size_t Size) override;
void setFilePointer(std::int64_t Offset, seek_mode Mode = seek_beginning) override;
size_t write(void const *, size_t) override { return 0; }
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; }
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
Expand Down
20 changes: 10 additions & 10 deletions ebml/SafeReadIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

std::uint8_t GetUInt8();
std::uint64_t GetUIntBE(size_t NumBytes);
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 &) { }
Expand Down
4 changes: 2 additions & 2 deletions ebml/StdIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ class EBML_DLL_API StdIOCallback:public IOCallback
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(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
Expand Down
2 changes: 1 addition & 1 deletion src/EbmlBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)
return 0;
}

Data = (GetSize() < std::numeric_limits<size_t>::max()) ? static_cast<binary *>(malloc(GetSize())) : nullptr;
Data = (GetSize() < std::numeric_limits<std::size_t>::max()) ? static_cast<binary *>(malloc(GetSize())) : nullptr;
if (Data == nullptr)
throw CRTError(std::string("Error allocating data"));
SetValueIsSet();
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Size);
if (i<Size)
Expand Down Expand Up @@ -616,7 +616,7 @@ filepos_t EbmlElement::RenderHead(IOCallback & output, bool bForceRender, bool b
filepos_t EbmlElement::MakeRenderHead(IOCallback & output, bool bKeepPosition)
{
std::array<binary, 4 + 8> 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());
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/EbmlUnicodeString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand All @@ -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++;
}
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlVoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ std::uint64_t EbmlVoid::ReplaceWith(EbmlElement & EltToReplaceWith, IOCallback &
// 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));
}
Expand Down
8 changes: 4 additions & 4 deletions src/IOCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<char *>(Buffer);
uint32_t readSize = static_cast<uint32_t>(std::min<size_t>(std::numeric_limits<std::uint32_t>::max(), Size));
uint32_t readSize = static_cast<uint32_t>(std::min<std::size_t>(std::numeric_limits<std::uint32_t>::max(), Size));
while (readSize != 0) {
if(read(readBuf,readSize) != readSize) {
stringstream Msg;
Expand All @@ -75,7 +75,7 @@ void IOCallback::readFully(void*Buffer,size_t Size)
}
Size -= readSize;
readBuf += readSize;
readSize = static_cast<uint32_t>(std::min<size_t>(std::numeric_limits<std::uint32_t>::max(), Size));
readSize = static_cast<uint32_t>(std::min<std::size_t>(std::numeric_limits<std::uint32_t>::max(), Size));
}
}

Expand Down
Loading

0 comments on commit 701f7b2

Please sign in to comment.