mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 09:57:47 +00:00
[common] replace enum constants with constexpr (#6845)
This commit replaces the `enum` constants with `constexpr` definitions in all the modules under `core/common`. It also adds type to the names `enum` definitions.
This commit is contained in:
committed by
Jonathan Hui
parent
e8b085e09c
commit
a5a6fba922
@@ -47,7 +47,7 @@ namespace ot {
|
||||
class Crc16
|
||||
{
|
||||
public:
|
||||
enum Polynomial
|
||||
enum Polynomial : uint16_t
|
||||
{
|
||||
kCcitt = 0x1021, ///< CRC16_CCITT
|
||||
kAnsi = 0x8005, ///< CRC16-ANSI
|
||||
|
||||
@@ -226,11 +226,8 @@ exit:
|
||||
}
|
||||
#endif
|
||||
|
||||
enum : uint8_t
|
||||
{
|
||||
kStringLineLength = 80,
|
||||
kDumpBytesPerLine = 16,
|
||||
};
|
||||
static constexpr uint8_t kStringLineLength = 80;
|
||||
static constexpr uint8_t kDumpBytesPerLine = 16;
|
||||
|
||||
static void DumpLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const uint8_t *aBytes, const size_t aLength)
|
||||
{
|
||||
@@ -279,10 +276,7 @@ static void DumpLine(otLogLevel aLogLevel, otLogRegion aLogRegion, const uint8_t
|
||||
|
||||
void otDump(otLogLevel aLogLevel, otLogRegion aLogRegion, const char *aId, const void *aBuf, const size_t aLength)
|
||||
{
|
||||
enum : uint8_t
|
||||
{
|
||||
kWidth = 72,
|
||||
};
|
||||
constexpr uint8_t kWidth = 72;
|
||||
|
||||
size_t idLen = strlen(aId);
|
||||
ot::String<kStringLineLength> string;
|
||||
|
||||
+10
-19
@@ -134,11 +134,8 @@ class HmacSha256;
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
enum
|
||||
{
|
||||
kNumBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS,
|
||||
kBufferSize = OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE,
|
||||
};
|
||||
constexpr uint16_t kNumBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
|
||||
constexpr uint16_t kBufferSize = OPENTHREAD_CONFIG_MESSAGE_BUFFER_SIZE;
|
||||
|
||||
class Message;
|
||||
class MessagePool;
|
||||
@@ -285,11 +282,8 @@ private:
|
||||
*/
|
||||
const uint8_t *GetData(void) const { return mBuffer.mData; }
|
||||
|
||||
enum
|
||||
{
|
||||
kBufferDataSize = kBufferSize - sizeof(otMessageBuffer),
|
||||
kHeadBufferDataSize = kBufferDataSize - sizeof(MessageMetadata),
|
||||
};
|
||||
static constexpr uint16_t kBufferDataSize = kBufferSize - sizeof(otMessageBuffer);
|
||||
static constexpr uint16_t kHeadBufferDataSize = kBufferDataSize - sizeof(MessageMetadata);
|
||||
|
||||
protected:
|
||||
union
|
||||
@@ -321,7 +315,7 @@ public:
|
||||
* This enumeration represents the message type.
|
||||
*
|
||||
*/
|
||||
enum Type
|
||||
enum Type : uint8_t
|
||||
{
|
||||
kTypeIp6 = 0, ///< A full uncompressed IPv6 packet
|
||||
kType6lowpan = 1, ///< A 6lowpan frame
|
||||
@@ -334,7 +328,7 @@ public:
|
||||
* This enumeration represents the message sub-type.
|
||||
*
|
||||
*/
|
||||
enum SubType
|
||||
enum SubType : uint8_t
|
||||
{
|
||||
kSubTypeNone = 0, ///< None
|
||||
kSubTypeMleAnnounce = 1, ///< MLE Announce
|
||||
@@ -349,7 +343,7 @@ public:
|
||||
kSubTypeMleChildIdRequest = 10, ///< MLE Child ID Request
|
||||
};
|
||||
|
||||
enum Priority
|
||||
enum Priority : uint8_t
|
||||
{
|
||||
kPriorityLow = OT_MESSAGE_PRIORITY_LOW, ///< Low priority level.
|
||||
kPriorityNormal = OT_MESSAGE_PRIORITY_NORMAL, ///< Normal priority level.
|
||||
@@ -357,16 +351,13 @@ public:
|
||||
kPriorityNet = OT_MESSAGE_PRIORITY_HIGH + 1, ///< Network Control priority level.
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
kNumPriorities = 4, ///< Number of priority levels.
|
||||
};
|
||||
static constexpr uint8_t kNumPriorities = 4; ///< Number of priority levels.
|
||||
|
||||
/**
|
||||
* This enumeration represents the link security mode (used by `Settings` constructor).
|
||||
*
|
||||
*/
|
||||
enum LinkSecurityMode
|
||||
enum LinkSecurityMode : uint8_t
|
||||
{
|
||||
kNoLinkSecurity, ///< Link security disabled (no link security).
|
||||
kWithLinkSecurity, ///< Link security enabled.
|
||||
@@ -1400,7 +1391,7 @@ public:
|
||||
* should be added in the queue.
|
||||
*
|
||||
*/
|
||||
enum QueuePosition
|
||||
enum QueuePosition : uint8_t
|
||||
{
|
||||
kQueuePositionHead, ///< Indicates the head (front) of the list.
|
||||
kQueuePositionTail, ///< Indicates the tail (end) of the list.
|
||||
|
||||
@@ -297,13 +297,15 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kMaxExternalHandlers = OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS,
|
||||
kFlagsStringLineLimit = 70, // Character limit to divide the log into multiple lines in `LogChangedFlags()`.
|
||||
kMaxFlagNameLength = 25, // Max length for string representation of a flag by `FlagToString()`.
|
||||
kFlagsStringBufferSize = kFlagsStringLineLimit + kMaxFlagNameLength,
|
||||
};
|
||||
static constexpr uint16_t kMaxExternalHandlers = OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS;
|
||||
|
||||
// Character limit to divide the log into multiple lines in `LogChangedFlags()`.
|
||||
static constexpr uint16_t kFlagsStringLineLimit = 70;
|
||||
|
||||
// Max length for string representation of a flag by `FlagToString()`.
|
||||
static constexpr uint8_t kMaxFlagNameLength = 25;
|
||||
|
||||
static constexpr uint16_t kFlagsStringBufferSize = kFlagsStringLineLimit + kMaxFlagNameLength;
|
||||
|
||||
struct ExternalCallback
|
||||
{
|
||||
|
||||
@@ -1062,7 +1062,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
enum IteratorType
|
||||
enum IteratorType : uint8_t
|
||||
{
|
||||
kEndIterator,
|
||||
};
|
||||
|
||||
@@ -249,10 +249,7 @@ public:
|
||||
static uint32_t MsecToSec(uint32_t aMilliseconds) { return aMilliseconds / 1000u; }
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
kDistantFuture = (1UL << 31),
|
||||
};
|
||||
static constexpr uint32_t kDistantFuture = (1UL << 31);
|
||||
|
||||
uint32_t mValue;
|
||||
};
|
||||
|
||||
@@ -109,11 +109,8 @@ public:
|
||||
bool IsReceiverRegistered(Receiver aReceiver) const { return (mReceivers & Mask(aReceiver)) != 0; }
|
||||
|
||||
private:
|
||||
enum : uint32_t
|
||||
{
|
||||
kTickInterval = 1000, // in msec.
|
||||
kRestartJitter = 4, // in msec, jitter added when restarting the timer [-4,+4] ms.
|
||||
};
|
||||
static constexpr uint32_t kTickInterval = 1000; // in msec.
|
||||
static constexpr uint32_t kRestartJitter = 4; // in msec, jitter added when restarting the timer [-4,+4] ms.
|
||||
|
||||
constexpr static uint32_t Mask(Receiver aReceiver) { return static_cast<uint32_t>(1U) << aReceiver; }
|
||||
|
||||
|
||||
@@ -58,13 +58,10 @@ class Tlv
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Length values.
|
||||
* The maximum length of the Base TLV format.
|
||||
*
|
||||
*/
|
||||
enum
|
||||
{
|
||||
kBaseTlvMaxLength = OT_NETWORK_BASE_TLV_MAX_LENGTH, ///< The maximum length of the Base TLV format.
|
||||
};
|
||||
static constexpr uint8_t kBaseTlvMaxLength = OT_NETWORK_BASE_TLV_MAX_LENGTH;
|
||||
|
||||
/**
|
||||
* This method returns the Type value.
|
||||
@@ -431,10 +428,7 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
enum
|
||||
{
|
||||
kExtendedLength = 255, ///< Extended Length value
|
||||
};
|
||||
static const uint8_t kExtendedLength = 255; // Extended Length value.
|
||||
|
||||
private:
|
||||
static Error Find(const Message &aMessage, uint8_t aType, uint16_t *aOffset, uint16_t *aSize, bool *aIsExtendedTlv);
|
||||
@@ -483,10 +477,7 @@ private:
|
||||
template <uint8_t kTlvTypeValue> class TlvInfo
|
||||
{
|
||||
public:
|
||||
enum : uint8_t
|
||||
{
|
||||
kType = kTlvTypeValue, ///< The TLV Type value.
|
||||
};
|
||||
static constexpr uint8_t kType = kTlvTypeValue; ///< The TLV Type value.
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -68,15 +68,12 @@ public:
|
||||
kModePlainTimer, ///< Operate as a plain periodic timer with random interval selected within min/max intervals.
|
||||
};
|
||||
|
||||
enum : uint16_t
|
||||
{
|
||||
/**
|
||||
* Special value for redundancy constant (aka `k`) to indicate infinity (when used, it disables trickle timer's
|
||||
* suppression behavior, invoking the handler callback independent of number of "consistent" events).
|
||||
*
|
||||
*/
|
||||
kInfiniteRedundancyConstant = NumericLimits<uint16_t>::kMax,
|
||||
};
|
||||
/**
|
||||
* Special value for redundancy constant (aka `k`) to indicate infinity (when used, it disables trickle timer's
|
||||
* suppression behavior, invoking the handler callback independent of number of "consistent" events).
|
||||
*
|
||||
*/
|
||||
static constexpr uint16_t kInfiniteRedundancyConstant = NumericLimits<uint16_t>::kMax;
|
||||
|
||||
/**
|
||||
* This function pointer is called when the timer expires (i.e., transmission should happen).
|
||||
|
||||
Reference in New Issue
Block a user