1 /*
2  * Copyright (c) 2020 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 #ifndef OHOS_ACELITE_KEY_PARSER_H
17 #define OHOS_ACELITE_KEY_PARSER_H
18 #include <cstdint>
19 #include "ace_mem_base.h"
20 #include "memory_heap.h"
21 #include "non_copyable.h"
22 namespace OHOS {
23 namespace ACELite {
24 class KeyParser final : public MemoryHeap {
25 public:
26     ACE_DISALLOW_COPY_AND_MOVE(KeyParser);
27     /**
28      * @fn uint16_t ParseKeyId(const char* s)
29      *
30      * @brief Search the key id in the keyword info with key string,
31      * do not use by default
32      *
33      * @param[in] The key string to be parsed
34      *
35      * @return The key id enum value
36      */
37     static uint16_t ParseKeyId(const char * const s);
38 
39     /**
40      * @fn uint16_t ParseKeyId(const char* s, const size_t len)
41      *
42      * @brief Search the key id in the keyword info with key string,
43      * add the length string has better performance
44      *
45      * @param[in] The key string to be parsed
46      *
47      * @param[in] The key string length
48      *
49      * @return The key id enum value
50      */
51     static uint16_t ParseKeyId(const char *s, const size_t len);
52 
53     /**
54      * @fn bool IsKeyValid(uint16_t id)
55      *
56      * @brief Check if the input id is supported.
57      *
58      * @param[in] The id
59      *
60      * @return true if the given id is valid, false for otherwise
61      */
62     static bool IsKeyValid(uint16_t id);
63 
64     /**
65      * @fn const char* GetKeyById(uint16_t id);
66      *
67      * @brief Get the key string by id index, for debugging print,
68      * do not support by default
69      *
70      * @param[in] The key id for index
71      *
72      * @return The key string
73      */
74     static const char *GetKeyById(uint16_t id);
75 
76 private:
KeyParser()77     KeyParser() {}
~KeyParser()78     ~KeyParser() {}
79 };
80 } // namespace ACELite
81 } // namespace OHOS
82 #endif // OHOS_ACELITE_KEY_PARSER_H
83