diff --git a/src/app/ConcreteAttributePath.h b/src/app/ConcreteAttributePath.h index 0fb764e057fae9..97e29bc190766d 100644 --- a/src/app/ConcreteAttributePath.h +++ b/src/app/ConcreteAttributePath.h @@ -18,6 +18,7 @@ #pragma once +#include #include #include @@ -30,28 +31,34 @@ namespace app { * The expanded flag can be set to indicate that a concrete path was expanded from a wildcard * or group path. */ -struct ConcreteAttributePath +struct ConcreteAttributePath : public ConcreteClusterPath { - ConcreteAttributePath() {} + ConcreteAttributePath() + { + // Note: mExpanded is in the superclass, so we can't use a field + // initializer. + mExpanded = false; + } ConcreteAttributePath(EndpointId aEndpointId, ClusterId aClusterId, AttributeId aAttributeId) : - mEndpointId(aEndpointId), mClusterId(aClusterId), mAttributeId(aAttributeId) - {} + ConcreteClusterPath(aEndpointId, aClusterId), mAttributeId(aAttributeId) + { + // Note: mExpanded is in the supercclass, so we can't use a field + // initializer. + mExpanded = false; + } - bool operator==(const ConcreteAttributePath & other) const + bool operator==(const ConcreteAttributePath & aOther) const { - return (mEndpointId == other.mEndpointId) && (mClusterId == other.mClusterId) && (mAttributeId == other.mAttributeId); + return ConcreteClusterPath::operator==(aOther) && (mAttributeId == aOther.mAttributeId); } bool operator<(const ConcreteAttributePath & path) const { return (mEndpointId < path.mEndpointId) || ((mEndpointId == path.mEndpointId) && (mClusterId < path.mClusterId)) || - ((mClusterId == path.mClusterId) && (mAttributeId < path.mAttributeId)); + ((mEndpointId == path.mEndpointId) && (mClusterId == path.mClusterId) && (mAttributeId < path.mAttributeId)); } - EndpointId mEndpointId = 0; - bool mExpanded = false; // NOTE: in between larger members - ClusterId mClusterId = 0; AttributeId mAttributeId = 0; }; diff --git a/src/app/ConcreteClusterPath.h b/src/app/ConcreteClusterPath.h new file mode 100644 index 00000000000000..ec880e8df404b2 --- /dev/null +++ b/src/app/ConcreteClusterPath.h @@ -0,0 +1,56 @@ +/* + * + * Copyright (c) 2021 Project CHIP Authors + * All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +namespace chip { +namespace app { + +/** + * A representation of a concrete cluster path. This identifies a specific + * cluster instance. + */ +struct ConcreteClusterPath +{ + ConcreteClusterPath(EndpointId aEndpointId, ClusterId aClusterId) : mEndpointId(aEndpointId), mClusterId(aClusterId) {} + + ConcreteClusterPath() {} + + ConcreteClusterPath(const ConcreteClusterPath & aOther) = default; + ConcreteClusterPath & operator=(const ConcreteClusterPath & aOther) = default; + + bool operator==(const ConcreteClusterPath & aOther) const + { + return mEndpointId == aOther.mEndpointId && mClusterId == aOther.mClusterId; + } + + bool operator!=(const ConcreteClusterPath & aOther) const { return !(*this == aOther); } + + EndpointId mEndpointId = 0; + // Note: not all subclasses of ConcreteClusterPath need mExpanded, but due + // to alignment requirements it's "free" in the sense of not needing more + // memory to put it here. But we don't initialize it, because that + // increases codesize for the non-consumers. + bool mExpanded; // NOTE: in between larger members + ClusterId mClusterId = 0; +}; + +} // namespace app +} // namespace chip diff --git a/src/app/ConcreteCommandPath.h b/src/app/ConcreteCommandPath.h index 7287e1289ddbb0..5020aa0ba6d2c0 100644 --- a/src/app/ConcreteCommandPath.h +++ b/src/app/ConcreteCommandPath.h @@ -18,8 +18,8 @@ #pragma once +#include #include -#include namespace chip { namespace app { @@ -27,20 +27,20 @@ namespace app { /** * A representation of a concrete invoke path. */ -struct ConcreteCommandPath +struct ConcreteCommandPath : public ConcreteClusterPath { ConcreteCommandPath(EndpointId aEndpointId, ClusterId aClusterId, CommandId aCommandId) : - mEndpointId(aEndpointId), mClusterId(aClusterId), mCommandId(aCommandId) + ConcreteClusterPath(aEndpointId, aClusterId), mCommandId(aCommandId) {} - bool operator==(const ConcreteCommandPath & other) const + bool operator==(const ConcreteCommandPath & aOther) const { - return mEndpointId == other.mEndpointId && mClusterId == other.mClusterId && mCommandId == other.mCommandId; + return ConcreteClusterPath::operator==(aOther) && (mCommandId == aOther.mCommandId); } - EndpointId mEndpointId = 0; - ClusterId mClusterId = 0; - CommandId mCommandId = 0; + bool operator!=(const ConcreteCommandPath & aOther) const { return !(*this == aOther); } + + CommandId mCommandId = 0; }; } // namespace app } // namespace chip diff --git a/src/app/ConcreteEventPath.h b/src/app/ConcreteEventPath.h index 8dd9ce6aaa419d..92dc1859f6256b 100644 --- a/src/app/ConcreteEventPath.h +++ b/src/app/ConcreteEventPath.h @@ -18,6 +18,7 @@ #pragma once +#include #include namespace chip { @@ -26,25 +27,25 @@ namespace app { /** * A representation of a concrete event path. */ -struct ConcreteEventPath +struct ConcreteEventPath : public ConcreteClusterPath { ConcreteEventPath(EndpointId aEndpointId, ClusterId aClusterId, EventId aEventId) : - mEndpointId(aEndpointId), mClusterId(aClusterId), mEventId(aEventId) + ConcreteClusterPath(aEndpointId, aClusterId), mEventId(aEventId) {} ConcreteEventPath() {} - ConcreteEventPath(const ConcreteEventPath & other) = default; - ConcreteEventPath & operator=(const ConcreteEventPath & other) = default; + ConcreteEventPath(const ConcreteEventPath & aOther) = default; + ConcreteEventPath & operator=(const ConcreteEventPath & aOther) = default; - bool operator==(const ConcreteEventPath & other) const + bool operator==(const ConcreteEventPath & aOther) const { - return mEndpointId == other.mEndpointId && mClusterId == other.mClusterId && mEventId == other.mEventId; + return ConcreteClusterPath::operator==(aOther) && (mEventId == aOther.mEventId); } - EndpointId mEndpointId = 0; - ClusterId mClusterId = 0; - EventId mEventId = 0; + bool operator!=(const ConcreteEventPath & aOther) const { return !(*this == aOther); } + + EventId mEventId = 0; }; } // namespace app } // namespace chip