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 FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MANIFEST_MANIFEST_WIDGET_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MANIFEST_MANIFEST_WIDGET_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <string>
22 #include <unordered_map>
23 
24 #include "base/json/json_util.h"
25 #include "base/memory/referenced.h"
26 #include "base/utils/noncopyable.h"
27 
28 namespace OHOS::Ace::Framework {
29 
30 class ManifestWidget : public Referenced {
31 public:
ManifestWidget(const std::string & name,const std::string & path)32     ManifestWidget(const std::string& name, const std::string& path) : widgetName_(name), widgetPath_(path) {}
33     ~ManifestWidget() override = default;
34 
35     // widget description.
36     const std::string& GetWidgetName() const;
37     const std::string& GetWidgetPath() const;
38 
39 private:
40     std::string widgetName_;
41     std::string widgetPath_;
42 
43     ACE_DISALLOW_COPY_AND_MOVE(ManifestWidget);
44 };
45 
46 class ManifestWidgetGroup : public Referenced {
47 public:
48     ManifestWidgetGroup() = default;
49     ~ManifestWidgetGroup() override = default;
50 
51     void WidgetParse(const std::unique_ptr<JsonValue>& root);
52 
GetWidgetNum()53     uint32_t GetWidgetNum() const
54     {
55         return static_cast<uint32_t>(widgets_.size());
56     }
57 
GetWidgetList()58     const std::unordered_map<std::string, RefPtr<ManifestWidget>>& GetWidgetList() const
59     {
60         return widgets_;
61     }
62 
63 private:
64     std::unordered_map<std::string, RefPtr<ManifestWidget>> widgets_;
65 
66     ACE_DISALLOW_COPY_AND_MOVE(ManifestWidgetGroup);
67 };
68 
69 } // namespace OHOS::Ace::Framework
70 
71 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_MANIFEST_MANIFEST_WIDGET_H
72