Skip to content

Commit

Permalink
reSharper: method fuctions can be made 'const'
Browse files Browse the repository at this point in the history
  • Loading branch information
jcdr428 committed Aug 9, 2023
1 parent 0007d79 commit 159484d
Show file tree
Hide file tree
Showing 84 changed files with 544 additions and 543 deletions.
4 changes: 2 additions & 2 deletions libmediation/fs/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ class File : public AbstractOutputStream
\param whence
\return Location of the cursor after relocating it, or uint64_t(-1) in case of an error.
*/
uint64_t seek(int64_t offset, SeekMethod whence = SeekMethod::smBegin);
uint64_t seek(int64_t offset, SeekMethod whence = SeekMethod::smBegin) const;

//! Change the size of the file
/*!
The location of the file cursor after calling this function is undefined.
\param newFileSize New size of the file. This function can both enlarge, as well as reduce the file size.
*/
bool truncate(uint64_t newFileSize);
bool truncate(uint64_t newFileSize) const;

std::string getName() { return m_name; }

Expand Down
4 changes: 2 additions & 2 deletions libmediation/fs/osdep/directory_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ uint64_t getFileSize(const std::string& fileName)
}
}

bool createDir(const std::string& dirName, bool createParentDirs)
bool createDir(const std::string& dirName, const bool createParentDirs)
{
const bool ok = preCreateDir(
[](auto&& parentDir) {
Expand Down Expand Up @@ -73,7 +73,7 @@ bool deleteFile(const string& fileName)
return DeleteFile(toWide(fileName).data()) != 0;
}

bool findFiles(const string& path, const string& fileMask, vector<string>* fileList, bool savePaths)
bool findFiles(const string& path, const string& fileMask, vector<string>* fileList, const bool savePaths)
{
WIN32_FIND_DATA fileData; // Data structure describes the file found
// Search handle returned by FindFirstFile
Expand Down
14 changes: 7 additions & 7 deletions libmediation/fs/osdep/file_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void throwFileError()
throw std::runtime_error(str);
}

void makeWin32OpenFlags(unsigned int oflag, DWORD* const dwDesiredAccess, DWORD* const dwCreationDisposition,
void makeWin32OpenFlags(const unsigned int oflag, DWORD* const dwDesiredAccess, DWORD* const dwCreationDisposition,
DWORD* const dwShareMode)
{
*dwDesiredAccess = 0;
Expand Down Expand Up @@ -47,7 +47,7 @@ void makeWin32OpenFlags(unsigned int oflag, DWORD* const dwDesiredAccess, DWORD*

File::File() : AbstractOutputStream(), m_impl(INVALID_HANDLE_VALUE), m_name(""), m_pos(0) {}

File::File(const char* fName, unsigned int oflag, unsigned int systemDependentFlags) /* throw ( std::runtime_error ) */
File::File(const char* fName, const unsigned int oflag, unsigned int systemDependentFlags) /* throw ( std::runtime_error ) */
: AbstractOutputStream(), m_impl(INVALID_HANDLE_VALUE), m_name(fName), m_pos(0)
{
DWORD dwDesiredAccess = 0;
Expand Down Expand Up @@ -85,7 +85,7 @@ File::~File()
close();
}

bool File::open(const char* fName, unsigned int oflag, unsigned int systemDependentFlags)
bool File::open(const char* fName, const unsigned int oflag, unsigned int systemDependentFlags)
{
m_name = fName;
m_pos = 0;
Expand Down Expand Up @@ -134,7 +134,7 @@ bool File::close()
return res != 0;
}

int File::read(void* buffer, uint32_t count) const
int File::read(void* buffer, const uint32_t count) const
{
if (!isOpen())
return -1;
Expand All @@ -149,7 +149,7 @@ int File::read(void* buffer, uint32_t count) const
return (int)bytesRead;
}

int File::write(const void* buffer, uint32_t count)
int File::write(const void* buffer, const uint32_t count)
{
if (!isOpen())
return -1;
Expand Down Expand Up @@ -184,7 +184,7 @@ bool File::size(uint64_t* const fileSize) const
return true;
}

uint64_t File::seek(int64_t offset, SeekMethod whence)
uint64_t File::seek(const int64_t offset, const SeekMethod whence) const
{
if (!isOpen())
return (uint64_t)-1;
Expand Down Expand Up @@ -215,7 +215,7 @@ uint64_t File::seek(int64_t offset, SeekMethod whence)
return m_pos;
}

bool File::truncate(uint64_t newFileSize)
bool File::truncate(const uint64_t newFileSize) const
{
const LONG distanceToMoveLow = (uint32_t)(newFileSize & 0xffffffff);
LONG distanceToMoveHigh = (uint32_t)((newFileSize & 0xffffffff00000000ull) >> 32);
Expand Down
30 changes: 15 additions & 15 deletions libmediation/types/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ int32_t strToInt32(const char* const str) { return strtol(str, nullptr, 10); }

int32_t strToInt32(const std::string& str) { return strToInt32(str.c_str()); }

int32_t strToInt32(const char* const str, int radix) { return strtol(str, nullptr, radix); }
int32_t strToInt32(const char* const str, const int radix) { return strtol(str, nullptr, radix); }

uint32_t strToInt32u(const char* const str, int radix) { return static_cast<uint32_t>(strtoul(str, nullptr, radix)); }
uint32_t strToInt32u(const char* const str, const int radix) { return static_cast<uint32_t>(strtoul(str, nullptr, radix)); }

int16_t strToInt16(const char* const str) { return (int16_t)strtol(str, nullptr, 10); }

Expand Down Expand Up @@ -148,7 +148,7 @@ string int32uToHex(const uint32_t& x)
return str.str();
}

string doubleToStr(const double& x, int precision)
string doubleToStr(const double& x, const int precision)
{
std::ostringstream str;
if (precision > 0)
Expand Down Expand Up @@ -207,15 +207,15 @@ uint64_t roundUp64(const uint64_t& value, const uint64_t& roundVal)
return roundVal ? ((value + roundVal - 1) / roundVal) * roundVal : 0;
}

string strPadLeft(const string& str, size_t newSize, char filler)
string strPadLeft(const string& str, const size_t newSize, const char filler)
{
const int cnt = (int)(newSize - str.size());
string prefix = "";
for (int i = 0; i < cnt; i++) prefix += filler;
return prefix + str;
}

string strPadRight(const string& str, size_t newSize, char filler)
string strPadRight(const string& str, const size_t newSize, const char filler)
{
const int cnt = (int)(newSize - str.size());
string postfix = "";
Expand Down Expand Up @@ -244,7 +244,7 @@ bool strStartWith(const string& str, const string& substr)
return true;
}

vector<string> splitStr(const char* str, char splitter)
vector<string> splitStr(const char* str, const char splitter)
{
vector<string> rez;
const char* prevPos = str;
Expand Down Expand Up @@ -285,7 +285,7 @@ vector<string> splitStr(const string& str, const string& splitter)
return res;
}

void splitStr(vector<string>& rez, const char* str, char splitter)
void splitStr(vector<string>& rez, const char* str, const char splitter)
{
rez.clear();
const char* prevPos = str;
Expand Down Expand Up @@ -336,7 +336,7 @@ string extractFileName(const string& src)
return "";
}

string extractFileName2(const string& src, bool withExt)
string extractFileName2(const string& src, const bool withExt)
{
string fileName = src;

Expand Down Expand Up @@ -400,7 +400,7 @@ string trimStr(const string& value)
return value.substr(chBeg - bufStart, chEnd - chBeg + 1);
}

vector<string> splitQuotedStr(const char* str, char splitter)
vector<string> splitQuotedStr(const char* str, const char splitter)
{
vector<string> rez;
const char* prevPos = str;
Expand Down Expand Up @@ -439,19 +439,19 @@ string strToLowerCase(const string& src)
return res;
}

uint32_t my_ntohl(const uint32_t val)
uint32_t my_ntohl(uint32_t val)
{
const auto* tmp = (uint8_t*)&val;
return tmp[3] + (tmp[2] << 8) + (tmp[1] << 16) + (tmp[0] << 24);
}

uint16_t my_ntohs(const uint16_t val)
uint16_t my_ntohs(uint16_t val)
{
const auto* tmp = (uint8_t*)&val;
return tmp[1] + (tmp[0] << 8);
}

char* strnstr(const char* s1, const char* s2, size_t len)
char* strnstr(char* s1, const char* s2, const size_t len)
{
size_t l1 = len;
const size_t l2 = strlen(s2);
Expand Down Expand Up @@ -480,7 +480,7 @@ uint32_t random32()

namespace
{
std::vector<wchar_t> mbtwc_wrapper(int codePage, const char* inputStr, int inputSize, int outputSize)
std::vector<wchar_t> mbtwc_wrapper(const int codePage, const char* inputStr, const int inputSize, const int outputSize)
{
std::vector<wchar_t> multiByteBuf(static_cast<std::size_t>(outputSize));
MultiByteToWideChar(codePage, 0, inputStr, inputSize, multiByteBuf.data(), outputSize);
Expand All @@ -492,15 +492,15 @@ std::vector<wchar_t> mbtwc_wrapper(int codePage, const char* inputStr, int input
}
} // namespace

std::vector<wchar_t> fromAcp(const char* acpStr, int sz)
std::vector<wchar_t> fromAcp(const char* acpStr, const int sz)
{
const auto requiredSiz = MultiByteToWideChar(CP_ACP, 0, acpStr, sz, nullptr, 0);
return mbtwc_wrapper(CP_ACP, acpStr, sz, requiredSiz);
}

std::vector<wchar_t> toWide(const std::string& utf8Str) { return toWide(utf8Str.c_str(), (int)utf8Str.size()); }

std::vector<wchar_t> toWide(const char* utf8Str, int sz)
std::vector<wchar_t> toWide(const char* utf8Str, const int sz)
{
const auto requiredSiz = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, utf8Str, sz, nullptr, 0);
if (requiredSiz != 0)
Expand Down
4 changes: 2 additions & 2 deletions tsMuxer/aac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool AACCodec::decodeFrame(uint8_t* buffer, uint8_t* end)
}
}

void AACCodec::buildADTSHeader(uint8_t* buffer, int frameSize)
void AACCodec::buildADTSHeader(uint8_t* buffer, const int frameSize)
{
BitStreamWriter writer{};
writer.setBuffer(buffer, buffer + AAC_HEADER_LEN);
Expand Down Expand Up @@ -111,7 +111,7 @@ void AACCodec::buildADTSHeader(uint8_t* buffer, int frameSize)
writer.flushBits();
}

void AACCodec::readConfig(uint8_t* buff, int size)
void AACCodec::readConfig(uint8_t* buff, const int size)
{
BitStreamReader reader{};
reader.setBuffer(buff, buff + size);
Expand Down
2 changes: 1 addition & 1 deletion tsMuxer/abstractMuxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AbstractMuxer::AbstractMuxer(MuxerManager* owner) : m_owner(owner)
m_fileFactory = nullptr;
}

void AbstractMuxer::setBlockMuxMode(int blockSize, int sectorSize)
void AbstractMuxer::setBlockMuxMode(const int blockSize, const int sectorSize)
{
m_interliaveBlockSize = blockSize;
m_sectorSize = sectorSize;
Expand Down
8 changes: 4 additions & 4 deletions tsMuxer/ac3Codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const CodecInfo &AC3Codec::getCodecInfo()
}

// returns true if ok, or false if error
bool AC3Codec::crc32(uint8_t *buf, int length)
bool AC3Codec::crc32(uint8_t *buf, const int length)
{
const uint8_t *end = buf + length;

Expand Down Expand Up @@ -416,7 +416,7 @@ int AC3Codec::decodeFrame(uint8_t *buf, uint8_t *end, int &skipBytes)
}
}

AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end)
AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end) const
{
BitStreamReader gbc{};
gbc.setBuffer(buf, buf + 7);
Expand Down Expand Up @@ -489,12 +489,12 @@ AC3Codec::AC3ParseError AC3Codec::testParseHeader(uint8_t *buf, uint8_t *end)
return AC3ParseError::NO_ERROR;
}

bool AC3Codec::testDecodeTestFrame(uint8_t *buf, uint8_t *end)
bool AC3Codec::testDecodeTestFrame(uint8_t *buf, uint8_t *end) const
{
return testParseHeader(buf, end) == AC3ParseError::NO_ERROR;
}

uint64_t AC3Codec::getFrameDuration()
uint64_t AC3Codec::getFrameDuration() const
{
// EAC3 dependent frame : wait for next independent frame
if (!m_bit_rate && m_strmtyp == 1)
Expand Down
6 changes: 3 additions & 3 deletions tsMuxer/ac3Codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AC3Codec
protected:
int decodeFrame(uint8_t* buff, uint8_t* end, int& skipBytes);
static uint8_t* findFrame(uint8_t* buff, uint8_t* end);
uint64_t getFrameDuration();
uint64_t getFrameDuration() const;
const CodecInfo& getCodecInfo();
const std::string getStreamInfo();

Expand Down Expand Up @@ -102,8 +102,8 @@ class AC3Codec
static bool crc32(uint8_t* buf, int length);
AC3ParseError parseHeader(uint8_t* buf, uint8_t* end);

AC3ParseError testParseHeader(uint8_t* buf, uint8_t* end);
bool testDecodeTestFrame(uint8_t* buf, uint8_t* end);
AC3ParseError testParseHeader(uint8_t* buf, uint8_t* end) const;
bool testDecodeTestFrame(uint8_t* buf, uint8_t* end) const;

protected:
bool m_testMode;
Expand Down
6 changes: 3 additions & 3 deletions tsMuxer/bitStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <cstdint>

void updateBits(const BitStreamReader& bitReader, int bitOffset, int bitLen, int value)
void updateBits(const BitStreamReader& bitReader, const int bitOffset, const int bitLen, const int value)
{
updateBits(bitReader.getBuffer(), bitOffset, bitLen, value);
}

void updateBits(const uint8_t* buffer, int bitOffset, int bitLen, int value)
void updateBits(uint8_t* buffer, const int bitOffset, const int bitLen, const int value)
{
uint8_t* ptr = (uint8_t*)buffer + bitOffset / 8;
BitStreamWriter bitWriter{};
Expand All @@ -32,7 +32,7 @@ void updateBits(const uint8_t* buffer, int bitOffset, int bitLen, int value)
bitWriter.flushBits();
}

void moveBits(uint8_t* buffer, int oldBitOffset, int newBitOffset, int len)
void moveBits(uint8_t* buffer, const int oldBitOffset, const int newBitOffset, int len)
{
uint8_t* src = (uint8_t*)buffer + (oldBitOffset >> 3);
BitStreamReader reader{};
Expand Down
6 changes: 3 additions & 3 deletions tsMuxer/bitStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ class BitStreamWriter : public BitStream
unsigned m_bitWrited;
};

void updateBits(const BitStreamReader& bitReader, int bitOffset, int bitLen, int value);
void updateBits(const uint8_t* buffer, int bitOffset, int bitLen, int value);
void updateBits(const BitStreamReader& bitReader, const int bitOffset, const int bitLen, const int value);
void updateBits(uint8_t* buffer, const int bitOffset, const int bitLen, const int value);

// move len bits from oldBitOffset position to newBitOffset
void moveBits(uint8_t* buffer, int oldBitOffset, int newBitOffset, int len);
void moveBits(uint8_t* buffer, const int oldBitOffset, const int newBitOffset, const int len);

#endif
Loading

0 comments on commit 159484d

Please sign in to comment.