• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dfx_option.h"
17 
18 namespace ark::os::dfx_option {
19 
20 /* static */
IsInOptionList(const std::string & s)21 bool DfxOptionHandler::IsInOptionList(const std::string &s)
22 {
23 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
24 #define D(e, v, str)                               \
25     /* CC-OFFNXT(G.PRE.10) function scope macro */ \
26     if (s == (str)) {                              \
27         /* CC-OFFNXT(G.PRE.05) function gen */     \
28         return true;                               \
29     }
30     DFX_OPTION_LIST(D)
31 #undef D
32     return false;
33 }
34 
35 /* static */
DfxOptionFromString(const std::string & s)36 DfxOptionHandler::DfxOption DfxOptionHandler::DfxOptionFromString(const std::string &s)
37 {
38 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
39 #define D(e, v, str)                               \
40     /* CC-OFFNXT(G.PRE.10) function scope macro */ \
41     if (s == (str)) {                              \
42         /* CC-OFFNXT(G.PRE.05) function gen */     \
43         return DfxOptionHandler::DfxOption::e;     \
44     }
45     DFX_OPTION_LIST(D)
46 #undef D
47     UNREACHABLE();
48 }
49 
50 /* static */
StringFromDfxOption(DfxOptionHandler::DfxOption dfxOption)51 std::string DfxOptionHandler::StringFromDfxOption(DfxOptionHandler::DfxOption dfxOption)
52 {
53 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
54 #define D(e, v, str)                                   \
55     /* CC-OFFNXT(G.PRE.10) function scope macro */     \
56     if (dfxOption == DfxOptionHandler::DfxOption::e) { \
57         /* CC-OFFNXT(G.PRE.05) function gen */         \
58         return (str);                                  \
59     }
60     DFX_OPTION_LIST(D)
61 #undef D
62     UNREACHABLE();
63 }
64 
65 }  // namespace ark::os::dfx_option
66