General: Make member functions const where applicable

These functions don't modify instance state, so they can be marked
const.
This commit is contained in:
Lioncash 2019-08-16 02:06:51 -04:00 committed by Phillip Stephens
parent 1822b555fa
commit 80c1103b44
7 changed files with 27 additions and 28 deletions

View File

@ -54,18 +54,18 @@ public:
bool sendUSBInterruptTransfer(const uint8_t* data, size_t length);
size_t receiveUSBInterruptTransfer(uint8_t* data, size_t length);
inline unsigned getVendorId();
inline unsigned getProductId();
inline std::string_view getVendorName();
inline std::string_view getProductName();
inline unsigned getVendorId() const;
inline unsigned getProductId() const;
inline std::string_view getVendorName() const;
inline std::string_view getProductName() const;
/* High-Level API */
#if _WIN32
#if !WINDOWS_STORE
const PHIDP_PREPARSED_DATA getReportDescriptor();
PHIDP_PREPARSED_DATA getReportDescriptor() const;
#endif
#else
std::vector<uint8_t> getReportDescriptor();
std::vector<uint8_t> getReportDescriptor() const;
#endif
bool sendHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message = 0);
size_t receiveHIDReport(uint8_t* data, size_t length, HIDReportType tp,

View File

@ -41,11 +41,8 @@ private:
/* Friend methods for platform-listener to find/insert/remove
* tokens with type-filtering */
bool _hasToken(const std::string& path) {
auto preCheck = m_tokens.find(path);
if (preCheck != m_tokens.end())
return true;
return false;
bool _hasToken(const std::string& path) const {
return m_tokens.find(path) != m_tokens.end();
}
bool _insertToken(std::unique_ptr<DeviceToken>&& token) {
if (DeviceSignature::DeviceMatchToken(*token, m_types)) {
@ -77,8 +74,12 @@ public:
public:
CDeviceTokensHandle(DeviceFinder& finder) : m_finder(finder) { m_finder.m_tokensLock.lock(); }
~CDeviceTokensHandle() { m_finder.m_tokensLock.unlock(); }
TDeviceTokens::iterator begin() { return m_finder.m_tokens.begin(); }
TDeviceTokens::iterator end() { return m_finder.m_tokens.end(); }
TDeviceTokens::iterator begin() noexcept { return m_finder.m_tokens.begin(); }
TDeviceTokens::iterator end() noexcept { return m_finder.m_tokens.end(); }
TDeviceTokens::const_iterator begin() const noexcept { return m_finder.m_tokens.begin(); }
TDeviceTokens::const_iterator end() const noexcept { return m_finder.m_tokens.end(); }
};
/* Application must specify its interested device-types */

View File

@ -136,7 +136,7 @@ public:
void stopRumble(int motor) { m_rumbleRequest &= ~EDualshockMotor(motor); }
EDualshockLED getLED() { return m_led; }
EDualshockLED getLED() const { return m_led; }
void setLED(EDualshockLED led, bool on = true) {
if (on)

View File

@ -23,8 +23,8 @@ struct NintendoPowerAState {
uint8_t leftY;
uint8_t rightX;
uint8_t rightY;
bool operator==(const NintendoPowerAState& other);
bool operator!=(const NintendoPowerAState& other);
bool operator==(const NintendoPowerAState& other) const;
bool operator!=(const NintendoPowerAState& other) const;
};
class NintendoPowerA;

View File

@ -249,7 +249,7 @@ public:
m_backcv.wait(lk, [this]() { return m_outstandingTasks == 0 || !m_running; });
}
bool isReady() {
bool isReady() const {
return m_outstandingTasks == 0 || !m_running;
}

View File

@ -37,25 +37,25 @@ size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length) {
return false;
}
unsigned DeviceBase::getVendorId() {
unsigned DeviceBase::getVendorId() const {
if (m_token)
return m_token->getVendorId();
return -1;
}
unsigned DeviceBase::getProductId() {
unsigned DeviceBase::getProductId() const {
if (m_token)
return m_token->getProductId();
return -1;
}
std::string_view DeviceBase::getVendorName() {
std::string_view DeviceBase::getVendorName() const {
if (m_token)
return m_token->getVendorName();
return {};
}
std::string_view DeviceBase::getProductName() {
std::string_view DeviceBase::getProductName() const {
if (m_token)
return m_token->getProductName();
return {};
@ -63,14 +63,14 @@ std::string_view DeviceBase::getProductName() {
#if _WIN32
#if !WINDOWS_STORE
const PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() {
PHIDP_PREPARSED_DATA DeviceBase::getReportDescriptor() const {
if (m_hidDev)
return m_hidDev->_getReportDescriptor();
return {};
}
#endif
#else
std::vector<uint8_t> DeviceBase::getReportDescriptor() {
std::vector<uint8_t> DeviceBase::getReportDescriptor() const {
if (m_hidDev)
return m_hidDev->_getReportDescriptor();
return {};

View File

@ -33,12 +33,10 @@ void NintendoPowerA::finalCycle() {}
void NintendoPowerA::receivedHIDReport(const uint8_t* data, size_t length, HIDReportType tp, uint32_t message) {}
bool NintendoPowerAState::operator==(const NintendoPowerAState& other) {
return !memcmp(this, &other, sizeof(NintendoPowerAState));
bool NintendoPowerAState::operator==(const NintendoPowerAState& other) const {
return memcmp(this, &other, sizeof(NintendoPowerAState)) == 0;
}
bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) {
return memcmp(this, &other, sizeof(NintendoPowerAState));
}
bool NintendoPowerAState::operator!=(const NintendoPowerAState& other) const { return !operator==(other); }
} // namespace boo