ArcGIS Procedural Runtime  3.2.10650
URI.h
1 /*
2  COPYRIGHT (c) 2012-2024 Esri R&D Center Zurich
3  TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
4  Unpublished material - all rights reserved under the
5  Copyright Laws of the United States and applicable international
6  laws, treaties, and conventions.
7 
8  For additional information, contact:
9  Environmental Systems Research Institute, Inc.
10  Attn: Contracts and Legal Services Department
11  380 New York Street
12  Redlands, California, 92373
13  USA
14 
15  email: contracts@esri.com
16 */
17 
18 #ifndef PRTX_URI_H_
19 #define PRTX_URI_H_
20 
21 #include "prtx/prtx.h"
22 
23 #include <string>
24 #include <vector>
25 #include <memory>
26 #include <map>
27 
28 #ifdef _MSC_VER
29 # pragma warning(push)
30 # pragma warning(disable : 4251 4231 4660)
31 #endif
32 
33 
34 namespace prtx {
35 
36 
37 class URI;
38 typedef std::shared_ptr<URI> URIPtr;
39 typedef std::vector<URIPtr> URIPtrVector;
40 
41 
59 class PRTX_EXPORTS_API URI {
60 public:
61  static const std::wstring SCHEME_FILE;
62  static const std::wstring SCHEME_SAMBA;
63  static const std::wstring SCHEME_UNC;
64  static const std::wstring SCHEME_MEMORY;
65  static const std::wstring SCHEME_RPK;
66  static const std::wstring SCHEME_ZIP;
67  static const std::wstring SCHEME_DATA;
68  static const std::wstring SCHEME_BUILTIN;
69 
70  static const std::wstring QUERY_TEXTURE_WIDTH;
71  static const std::wstring QUERY_TEXTURE_HEIGHT;
72  static const std::wstring QUERY_TEXTURE_FORMAT;
73  static const std::wstring QUERY_TEXTURE_NAME;
74 
75  static const std::wstring DELIM_SCHEME;
76  static const std::wstring DELIM_QUERY;
77  static const std::wstring DELIM_QUERY_ITEM;
78  static const std::wstring DELIM_FRAGMENT;
79  static const std::wstring DELIM_FRAGMENT_ITEM;
80  static const std::wstring DELIM_ENTRY;
81 
82 public:
87  static URIPtr create();
88 
89 
94  static URIPtr create(const std::wstring& fullURI);
95 
96 
97  // -- STATE OBSERVERS
98 
102  virtual bool isValid() const = 0;
103 
107  virtual bool isFilePath() const = 0;
108 
109 
110  // -- COMPOSITE SUPPORT
111 
115  virtual bool isComposite() const = 0;
116 
122  virtual URIPtr getNestedURI() const = 0;
123 
124 
125  // -- STRING OUTPUT
126 
132  virtual const std::wstring& wstring() const = 0;
133 
139  virtual std::string string() const = 0;
140 
145  virtual std::wstring getNativeFormat() const = 0;
146 
147 
148  // --- COMPONENT OBSERVERS
149 
154  virtual const std::wstring& getScheme() const = 0;
155 
159  virtual const std::wstring& getHost() const = 0;
160 
165  virtual std::wstring getPath() const = 0;
166 
171  virtual std::wstring getBaseName() const = 0;
172 
177  virtual const std::wstring& getExtension() const = 0;
178 
182  virtual bool hasQuery() const = 0;
183 
187  virtual const std::wstring& getQuery() const = 0;
188 
196  virtual std::wstring getQuery(const std::wstring& key) const = 0;
197 
201  virtual bool hasFragment() const = 0;
202 
206  virtual const std::wstring& getFragment() const = 0;
207 
215  virtual std::wstring getFragment(const std::wstring &key) const = 0;
216 
217 public:
218  virtual ~URI() = default;
219 
220 protected:
221  URI() = default;
222  URI(const URI&) = default;
223 };
224 
225 
230 namespace URIUtils {
231 
232 
238 PRTX_EXPORTS_API URIPtr createFileURI(const std::wstring& percentEncodedAbsolutePath);
239 
240 
245 PRTX_EXPORTS_API URIPtr createBuiltinURI(const std::wstring& name);
246 
247 
254 PRTX_EXPORTS_API URIPtr createMemoryURI(const uint8_t* ptr, size_t size, const std::wstring& ext);
255 
256 
266 PRTX_EXPORTS_API URIPtr createDataURI(const std::string& mediaType, bool base64, const uint8_t* data, size_t dataSize);
267 
268 
274 PRTX_EXPORTS_API URIPtr createCompositeURI(
275  const URIPtr& nestedURI,
276  const std::wstring& outerScheme,
277  const std::wstring& outerPath,
278  const std::wstring& outerQuery = {},
279  const std::wstring& outerFragment = {}
280 );
281 
282 
289 PRTX_EXPORTS_API URIPtr replaceFilename(const URIPtr& uri, const std::wstring& newFileName);
290 
291 
298 PRTX_EXPORTS_API URIPtr replaceExtension(const URIPtr& uri, const std::wstring& newExtWithSep);
299 
300 
306 PRTX_EXPORTS_API URIPtr addQuery(const URIPtr& uri, const std::wstring& key, const std::wstring& value);
307 
308 
314 PRTX_EXPORTS_API URIPtr addQuery(const URIPtr& uri, const std::map<std::wstring, std::wstring>& queries);
315 
316 
322 PRTX_EXPORTS_API URIPtr addQuery(const URIPtr& uri, const std::wstring& query);
323 
324 
329 PRTX_EXPORTS_API URIPtr removeQuery(const URIPtr& uri);
330 
331 
337 PRTX_EXPORTS_API URIPtr addFragment(const URIPtr& uri, const std::wstring& key, const std::wstring& value);
338 
339 
345 PRTX_EXPORTS_API URIPtr addFragment(const URIPtr& uri, const std::map<std::wstring, std::wstring>& fragments);
346 
347 
353 PRTX_EXPORTS_API URIPtr addFragment(const URIPtr& uri, const std::wstring& fragment);
354 
355 
360 PRTX_EXPORTS_API URIPtr removeFragment(const URIPtr& uri);
361 
362 
369 PRTX_EXPORTS_API void parseMemoryURI(
370  const URIPtr& uri,
371  const uint8_t*& address,
372  size_t& byteCount
373 );
374 
375 
380 PRTX_EXPORTS_API std::string percentEncode(const std::string& s);
381 
382 
387 PRTX_EXPORTS_API std::wstring percentEncode(const std::wstring& s);
388 
389 
394 PRTX_EXPORTS_API std::string percentDecode(const std::string& percentEncodedString);
395 
396 
402 PRTX_EXPORTS_API uint64_t getUniqueId();
403 
404 
405 } // namespace URIUtils
406 
407 
408 } // namespace prtx
409 
410 
411 #ifdef _MSC_VER
412 # pragma warning(pop)
413 #endif
414 
415 
416 #endif /* PRTX_URI_H_ */
URIPtr createFileURI(const std::wstring &percentEncodedAbsolutePath)
URIPtr removeFragment(const URIPtr &uri)
static const std::wstring SCHEME_MEMORY
"memory" scheme, see prtx::URIUtils::createMemoryURI()
Definition: URI.h:64
std::vector< URIPtr > URIPtrVector
vector of shared pointers to prtx::URI
Definition: URI.h:39
static const std::wstring SCHEME_FILE
"file" scheme, e.g. file:/local/file/system/file.ext
Definition: URI.h:61
static const std::wstring DELIM_FRAGMENT_ITEM
fragment item delimiting character &#39;&&#39;
Definition: URI.h:79
std::string percentDecode(const std::string &percentEncodedString)
URIPtr removeQuery(const URIPtr &uri)
static const std::wstring SCHEME_SAMBA
samba "smb" scheme, e.g. smb://host/share syntax
Definition: URI.h:62
static const std::wstring SCHEME_ZIP
"zip" scheme
Definition: URI.h:66
static const std::wstring SCHEME_BUILTIN
"builtin" scheme
Definition: URI.h:68
URIPtr createCompositeURI(const URIPtr &nestedURI, const std::wstring &outerScheme, const std::wstring &outerPath, const std::wstring &outerQuery={}, const std::wstring &outerFragment={})
static const std::wstring DELIM_SCHEME
scheme delimiting character &#39;:&#39;
Definition: URI.h:75
static const std::wstring DELIM_QUERY_ITEM
query item delimiting character &#39;&&#39;
Definition: URI.h:77
The Procedural Runtime eXtension namespace. The prtx namespace contains the tools to extend the Proce...
Definition: AnnotationBuilder.h:35
static const std::wstring SCHEME_DATA
"data" scheme, see http://tools.ietf.org/html/rfc2397
Definition: URI.h:67
std::shared_ptr< URI > URIPtr
shared pointer implementation of prtx::URI
Definition: URI.h:37
void parseMemoryURI(const URIPtr &uri, const uint8_t *&address, size_t &byteCount)
static const std::wstring DELIM_ENTRY
composite/nested URI delimiting character &#39;!&#39;
Definition: URI.h:80
URIPtr createDataURI(const std::string &mediaType, bool base64, const uint8_t *data, size_t dataSize)
uint64_t getUniqueId()
static const std::wstring SCHEME_RPK
rule package "rpk" scheme, see prtx::URIUtils::createCompositeURI()
Definition: URI.h:65
Definition: URI.h:59
URIPtr replaceFilename(const URIPtr &uri, const std::wstring &newFileName)
static const std::wstring SCHEME_UNC
UNC scheme, e.g. \ syntax.
Definition: URI.h:63
URIPtr addFragment(const URIPtr &uri, const std::wstring &key, const std::wstring &value)
std::string percentEncode(const std::string &s)
URIPtr createMemoryURI(const uint8_t *ptr, size_t size, const std::wstring &ext)
static const std::wstring DELIM_FRAGMENT
fragment delimiting character &#39;#&#39;
Definition: URI.h:78
URIPtr addQuery(const URIPtr &uri, const std::wstring &key, const std::wstring &value)
URIPtr replaceExtension(const URIPtr &uri, const std::wstring &newExtWithSep)
URIPtr createBuiltinURI(const std::wstring &name)
static const std::wstring DELIM_QUERY
query delimiting character &#39;?&#39;
Definition: URI.h:76