LCOV - code coverage report
Current view: top level - acl/common - json_parser.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 6 6 100.0 %
Date: 2026-08-27 13:24:42 Functions: 3 3 100.0 %

          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 ACL_JSON_PARSER_H
      12             : #define ACL_JSON_PARSER_H
      13             : 
      14             : #include "nlohmann/json.hpp"
      15             : #include "acl/acl_base.h"
      16             : #include "log_inner.h"
      17             : #include "utils/cann_info_utils.h"
      18             : 
      19             : namespace acl {
      20             :     class JsonParser {
      21             :     public:
      22             :         static aclError ParseJsonFromFile(const char_t *const fileName, nlohmann::json &js);
      23             :         static aclError GetJsonCtxByKey(
      24             :             const char_t *const fileName, std::string &strJsonCtx, const std::string &subStrKey, bool &found);
      25             :         static aclError GetAttrConfigFromFile(
      26             :             const char_t *const fileName, std::map<aclCannAttr, CannInfo> &cannInfoMap);
      27             :         static aclError GetDefaultDeviceIdFromFile(const char_t *const fileName, int32_t& devId);
      28             :         static aclError GetEventModeFromFile(const char_t *const fileName, uint8_t &event_mode, bool &found);
      29             :         static aclError GetStackSizeByType(const char_t *const fileName, const std::string &typeName, size_t &outSize,
      30             :                                             bool &outExist);  
      31             :         static aclError GetPrintFifoSizeByType(const char_t* const fileName, const std::string& typeName, 
      32             :             size_t& fifoSize, bool& found);
      33             :         static aclError ParseJson(const char_t* const fileName, const char_t *const configStr, nlohmann::json &js);
      34             :         static aclError GetConfigStrFromFile(const char_t *const fileName, std::string &configStr);
      35             : 
      36             :     private:
      37             :         static void GetMaxNestedLayers(const char_t *const fileName, const size_t length,
      38             :                                        size_t &maxObjDepth, size_t &maxArrayDepth);
      39             :         static bool IsValidFileName(const char_t *const fileName);
      40             : 
      41          13 :         static const nlohmann::json& GetCfgJsonByKey(const nlohmann::json &js, const std::string &key) {
      42          13 :             return js.at(key);
      43             :         }
      44             : 
      45          11 :         static std::string GetCfgStrByKey(const nlohmann::json &js , const std::string &key) {
      46          11 :             return js.at(key).get<std::string>();
      47             :         }
      48             :         
      49          57 :         static bool ContainKey(const nlohmann::json &js, const std::string &key) {
      50          57 :             return (js.find(key) != js.end());
      51             :         }
      52             :     };
      53             : }
      54             : #endif // ACL_JSON_PARSER_H

Generated by: LCOV version 1.14