summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-09-14 14:36:05 +0200
committerSven Gothel <[email protected]>2020-09-14 14:36:05 +0200
commitbbc1f5c6f6c40dfa5d40abd802426828dd531124 (patch)
tree98c9e5ce77a41df63e2a42815df5e0a79e57c416 /api
parent5085f539fb987960acd62729bd00396955d56d33 (diff)
C++ IndexOutOfBoundsException: Add variant for just index + length
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/BasicTypes.hpp15
-rw-r--r--api/direct_bt/DBTManager.hpp2
2 files changed, 10 insertions, 7 deletions
diff --git a/api/direct_bt/BasicTypes.hpp b/api/direct_bt/BasicTypes.hpp
index e75a8112..2bc9330d 100644
--- a/api/direct_bt/BasicTypes.hpp
+++ b/api/direct_bt/BasicTypes.hpp
@@ -99,6 +99,9 @@ namespace direct_bt {
class IndexOutOfBoundsException : public RuntimeException {
public:
+ IndexOutOfBoundsException(const int index, const int length, const char* file, int line) noexcept
+ : RuntimeException("IndexOutOfBoundsException", "Index "+std::to_string(index)+", data length "+std::to_string(length), file, line) {}
+
IndexOutOfBoundsException(const int index, const int count, const int length, const char* file, int line) noexcept
: RuntimeException("IndexOutOfBoundsException", "Index "+std::to_string(index)+", count "+std::to_string(count)+", data length "+std::to_string(length), file, line) {}
};
@@ -311,37 +314,37 @@ namespace direct_bt {
inline void set_bit_uint32(const uint8_t nr, uint32_t &mask)
{
- if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); }
+ if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); }
mask |= 1 << (nr & 31);
}
inline void clear_bit_uint32(const uint8_t nr, uint32_t &mask)
{
- if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); }
+ if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); }
mask |= ~(1 << (nr & 31));
}
inline uint32_t test_bit_uint32(const uint8_t nr, const uint32_t mask)
{
- if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, 32, E_FILE_LINE); }
+ if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); }
return mask & (1 << (nr & 31));
}
inline void set_bit_uint64(const uint8_t nr, uint64_t &mask)
{
- if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); }
+ if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); }
mask |= 1 << (nr & 63);
}
inline void clear_bit_uint64(const uint8_t nr, uint64_t &mask)
{
- if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); }
+ if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); }
mask |= ~(1 << (nr & 63));
}
inline uint64_t test_bit_uint64(const uint8_t nr, const uint64_t mask)
{
- if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, 64, E_FILE_LINE); }
+ if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); }
return mask & (1 << (nr & 63));
}
diff --git a/api/direct_bt/DBTManager.hpp b/api/direct_bt/DBTManager.hpp
index 6cb9e4b3..e6123d46 100644
--- a/api/direct_bt/DBTManager.hpp
+++ b/api/direct_bt/DBTManager.hpp
@@ -168,7 +168,7 @@ namespace direct_bt {
std::recursive_mutex mtx_callbackLists;
inline void checkMgmtEventCallbackListsIndex(const MgmtEvent::Opcode opc) const {
if( static_cast<uint16_t>(opc) >= mgmtAdapterEventCallbackLists.size() ) {
- throw IndexOutOfBoundsException(static_cast<uint16_t>(opc), 1, mgmtAdapterEventCallbackLists.size(), E_FILE_LINE);
+ throw IndexOutOfBoundsException(static_cast<uint16_t>(opc), mgmtAdapterEventCallbackLists.size(), E_FILE_LINE);
}
}