Matter SDK Coverage Report
Current view: top level - app - ConcreteClusterPath.h (source / functions) Coverage Total Hit
Test: SHA:f1767a8b0a3778fdf31b1d979afbdf544892fd94 Lines: 100.0 % 12 12
Test Date: 2026-06-03 07:35:21 Functions: 100.0 % 8 8

            Line data    Source code
       1              : /*
       2              :  *
       3              :  *    Copyright (c) 2021 Project CHIP Authors
       4              :  *    All rights reserved.
       5              :  *
       6              :  *    Licensed under the Apache License, Version 2.0 (the "License");
       7              :  *    you may not use this file except in compliance with the License.
       8              :  *    You may obtain a copy of the License at
       9              :  *
      10              :  *        http://www.apache.org/licenses/LICENSE-2.0
      11              :  *
      12              :  *    Unless required by applicable law or agreed to in writing, software
      13              :  *    distributed under the License is distributed on an "AS IS" BASIS,
      14              :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      15              :  *    See the License for the specific language governing permissions and
      16              :  *    limitations under the License.
      17              :  */
      18              : 
      19              : #pragma once
      20              : 
      21              : #include <app/util/basic-types.h>
      22              : #include <lib/support/Compiler.h>
      23              : 
      24              : namespace chip {
      25              : namespace app {
      26              : 
      27              : /**
      28              :  * A representation of a concrete cluster path.  This identifies a specific
      29              :  * cluster instance.
      30              :  */
      31              : struct ConcreteClusterPath
      32              : {
      33              :     CHIP_CPP20(constexpr)
      34        89613 :     ConcreteClusterPath(EndpointId aEndpointId, ClusterId aClusterId) : mEndpointId(aEndpointId), mClusterId(aClusterId) {}
      35        23324 :     CHIP_CPP20(constexpr) ConcreteClusterPath() = default;
      36              : 
      37              :     ConcreteClusterPath(const ConcreteClusterPath & aOther)             = default;
      38              :     ConcreteClusterPath & operator=(const ConcreteClusterPath & aOther) = default;
      39              : 
      40          227 :     bool IsValidConcreteClusterPath() const { return !(mEndpointId == kInvalidEndpointId || mClusterId == kInvalidClusterId); }
      41              : 
      42         6329 :     bool HasValidIds() const { return IsValidEndpointId(mEndpointId) && IsValidClusterId(mClusterId); }
      43              : 
      44      1767784 :     bool operator==(const ConcreteClusterPath & aOther) const
      45              :     {
      46      1767784 :         return mEndpointId == aOther.mEndpointId && mClusterId == aOther.mClusterId;
      47              :     }
      48              : 
      49        14589 :     bool operator!=(const ConcreteClusterPath & aOther) const { return !(*this == aOther); }
      50              : 
      51              :     EndpointId mEndpointId = 0;
      52              :     // Note: not all subclasses of ConcreteClusterPath need mExpanded, but due
      53              :     // to alignment requirements it's "free" in the sense of not needing more
      54              :     // memory to put it here.  But we don't initialize it, because that
      55              :     // increases codesize for the non-consumers.
      56              :     bool mExpanded; // NOTE: in between larger members, NOT initialized (see above)
      57              :     ClusterId mClusterId = 0;
      58              : 
      59              :     /// Creates a concrete cluster path as a constexpr. This is a workaround for C++ before C++20 requiring all members
      60              :     /// to be initialized for constexpr constructors.
      61          411 :     constexpr static ConcreteClusterPath ConstExpr(EndpointId aEndpointId, ClusterId aClusterId)
      62              :     {
      63          411 :         return { aEndpointId, aClusterId, false };
      64              :     }
      65              : 
      66              : private:
      67              :     // Setting this as private since as of C++20 we would be allowed to have constructors
      68              :     // that do not initialize all members. Until then though, we require one that
      69              :     // initializes everything and this is that constructor. Readibility of a `bool` is poor though
      70              :     // so we route this throgh the `ConstExpr()` factory instead for readability and eventual
      71              :     // removal.
      72          411 :     constexpr ConcreteClusterPath(EndpointId aEndpointId, ClusterId aClusterId, bool expanded) :
      73          411 :         mEndpointId(aEndpointId), mExpanded(expanded), mClusterId(aClusterId)
      74          411 :     {}
      75              : };
      76              : 
      77              : } // namespace app
      78              : } // namespace chip
        

Generated by: LCOV version 2.0-1