VTK  9.3.0
vtkURI.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkURI_h
4 #define vtkURI_h
5 
6 #include "vtkIOCoreModule.h" // For export macro
7 #include "vtkObject.h"
8 #include "vtkSmartPointer.h" // For vtkSmartPointer
9 #include "vtkWrappingHints.h" // For VTK_WRAPEXCLUDE
10 
11 #include <cstdlib> // for std::size_t
12 #include <memory> // for std::unique_ptr
13 #include <string> // for std::string
14 
15 VTK_ABI_NAMESPACE_BEGIN
16 
28 class VTKIOCORE_EXPORT vtkURIComponent
29 {
30 public:
31  struct UndefinedTag
32  {
33  };
34  static constexpr UndefinedTag Undefined{};
35 
39  vtkURIComponent() = default;
40 
46  : Value{ std::move(str) }
47  , Defined{ true }
48  {
49  }
50 
55  vtkURIComponent(const char* str)
56  : Value{ str }
57  , Defined{ true }
58  {
59  }
60 
65 
66  ~vtkURIComponent() = default;
67  vtkURIComponent(const vtkURIComponent&) = default;
71 
75  const std::string& GetValue() const noexcept { return this->Value; }
76 
80  bool IsDefined() const noexcept { return this->Defined; }
81 
85  explicit operator bool() const noexcept { return this->Defined; }
86 
88 
93  bool operator==(const vtkURIComponent& other) const noexcept
94  {
95  return this->Value == other.Value && this->Defined == other.Defined;
96  }
97 
98  bool operator!=(const vtkURIComponent& other) const noexcept { return !(*this == other); }
100 
101 private:
102  std::string Value;
103  bool Defined = false;
104 };
105 
121 class VTKIOCORE_EXPORT vtkURI final : public vtkObject
122 {
123 public:
124  vtkTypeMacro(vtkURI, vtkObject);
125  void PrintSelf(ostream& os, vtkIndent indent) override;
126 
134  static vtkURI* New();
135 
143  {
144  return PercentEncode(str.data(), str.size());
145  }
146 
164  static std::string PercentEncode(const char* str, std::size_t size);
165 
173  {
174  return PercentDecode(str.data(), str.size());
175  }
176 
189  static std::string PercentDecode(const char* str, std::size_t size);
190 
219 
227  static vtkSmartPointer<vtkURI> Clone(const vtkURI* other);
228 
238  {
239  return Parse(uri.data(), uri.size());
240  }
241 
249  static vtkSmartPointer<vtkURI> Parse(const char* uri, std::size_t size);
250 
261  static vtkSmartPointer<vtkURI> Resolve(const vtkURI* baseURI, const vtkURI* uri);
262 
266  const vtkURIComponent& GetScheme() const { return this->Scheme; }
267 
271  const vtkURIComponent& GetAuthority() const { return this->Authority; }
272 
276  const vtkURIComponent& GetPath() const { return this->Path; }
277 
281  const vtkURIComponent& GetQuery() const { return this->Query; }
282 
286  const vtkURIComponent& GetFragment() const { return this->Fragment; }
287 
289 
307  bool IsReference() const { return this->IsRelative() || this->IsFull(); }
308 
309  bool IsRelative() const { return !this->Scheme; }
310 
311  bool IsAbsolute() const { return this->Scheme && !this->Fragment; }
312 
313  bool IsFull() const { return this->Scheme.IsDefined(); }
314 
315  bool IsSameDocRef() const
316  {
317  return !this->Scheme && !this->Authority && this->Path.GetValue().empty() && !this->Query &&
318  this->Fragment;
319  }
320 
321  bool IsEmpty() const
322  {
323  return !this->Scheme && !this->Authority && this->Path.GetValue().empty() && !this->Query &&
324  !this->Fragment;
325  }
327 
331  vtkSmartPointer<vtkURI> Clone() const { return vtkURI::Clone(this); }
332 
339 
340 private:
344  static vtkSmartPointer<vtkURI> MakeUnchecked(vtkURIComponent scheme, vtkURIComponent authority,
345  vtkURIComponent path, vtkURIComponent query, vtkURIComponent fragment);
346 
347  // These functions are factories and need write access to this class
349  vtkURIComponent path, vtkURIComponent query, vtkURIComponent fragment);
350  friend vtkSmartPointer<vtkURI> Clone(const vtkURI* other);
351 
352  vtkURI() = default;
353  ~vtkURI() override = default;
354  vtkURI(const vtkURI&) = delete;
355  vtkURI& operator=(const vtkURI&) = delete;
356 
357  vtkURIComponent Scheme{};
358  vtkURIComponent Authority{};
359  vtkURIComponent Path{ "" }; // path is defined but empty by default
360  vtkURIComponent Query{};
361  vtkURIComponent Fragment{};
362 };
363 
364 VTK_ABI_NAMESPACE_END
365 
366 #endif
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
Hold a reference to a vtkObjectBase instance.
Represent an URI component.
Definition: vtkURI.h:29
~vtkURIComponent()=default
bool operator!=(const vtkURIComponent &other) const noexcept
Definition: vtkURI.h:98
vtkURIComponent & operator=(vtkURIComponent &&)=default
vtkURIComponent()=default
Default constructor.
vtkURIComponent(UndefinedTag)
Constructs an undefined component.
Definition: vtkURI.h:64
bool IsDefined() const noexcept
Definition: vtkURI.h:80
const std::string & GetValue() const noexcept
Definition: vtkURI.h:75
vtkURIComponent(vtkURIComponent &&)=default
static constexpr UndefinedTag Undefined
Definition: vtkURI.h:34
vtkURIComponent & operator=(const vtkURIComponent &)=default
vtkURIComponent(const vtkURIComponent &)=default
bool operator==(const vtkURIComponent &other) const noexcept
Definition: vtkURI.h:93
vtkURIComponent(const char *str)
Default constructor.
Definition: vtkURI.h:55
vtkURIComponent(std::string str)
Default constructor.
Definition: vtkURI.h:45
URI representation.
Definition: vtkURI.h:122
const vtkURIComponent & GetQuery() const
URI query.
Definition: vtkURI.h:281
static std::string PercentDecode(const std::string &str)
Calls PercentDecode(str.data(), str.size())
Definition: vtkURI.h:172
static std::string PercentEncode(const char *str, std::size_t size)
Encode a string into an URI compatible, percent-encoded, string.
const vtkURIComponent & GetScheme() const
URI scheme.
Definition: vtkURI.h:266
bool IsEmpty() const
URI types determination.
Definition: vtkURI.h:321
std::string ToString() const
Contruct the string representation of the URI.
bool IsSameDocRef() const
URI types determination.
Definition: vtkURI.h:315
const vtkURIComponent & GetPath() const
URI path.
Definition: vtkURI.h:276
static vtkSmartPointer< vtkURI > Resolve(const vtkURI *baseURI, const vtkURI *uri)
Resolve an URI from a base URI.
static vtkURI * New()
Contruct a new vtkURI.
static vtkSmartPointer< vtkURI > Parse(const char *uri, std::size_t size)
Create a new URI from a string.
bool IsAbsolute() const
URI types determination.
Definition: vtkURI.h:311
bool IsReference() const
URI types determination.
Definition: vtkURI.h:307
static vtkSmartPointer< vtkURI > Parse(const std::string &uri)
Create a new URI from a string.
Definition: vtkURI.h:237
const vtkURIComponent & GetAuthority() const
URI authority.
Definition: vtkURI.h:271
bool IsFull() const
URI types determination.
Definition: vtkURI.h:313
static std::string PercentEncode(const std::string &str)
Calls PercentEncode(str.data(), str.size())
Definition: vtkURI.h:142
static VTK_WRAPEXCLUDE vtkSmartPointer< vtkURI > Make(vtkURIComponent scheme=vtkURIComponent::Undefined, vtkURIComponent authority=vtkURIComponent::Undefined, vtkURIComponent path="", vtkURIComponent query=vtkURIComponent::Undefined, vtkURIComponent fragment=vtkURIComponent::Undefined)
Create a new vtkURI with specified components.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
const vtkURIComponent & GetFragment() const
URI fragment.
Definition: vtkURI.h:286
bool IsRelative() const
URI types determination.
Definition: vtkURI.h:309
friend vtkSmartPointer< vtkURI > MakeUnchecked(vtkURIComponent scheme, vtkURIComponent authority, vtkURIComponent path, vtkURIComponent query, vtkURIComponent fragment)
friend vtkSmartPointer< vtkURI > Clone(const vtkURI *other)
static vtkSmartPointer< vtkURI > Clone(const vtkURI *other)
Clone a vtkURI.
static std::string PercentDecode(const char *str, std::size_t size)
Decode percent-encoded values from given string.
vtkSmartPointer< vtkURI > Clone() const
Definition: vtkURI.h:331
@ size
Definition: vtkX3D.h:253
@ string
Definition: vtkX3D.h:490
#define VTK_WRAPEXCLUDE