VTK  9.3.1
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;
68  vtkURIComponent& operator=(const vtkURIComponent&) = default;
69  vtkURIComponent(vtkURIComponent&&) = default;
70  vtkURIComponent& operator=(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 
338  std::string ToString() const;
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
348  friend vtkSmartPointer<vtkURI> MakeUnchecked(vtkURIComponent scheme, vtkURIComponent authority,
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
const vtkURIComponent & GetQuery() const
URI query.
Definition: vtkURI.h:281
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
bool IsFull() const
URI types determination.
Definition: vtkURI.h:313
URI representation.
Definition: vtkURI.h:121
bool IsSameDocRef() const
URI types determination.
Definition: vtkURI.h:315
static constexpr UndefinedTag Undefined
Definition: vtkURI.h:34
bool operator!=(const vtkURIComponent &other) const noexcept
Definition: vtkURI.h:98
const vtkURIComponent & GetPath() const
URI path.
Definition: vtkURI.h:276
const std::string & GetValue() const noexcept
Definition: vtkURI.h:75
Hold a reference to a vtkObjectBase instance.
Definition: vtkMeta.h:23
vtkURIComponent(std::string str)
Default constructor.
Definition: vtkURI.h:45
bool IsDefined() const noexcept
Definition: vtkURI.h:80
bool IsAbsolute() const
URI types determination.
Definition: vtkURI.h:311
vtkURIComponent(const char *str)
Default constructor.
Definition: vtkURI.h:55
bool IsRelative() const
URI types determination.
Definition: vtkURI.h:309
static std::string PercentEncode(const std::string &str)
Calls PercentEncode(str.data(), str.size())
Definition: vtkURI.h:142
a simple class to control print indentation
Definition: vtkIndent.h:28
bool IsReference() const
URI types determination.
Definition: vtkURI.h:307
vtkURIComponent(UndefinedTag)
Constructs an undefined component.
Definition: vtkURI.h:64
const vtkURIComponent & GetScheme() const
URI scheme.
Definition: vtkURI.h:266
static vtkSmartPointer< vtkURI > Parse(const std::string &uri)
Create a new URI from a string.
Definition: vtkURI.h:237
vtkSmartPointer< vtkURI > Clone() const
Definition: vtkURI.h:331
static std::string PercentDecode(const std::string &str)
Calls PercentDecode(str.data(), str.size())
Definition: vtkURI.h:172
const vtkURIComponent & GetAuthority() const
URI authority.
Definition: vtkURI.h:271
bool operator==(const vtkURIComponent &other) const noexcept
Definition: vtkURI.h:93
const vtkURIComponent & GetFragment() const
URI fragment.
Definition: vtkURI.h:286
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
Represent an URI component.
Definition: vtkURI.h:28
bool IsEmpty() const
URI types determination.
Definition: vtkURI.h:321
#define VTK_WRAPEXCLUDE