• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_RESTOOL_XML_KEY_NODE_H
17 #define OHOS_RESTOOL_XML_KEY_NODE_H
18 
19 #include<functional>
20 #include<map>
21 #include<stdint.h>
22 #include<string>
23 
24 namespace OHOS {
25 namespace Global {
26 namespace Restool {
27 class XmlKeyNode {
28 public:
29     XmlKeyNode();
30     virtual ~XmlKeyNode();
31     int32_t PushKey(const std::string &name);
32     bool SaveToFile(const std::string &filePath) const;
33     bool LoadFromFile(const std::string &filePath);
34     using RefParser = std::function<bool(std::string&)>;
35     bool LoadFromFile(const std::string &filePath, RefParser parser);
36     bool GetKeyValue(int32_t keyId, std::string &value) const;
37 
38     enum class KeyType {
39         NODE = 0,
40         ATTRIBUTE,
41         CONSTANT,
42         CONTENT,
43         END
44     };
45     static const std::map<KeyType, std::string> KEY_TO_FILE_NAME;
46 private:
47     int32_t keyId_;
48     std::map<std::string, int32_t> keyMap_;
49 };
50 }
51 }
52 }
53 #endif