• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_INTERFACES_INNER_API_ACE_KIT_INCLUDE_RESOURCE_RESOURCE_OBJECT_H
17 #define FOUNDATION_ACE_INTERFACES_INNER_API_ACE_KIT_INCLUDE_RESOURCE_RESOURCE_OBJECT_H
18 
19 #include <cstdint>
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 #include "ui/base/ace_type.h"
25 #include "ui/properties/color.h"
26 
27 namespace OHOS::Ace {
28 enum class ResourceObjectParamType { NONE, INT, STRING, FLOAT };
29 
30 struct ResourceObjectParams {
31     std::optional<std::string> value;
32     ResourceObjectParamType type = ResourceObjectParamType::NONE;
33 };
34 
35 class ResourceObject : public AceType {
36     DECLARE_ACE_TYPE(ResourceObject, AceType);
37 
38 public:
39     ResourceObject() = default;
ResourceObject(int32_t id,int32_t type,const std::vector<ResourceObjectParams> & params,const std::string & bundleName,const std::string & moduleName,int32_t instanceId)40     ResourceObject(int32_t id, int32_t type, const std::vector<ResourceObjectParams>& params,
41         const std::string& bundleName, const std::string& moduleName, int32_t instanceId)
42         : id_(id), type_(type), instanceId_(instanceId), params_(params), bundleName_(bundleName),
43           moduleName_(moduleName) {};
ResourceObject(const std::string & bundleName,const std::string & moduleName,int32_t instanceId)44     ResourceObject(const std::string& bundleName, const std::string& moduleName, int32_t instanceId)
45         : id_(-1), type_(-1), instanceId_(instanceId), params_(std::vector<ResourceObjectParams>()),
46           bundleName_(bundleName), moduleName_(moduleName) {};
47     ~ResourceObject() = default;
48 
GetId()49     int32_t GetId() const
50     {
51         return id_;
52     }
53 
GetType()54     int32_t GetType() const
55     {
56         return type_;
57     }
58 
GetInstanceId()59     int32_t GetInstanceId() const
60     {
61         return instanceId_;
62     }
63 
SetInstanceId(int32_t instanceId)64     void SetInstanceId(int32_t instanceId)
65     {
66         instanceId_ = instanceId;
67     }
68 
GetParams()69     std::vector<ResourceObjectParams> GetParams() const
70     {
71         return params_;
72     }
73 
GetBundleName()74     std::string GetBundleName() const
75     {
76         return bundleName_;
77     }
78 
GetModuleName()79     std::string GetModuleName() const
80     {
81         return moduleName_;
82     }
83 
GetColor()84     const Color& GetColor() const
85     {
86         return color_;
87     }
88 
SetColor(const Color & color)89     void SetColor(const Color& color)
90     {
91         color_ = color;
92     }
93 
SetNodeTag(const std::string & nodeTag)94     void SetNodeTag(const std::string& nodeTag)
95     {
96         nodeTag_ = nodeTag;
97     }
98 
GetNodeTag()99     const std::string& GetNodeTag() const
100     {
101         return nodeTag_;
102     }
103 
IsResource()104     bool IsResource() const
105     {
106         return isResource_;
107     }
108 
SetIsResource(bool isResource)109     void SetIsResource(bool isResource)
110     {
111         isResource_ = isResource;
112     }
113 
SetColorMode(ColorMode colorMode)114     void SetColorMode(ColorMode colorMode)
115     {
116         colorMode_ = colorMode;
117     }
118 
GetColorMode()119     const ColorMode& GetColorMode() const
120     {
121         return colorMode_;
122     }
123 
SetHasDarkRes(bool hasDarkRes)124     void SetHasDarkRes(bool hasDarkRes)
125     {
126         hasDarkRes_ = hasDarkRes;
127     }
128 
HasDarkResource()129     bool HasDarkResource() const
130     {
131         return hasDarkRes_;
132     }
133 
134 private:
135     int32_t id_;
136     int32_t type_;
137     int32_t instanceId_;
138     Color color_;
139     std::vector<ResourceObjectParams> params_;
140     std::string bundleName_;
141     std::string moduleName_;
142     std::string nodeTag_;
143     ColorMode colorMode_ = ColorMode::COLOR_MODE_UNDEFINED;
144     bool isResource_ = true;
145     bool hasDarkRes_ = false;
146 };
147 } // namespace OHOS::Ace
148 
149 #endif