LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/pub_inc/ccu - ccu_ctx_signature.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 24 24
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 13 13

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #ifndef HCCL_CCU_CTX_SIGNATURE_H
      12              : #define HCCL_CCU_CTX_SIGNATURE_H
      13              : 
      14              : #include <sstream>
      15              : #include <iostream>
      16              : #include <string>
      17              : #include <ios>
      18              : #include "hash_utils.h"
      19              : #include "string_util.h"
      20              : 
      21              : namespace Hccl {
      22              : 
      23              : class CcuCtxSignature {
      24              : public:
      25          108 :     CcuCtxSignature()  = default;
      26          128 :     ~CcuCtxSignature() = default;
      27           20 :     CcuCtxSignature(const CcuCtxSignature &other)
      28           20 :     {
      29              :         // 实现复制构造函数
      30           20 :         data << other.data.str();
      31           20 :     }
      32              :  
      33            8 :     void operator=(const CcuCtxSignature &other)
      34              :     {
      35              :         // 实现赋值操作
      36            8 :         data << other.data.str();
      37            8 :     }
      38              :  
      39           20 :     bool operator==(const CcuCtxSignature &rhs) const
      40              :     {
      41           20 :         return this == &rhs || data.str() == rhs.data.str();
      42              :     }
      43              :  
      44              :     // 用法Append<T>(t)
      45          118 :     template <typename T> void Append(T t)
      46              :     {
      47          118 :         data << t;
      48          118 :     }
      49              :  
      50            2 :     void Append(const CcuCtxSignature &other)
      51              :     {
      52            2 :         data << other.data.str();
      53            2 :     }
      54              : 
      55           51 :     std::string Describe() const
      56              :     {
      57           51 :         return StringFormat("CcuCtxSignature[data=%s]", data.str().c_str());
      58              :     }
      59              :  
      60              :     // 下掉CcuContext GetSignatrue
      61           75 :     std::string GetData() const
      62              :     {
      63           75 :         return data.str();
      64              :     }
      65              :  
      66              :     friend class std::hash<Hccl::CcuCtxSignature>;
      67              : 
      68              : private:
      69              :     std::ostringstream data;
      70              : };
      71              : 
      72              : } // namespace Hccl
      73              : 
      74              : namespace std {
      75              : 
      76              : template <> class hash<Hccl::CcuCtxSignature> {
      77              : public:
      78           24 :     size_t operator()(const Hccl::CcuCtxSignature &signature) const
      79              :     {
      80           24 :         auto dataHash = hash<string>{}(signature.GetData());
      81           24 :         return Hccl::HashCombine({dataHash});
      82              :     }
      83              : };
      84              : 
      85              : } // namespace std
      86              : 
      87              : #endif // HCCL_CCU_CTX_SIGNATURE_H
        

Generated by: LCOV version 2.0-1