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