[dali_2.3.21] 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) 2024 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 // EXTERNAL INCLUDES
21 #include <cstdint>
22 #include <string>
23 #include <string_view>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Internal
30 {
31 class VisualUrl
32 {
33 public:
34   /**
35    * The type of the URL based on the string contents
36    */
37   enum Type
38   {
39     REGULAR_IMAGE,
40     N_PATCH,
41     SVG,
42     GIF,
43     WEBP,
44     JSON,
45     TVG
46   };
47
48   enum ProtocolType
49   {
50     LOCAL,   ///< file in local file system
51     TEXTURE, ///< texture uploaded to texture manager
52     REMOTE,  ///< remote image
53     BUFFER   ///< encoded image buffer
54   };
55
56   /**
57    * Default Constructor.
58    * Resulting URL is not valid
59    */
60   VisualUrl();
61
62   /**
63    * Default Destructor.
64    * Delete an external texture if if protocolType is TEXTURE.
65    */
66   ~VisualUrl();
67
68   /**
69    * Constructor.
70    * Determines type of visual and whether the url is local or remote
71    * Notify that it is using an external texture if if protocolType is TEXTURE.
72    *
73    * @param[in] url The URL to store and resolve
74    */
75   VisualUrl(const std::string& url);
76
77   /**
78    * Copy constructor
79    * @param[in] url The VisualUrl to copy
80    */
81   VisualUrl(const VisualUrl& url);
82
83   /**
84    * Assignment operator
85    * @param[in] url The VisualUrl to copy
86    */
87   VisualUrl& operator=(const VisualUrl& url);
88
89   /**
90    * Move constructor
91    * @param[in] url The VisualUrl to move
92    */
93   VisualUrl(VisualUrl&& url) noexcept;
94
95   /**
96    * Move assignment operator
97    * @param[in] url The VisualUrl to move
98    */
99   VisualUrl& operator=(VisualUrl&& url) noexcept;
100
101   /**
102    * Get the full URL
103    * @return The url
104    */
105   const std::string& GetUrl() const;
106
107   /**
108    * Get the ellipsed URL.
109    * @return The ellipsed url
110    */
111   std::string GetEllipsedUrl() const;
112
113   /**
114    * Get the hash value of full URL
115    * @return The hash value of url
116    */
117   std::uint64_t GetUrlHash() const;
118
119   /**
120    * Get the visual type of the URL
121    * @return The visual type of the URL
122    */
123   Type GetType() const;
124
125   /**
126    * Is the URL is local to the device, or remote?
127    * @return the location of the resource
128    */
129   ProtocolType GetProtocolType() const;
130
131   /**
132    * Is the URL valid?
133    * @return true if the URL has length
134    */
135   bool IsValid() const;
136
137   /**
138    * @return true if the location is LOCAL, i.e. is loadable from local file system
139    */
140   bool IsLocalResource() const;
141
142   /**
143    * @return true if the location is BUFFER, i.e. may contain EncodedImageBuffer
144    */
145   bool IsBufferResource() const;
146
147   /**
148    * @return the location part of the url
149    */
150   std::string GetLocation() const;
151
152   /**
153    * @return the location part of the url without extension
154    */
155   std::string GetLocationWithoutExtension() const;
156
157   /**
158    * Helper to create a URL of type TEXTURE
159    * @param location the location of the texture
160    * @return the Url
161    */
162   static std::string CreateTextureUrl(const std::string& location);
163
164   /**
165    * Helper to create a URL of type BUFFER
166    * @param[in] location the location of the texture
167    * @param[in] extension the extension of url
168    * @return the Url
169    */
170   static std::string CreateBufferUrl(const std::string& location, const std::string_view& extension);
171
172   /**
173    * Helper to get a ProtocolType from url
174    * @param url the url of the texture
175    * @return the protocol type
176    */
177   static VisualUrl::ProtocolType GetProtocolType(const std::string& url);
178
179   /**
180    * Helper to get a location from url
181    * @param url the location of the texture
182    * @return the location
183    */
184   static std::string GetLocation(const std::string& url);
185
186   /**
187    * Helper to get a location from url without extension
188    * @param[in] url the location of the texture
189    * @return the location without extension
190    */
191   static std::string GetLocationWithoutExtension(const std::string& url);
192
193 private:
194   std::string  mUrl;
195   Type         mType;
196   ProtocolType mLocation;
197
198   mutable std::uint64_t mUrlHash;
199 };
200
201 } // namespace Internal
202
203 } // namespace Toolkit
204
205 } // namespace Dali
206
207 #endif /* DALI_TOOLKIT_INTERNAL_VISUAL_URL_H */