• 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_INTERFACE_INNERAPI_BASE_SOURCE_INFO_H
17 #define FOUNDATION_ACE_INTERFACE_INNERAPI_BASE_SOURCE_INFO_H
18 
19 #include <string>
20 
21 #include "base/resource.h"
22 
23 namespace OHOS {
24 namespace Ace {
25 namespace Drawable {
26 enum class SrcType {
27     UNSUPPORTED = -1,
28     RESOURCE,
29     PIXMAP,
30 };
31 
32 class SourceInfo final {
33 public:
34     SourceInfo() = default;
35     ~SourceInfo() = default;
36 
SourceInfo(const std::string & src)37     explicit SourceInfo(const std::string& src) : src_(src), srcType_(ResolveSrcType(src)) {}
38 
SourceInfo(const Resource & resource)39     explicit SourceInfo(const Resource& resource) : resource_(resource), srcType_(SrcType::RESOURCE) {}
40 
SetSrc(const std::string & src)41     void SetSrc(const std::string& src)
42     {
43         src_ = src;
44         srcType_ = ResolveSrcType(src);
45     }
46 
SetSrcType(const SrcType & srcType)47     void SetSrcType(const SrcType& srcType)
48     {
49         srcType_ = srcType;
50     }
51 
GetSrcType()52     SrcType GetSrcType() const
53     {
54         return srcType_;
55     }
56 
GetSrc()57     std::string GetSrc() const
58     {
59         return src_;
60     }
61 
SetResource(const Resource & resource)62     void SetResource(const Resource& resource)
63     {
64         resource_ = resource;
65     }
66 
GetResource()67     Resource GetResource() const
68     {
69         return resource_;
70     }
71 
72     std::string ToString() const;
73 
74 private:
75     static SrcType ResolveSrcType(const std::string& src);
76 
77     std::string src_;
78     Resource resource_;
79     SrcType srcType_ = SrcType::UNSUPPORTED;
80 };
81 } // namespace Drawable
82 } // namespace Ace
83 } // namespace OHOS
84 
85 #endif // FOUNDATION_ACE_INTERFACE_INNERAPI_BASE_SOURCE_INFO_H
86