LCOV - code coverage report
Current view: top level - acl/common - json_parser.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 5 5
Test Date: 2026-07-28 10:53:01 Functions: 100.0 % 3 3

            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(const char_t* const fileName, std::map<aclCannAttr, CannInfo>& cannInfoMap);
      26              :     static aclError GetDefaultDeviceIdFromFile(const char_t* const fileName, int32_t& devId);
      27              :     static aclError GetEventModeFromFile(const char_t* const fileName, uint8_t& event_mode, bool& found);
      28              :     static aclError GetStackSizeByType(
      29              :         const char_t* const fileName, const std::string& typeName, size_t& outSize, bool& outExist);
      30              :     static aclError GetPrintFifoSizeByType(
      31              :         const char_t* const fileName, const std::string& typeName, size_t& fifoSize, bool& found);
      32              :     static aclError ParseJson(const char_t* const fileName, const char_t* const configStr, nlohmann::json& js);
      33              :     static aclError GetConfigStrFromFile(const char_t* const fileName, std::string& configStr);
      34              : 
      35              : private:
      36              :     static void GetMaxNestedLayers(
      37              :         const char_t* const fileName, const size_t length, size_t& maxObjDepth, size_t& maxArrayDepth);
      38              :     static bool IsValidFileName(const char_t* const fileName);
      39              : 
      40           13 :     static const nlohmann::json& GetCfgJsonByKey(const nlohmann::json& js, const std::string& key)
      41              :     {
      42           13 :         return js.at(key);
      43              :     }
      44              : 
      45           11 :     static std::string GetCfgStrByKey(const nlohmann::json& js, const std::string& key)
      46              :     {
      47           11 :         return js.at(key).get<std::string>();
      48              :     }
      49              : 
      50           57 :     static bool ContainKey(const nlohmann::json& js, const std::string& key) { return (js.find(key) != js.end()); }
      51              : };
      52              : } // namespace acl
      53              : #endif // ACL_JSON_PARSER_H
        

Generated by: LCOV version 2.0-1