[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-url.h
1 #ifndef DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
2 #define DALI_TOOLKIT_INTERNAL_VISUAL_URL_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <string>
21
22 namespace Dali
23 {
24 namespace Toolkit
25 {
26 namespace Internal
27 {
28 class VisualUrl
29 {
30 public:
31   /**
32    * The type of the URL based on the string contents
33    */
34   enum Type
35   {
36     REGULAR_IMAGE,
37     N_PATCH,
38     SVG,
39     GIF,
40     WEBP,
41     JSON,
42     TVG
43   };
44
45   enum ProtocolType
46   {
47     LOCAL,   ///< file in local file system
48     TEXTURE, ///< texture uploaded to texture manager
49     REMOTE,  ///< remote image
50     BUFFER   ///< encoded image buffer
51   };
52
53   /**
54    * Default Constructor.
55    * Resulting URL is not valid
56    */
57   VisualUrl();
58
59   /**
60    * Default Destructor.
61    * Delete an external texture if if protocolType is TEXTURE.
62    */
63   ~VisualUrl();
64
65   /**
66    * Constructor.
67    * Determines type of visual and whether the url is local or remote
68    * Notify that it is using an external texture if if protocolType is TEXTURE.
69    *
70    * @param[in] url The URL to store and resolve
71    */
72   VisualUrl(const std::string& url);
73
74   /**
75    * Copy constructor
76    * @param[in] url The VisualUrl to copy
77    */
78   VisualUrl(const VisualUrl& url);
79
80   /**
81    * Assignment operator
82    * @param[in] url The VisualUrl to copy
83    */
84   VisualUrl& operator=(const VisualUrl& url);
85
86   /**
87    * Move constructor
88    * @param[in] url The VisualUrl to move
89    */
90   VisualUrl(VisualUrl&& url) noexcept;
91
92   /**
93    * Move assignment operator
94    * @param[in] url The VisualUrl to move
95    */
96   VisualUrl& operator=(VisualUrl&& url) noexcept;
97
98   /**
99    * Get the full URL
100    * @return The url
101    */
102   const std::string& GetUrl() const;
103
104   /**
105    * Get the hash value of full URL
106    * @return The hash value of url
107    */
108   std::uint64_t GetUrlHash() const;
109
110   /**
111    * Get the visual type of the URL
112    * @return The visual type of the URL
113    */
114   Type GetType() const;
115
116   /**
117    * Is the URL is local to the device, or remote?
118    * @return the location of the resource
119    */
120   ProtocolType GetProtocolType() const;
121
122   /**
123    * Is the URL valid?
124    * @return true if the URL has length
125    */
126   bool IsValid() const;
127
128   /**
129    * @return true if the location is LOCAL, i.e. is loadable from local file system
130    */
131   bool IsLocalResource() const;
132
133   /**
134    * @return true if the location is BUFFER, i.e. may contain EncodedImageBuffer
135    */
136   bool IsBufferResource() const;
137
138   /**
139    * @return the location part of the url
140    */
141   std::string GetLocation() const;
142
143   /**
144    * Helper to create a URL of type TEXTURE
145    * @param location the location of the texture
146    * @return the Url
147    */
148   static std::string CreateTextureUrl(const std::string& location);
149
150   /**
151    * Helper to create a URL of type BUFFER
152    * @param location the location of the texture
153    * @return the Url
154    */
155   static std::string CreateBufferUrl(const std::string& location);
156
157   /**
158    * Helper to get a ProtocolType from url
159    * @param url the url of the texture
160    * @return the protocol type
161    */
162   static VisualUrl::ProtocolType GetProtocolType(const std::string& url);
163
164   /**
165    * Helper to get a location from url
166    * @param url the location of the texture
167    * @return the location
168    */
169   static std::string GetLocation(const std::string& url);
170
171 private:
172   std::string  mUrl;
173   Type         mType;
174   ProtocolType mLocation;
175
176   mutable std::uint64_t mUrlHash;
177 };
178
179 } // namespace Internal
180
181 } // namespace Toolkit
182
183 } // namespace Dali
184
185 #endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */