Uri.hpp
Go to the documentation of this file.
1 // @formatter:off
2 //
3 // Balau core C++ library
4 //
5 // Copyright (C) 2008 Bora Software (contact@borasoftware.com)
6 //
7 // Licensed under the Boost Software License - Version 1.0 - August 17th, 2003.
8 // See the LICENSE file for the full license text.
9 //
10 
16 
17 #ifndef COM_BORA_SOFTWARE__BALAU_RESOURCE__URI
18 #define COM_BORA_SOFTWARE__BALAU_RESOURCE__URI
19 
20 #include <Balau/Dev/Assert.hpp>
22 #include <Balau/Type/StdTypes.hpp>
23 
24 #include <memory>
25 
26 namespace Balau::Resource {
27 
28 class Uri;
29 class ByteReadResource;
30 class ByteWriteResource;
31 class Utf8To32ReadResource;
32 class Utf32To8WriteResource;
33 
44  public: virtual bool hasNext() const = 0;
45 
51  public: virtual std::unique_ptr<Uri> next() = 0;
52 
56  public: virtual ~RecursiveUriIterator() = default;
57 
63 // public: virtual bool operator == (const RecursiveUriIterator & rhs) const = 0;
64 
70 // public: virtual RecursiveUriIterator operator ++(const RecursiveUriIterator & rhs) const = 0;
71 
77 // public: virtual bool operator == (const RecursiveUriIterator & rhs) const = 0;
78 
79 };
80 
84 class UriIterator {
91  public: virtual bool hasNext() const = 0;
92 
98  public: virtual std::unique_ptr<Uri> next() = 0;
99 
103  public: virtual ~UriIterator() = default;
104 
110 // public: virtual bool operator == (const UriIterator & rhs) const = 0;
111 
117 // public: virtual RecursiveUriIterator operator ++(const UriIterator & rhs) const = 0;
118 
124 // public: virtual bool operator == (const UriIterator & rhs) const = 0;
125 
126 };
127 
131 class Uri {
137  public: virtual std::unique_ptr<Uri> clone() const = 0;
138 
144  public: std::shared_ptr<Uri> cloneToShared() const {
145  return clone();
146  }
147 
153  public: virtual std::unique_ptr<Uri> append(const std::string & pathComponent) const = 0;
154 
172  public: virtual std::unique_ptr<Uri> resolve(std::string_view path) const = 0;
173 
179  public: virtual bool isRegularDirectory() const = 0;
180 
186  public: virtual bool isRegularFile() const = 0;
187 
193  public: virtual std::string toUriString() const = 0;
194 
201  public: virtual std::string toRawString() const = 0;
202 
208  public: virtual size_t hashcode() const noexcept = 0;
209 
213  public: virtual bool canReadFrom() const = 0;
214 
218  public: virtual bool canWriteTo() const = 0;
219 
226  public: virtual std::unique_ptr<ByteReadResource> byteReadResource() const = 0;
227 
234  public: virtual std::unique_ptr<Utf8To32ReadResource> utf8To32ReadResource() const = 0;
235 
242  public: virtual std::unique_ptr<ByteWriteResource> byteWriteResource() = 0;
243 
250  public: virtual std::unique_ptr<Utf32To8WriteResource> utf32To8WriteResource() = 0;
251 
255  public: virtual bool isRecursivelyIterable() const = 0;
256 
260  public: virtual bool isIterable() const = 0;
261 
267  public: virtual std::unique_ptr<RecursiveUriIterator> recursiveIterator() const = 0;
268 
274  public: virtual std::unique_ptr<UriIterator> iterator() const = 0;
275 
281  public: virtual bool operator == (const Uri & rhs) const = 0;
282 
286  public: virtual ~Uri() = default;
287 
293  public: virtual void dispatch(UriDispatcher & visitor) const = 0;
294 };
295 
301 inline std::unique_ptr<Uri> operator / (const std::unique_ptr<Uri> & uri, const std::string & pathComponent) {
302  return uri->append(pathComponent);
303 }
304 
312 inline std::string toString(const Uri & uri) {
313  return uri.toRawString();
314 }
315 
322 void fromString(std::unique_ptr<Uri> & uri, std::string_view value);
323 
330 inline void fromString(std::shared_ptr<Uri> & uri, std::string_view value) {
331  std::unique_ptr<Uri> ptr;
332  fromString(ptr, value);
333  uri = std::shared_ptr<Uri>(std::move(ptr));
334 }
335 
342 inline void fromString(std::shared_ptr<const Uri> & uri, std::string_view value) {
343  std::unique_ptr<Uri> ptr;
344  fromString(ptr, value);
345  uri = std::shared_ptr<const Uri>(std::move(ptr));
346 }
347 
348 } // namespace Balau::Resource
349 
350 #endif // COM_BORA_SOFTWARE__BALAU_RESOURCE__URI
virtual std::unique_ptr< Uri > next()=0
Get the next item.
bool operator==(const UriComponents &lhs, const UriComponents &rhs)
Returns true if the two URI component instances are equal.
Definition: UriComponents.hpp:335
virtual ~RecursiveUriIterator()=default
Destroy the iterator instance.
void fromString(File &destination, std::string_view value)
Overwrite the supplied file URI by assignment by converting the supplied UTF-8 string to a file URI...
Definition: File.hpp:733
An abstract universal resource identifier.
Definition: Uri.hpp:131
virtual bool hasNext() const =0
Returns true if there is another item available in the iterator.
The unified resource class hierarchy.
Definition: ByteReadResource.hpp:24
An abstract read iterator that iterates recursively.
Definition: Uri.hpp:37
virtual std::string toRawString() const =0
Get a string representing the raw URI.
Core includes, typedefs and functions.
Balau::U8String< AllocatorT > toString(const File &file)
Print the file URI as a UTF-8 string.
Definition: File.hpp:724
Assertion utilities for development purposes.
std::shared_ptr< Uri > cloneToShared() const
Clone the concrete Uri to a shared pointer.
Definition: Uri.hpp:144
An abstract read iterator.
Definition: Uri.hpp:84
Dispatcher interface for URIs.
Visitor interface for URIs.
Definition: UriDispatcher.hpp:32
std::unique_ptr< Uri > operator/(const std::unique_ptr< Uri > &uri, const std::string &pathComponent)
Appends the path component to the supplied URI, returning a new URI.
Definition: Uri.hpp:301