mirror of
https://github.com/espressif/openthread.git
synced 2026-09-16 14:10:09 +00:00
[ncp] conform with c++11 constexpr and static_assert (#4416)
C++11 constexpr doesn't support local variables and loop. This commit uses recursive way to assert handlers are sorted. C++11 static_assert requires a message. This commit adds the missing messages to static_assert calls.
This commit is contained in:
@@ -213,7 +213,7 @@ protected:
|
|||||||
otError HandleCommand(uint8_t aHeader);
|
otError HandleCommand(uint8_t aHeader);
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
static constexpr bool IsHandlerEntriesSorted(const HandlerEntry *aHandlerEntries, size_t aSize);
|
static constexpr bool AreHandlerEntriesSorted(const HandlerEntry *aHandlerEntries, size_t aSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static PropertyHandler FindPropertyHandler(const HandlerEntry *aHandlerEntries,
|
static PropertyHandler FindPropertyHandler(const HandlerEntry *aHandlerEntries,
|
||||||
|
|||||||
@@ -36,19 +36,11 @@ namespace ot {
|
|||||||
namespace Ncp {
|
namespace Ncp {
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
constexpr bool NcpBase::IsHandlerEntriesSorted(const HandlerEntry *aHandlerEntries, size_t aSize)
|
constexpr bool NcpBase::AreHandlerEntriesSorted(const HandlerEntry *aHandlerEntries, size_t aSize)
|
||||||
{
|
{
|
||||||
bool rval = true;
|
return aSize < 2 ? true
|
||||||
|
: ((aHandlerEntries[aSize - 1].mKey > aHandlerEntries[aSize - 2].mKey) &&
|
||||||
for (size_t i = 1; i < aSize; ++i)
|
AreHandlerEntriesSorted(aHandlerEntries, aSize - 1));
|
||||||
{
|
|
||||||
if (aHandlerEntries[i].mKey <= aHandlerEntries[i - 1].mKey)
|
|
||||||
{
|
|
||||||
rval = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rval;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -352,7 +344,8 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
static_assert(IsHandlerEntriesSorted(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries)));
|
static_assert(AreHandlerEntriesSorted(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries)),
|
||||||
|
"NCP property getter entries not sorted!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return FindPropertyHandler(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries), aKey);
|
return FindPropertyHandler(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries), aKey);
|
||||||
@@ -568,7 +561,8 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey)
|
|||||||
};
|
};
|
||||||
|
|
||||||
#if __cplusplus >= 201103L
|
#if __cplusplus >= 201103L
|
||||||
static_assert(IsHandlerEntriesSorted(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries)));
|
static_assert(AreHandlerEntriesSorted(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries)),
|
||||||
|
"NCP property setter entries not sorted!");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return FindPropertyHandler(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries), aKey);
|
return FindPropertyHandler(sHandlerEntries, OT_ARRAY_LENGTH(sHandlerEntries), aKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user