Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 : #include "ccu_res_desc.h"
12 :
13 : namespace hcomm {
14 : static_assert(
15 : CCU_RES_TYPE_COUNT == static_cast<size_t>(ResType::__COUNT__), "CCU_RES_TYPE_COUNT must match ResType::__COUNT__");
16 :
17 1965 : CcuResult CcuResDesc::SetResNum(ResType resType, uint32_t num)
18 : {
19 1965 : if (!IsValidResType(resType)) {
20 0 : return CcuResult::CCU_E_PARA;
21 : }
22 :
23 1965 : resNum[ResTypeIndex(resType)] = num;
24 1965 : return CcuResult::CCU_SUCCESS;
25 : }
26 :
27 882 : CcuResult CcuResDesc::QueryResNum(ResType resType, uint32_t& num) const
28 : {
29 882 : if (!IsValidResType(resType)) {
30 0 : return CcuResult::CCU_E_PARA;
31 : }
32 :
33 882 : num = resNum[ResTypeIndex(resType)];
34 882 : return CcuResult::CCU_SUCCESS;
35 : }
36 :
37 2847 : bool CcuResDesc::IsValidResType(ResType resType) { return resType < ResType::__COUNT__; }
38 :
39 2847 : size_t CcuResDesc::ResTypeIndex(ResType resType) { return static_cast<size_t>(static_cast<ResType::Value>(resType)); }
40 : } // namespace hcomm
|