[clearable] update Clearable to ensure CRTP-style use (#8198)

This commit updates `Clearable<Type>::Clear()` method to perform
`static_cast<Type *>(this)`. This ensures CRTP-style use and also
allows the `Clearable` to be used for types that may not be a
standard layout type (and/or more generally in cases where empty
base optimization may not be applied).
This commit is contained in:
Abtin Keshavarzian
2022-09-23 09:04:24 -07:00
committed by GitHub
parent 322671e682
commit 1942a79d75
8 changed files with 20 additions and 3 deletions
@@ -65,6 +65,7 @@ public:
class NdProxy : private Clearable<NdProxy>
{
friend class NdProxyTable;
friend class Clearable<NdProxy>;
public:
/**
@@ -433,6 +433,7 @@ private:
class Entry : public LinkedListEntry<Entry>, public Unequatable<Entry>, private Clearable<Entry>
{
friend class LinkedListEntry<Entry>;
friend class Clearable<Entry>;
public:
enum Type : uint8_t
+2 -2
View File
@@ -41,7 +41,7 @@
namespace ot {
/**
* This template class defines a Clearable object which provides `Clear()` method.
* This template class defines a `Clearable` object which provides `Clear()` method.
*
* The `Clear` implementation simply sets all the bytes of a `Type` instance to zero.
*
@@ -52,7 +52,7 @@ namespace ot {
template <typename Type> class Clearable
{
public:
void Clear(void) { memset(reinterpret_cast<void *>(this), 0, sizeof(Type)); }
void Clear(void) { memset(reinterpret_cast<void *>(static_cast<Type *>(this)), 0, sizeof(Type)); }
};
} // namespace ot
+1
View File
@@ -1506,6 +1506,7 @@ class PriorityQueue : private Clearable<PriorityQueue>
friend class Message;
friend class MessageQueue;
friend class MessagePool;
friend class Clearable<PriorityQueue>;
public:
typedef otMessageQueueInfo Info; ///< This struct represents info (number of messages/buffers) about a queue.
+5
View File
@@ -133,6 +133,7 @@ public:
class NetworkInfo : private Clearable<NetworkInfo>
{
friend class Settings;
friend class Clearable<NetworkInfo>;
public:
static constexpr Key kKey = kKeyNetworkInfo; ///< The associated key.
@@ -339,6 +340,7 @@ public:
class ParentInfo : private Clearable<ParentInfo>
{
friend class Settings;
friend class Clearable<ParentInfo>;
public:
static constexpr Key kKey = kKeyParentInfo; ///< The associated key.
@@ -532,6 +534,7 @@ public:
class DadInfo : private Clearable<DadInfo>
{
friend class Settings;
friend class Clearable<DadInfo>;
public:
static constexpr Key kKey = kKeyDadInfo; ///< The associated key.
@@ -607,6 +610,7 @@ public:
class SrpClientInfo : private Clearable<SrpClientInfo>
{
friend class Settings;
friend class Clearable<SrpClientInfo>;
public:
static constexpr Key kKey = kKeySrpClientInfo; ///< The associated key.
@@ -667,6 +671,7 @@ public:
class SrpServerInfo : private Clearable<SrpServerInfo>
{
friend class Settings;
friend class Clearable<SrpServerInfo>;
public:
static constexpr Key kKey = kKeySrpServerInfo; ///< The associated key.
+2
View File
@@ -416,6 +416,8 @@ private:
*/
class Headers : private Clearable<Headers>
{
friend class Clearable<Headers>;
public:
/**
* This method parses the IPv6 and UDP/TCP/ICMP6 headers from a given message.
+6
View File
@@ -175,6 +175,8 @@ private:
OT_TOOL_PACKED_BEGIN
class PrefixInfoOption : public Option, private Clearable<PrefixInfoOption>
{
friend class Clearable<PrefixInfoOption>;
public:
static constexpr Type kType = kTypePrefixInfo; ///< Prefix Information Option Type.
@@ -330,6 +332,8 @@ static_assert(sizeof(PrefixInfoOption) == 32, "invalid PrefixInfoOption structur
OT_TOOL_PACKED_BEGIN
class RouteInfoOption : public Option, private Clearable<RouteInfoOption>
{
friend class Clearable<RouteInfoOption>;
public:
static constexpr uint16_t kMinSize = kLengthUnit; ///< Minimum size (in bytes) of a Route Info Option
static constexpr Type kType = kTypeRouteInfo; ///< Route Information Option Type.
@@ -470,6 +474,8 @@ public:
OT_TOOL_PACKED_BEGIN
class Header : public Equatable<Header>, private Clearable<Header>
{
friend class Clearable<Header>;
public:
/**
* This constructor initializes the Router Advertisement message with
+2 -1
View File
@@ -106,6 +106,7 @@ public:
class HostInfo : public otSrpClientHostInfo, private Clearable<HostInfo>
{
friend class Client;
friend class Clearable<HostInfo>;
public:
/**
@@ -890,7 +891,7 @@ private:
};
#if OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE
class AutoStart : Clearable<AutoStart>
class AutoStart : public Clearable<AutoStart>
{
public:
enum State : uint8_t{