Gazebo Common

API Reference

4.5.1
URI.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef IGNITION_COMMON_URI_HH_
18 #define IGNITION_COMMON_URI_HH_
19 
20 #include <memory>
21 #include <optional>
22 #include <string>
23 
24 #include <ignition/common/Export.hh>
26 
27 namespace ignition
28 {
29  namespace common
30  {
31  // Forward declare private data classes.
32  class URIAuthorityPrivate;
33  class URIPathPrivate;
34  class URIQueryPrivate;
35  class URIFragmentPrivate;
36  class URIPrivate;
37 
62  class IGNITION_COMMON_VISIBLE URIAuthority
63  {
65  public: URIAuthority();
66 
69  public: URIAuthority(const URIAuthority &_path);
70 
73  public: explicit URIAuthority(const std::string &_str);
74 
76  public: virtual ~URIAuthority();
77 
79  public: void Clear();
80 
84  public: std::string UserInfo() const;
85 
88  public: void SetUserInfo(const std::string &_userInfo) const;
89 
92  public: std::string Host() const;
93 
96  public: void SetHost(const std::string &_host) const;
97 
100  public: bool EmptyHostValid() const;
101 
106  public: void SetEmptyHostValid(bool _valid) const;
107 
110  public: std::optional<int> Port() const;
111 
113  public: void SetPort(int _port) const;
114 
118  public: bool operator==(const URIAuthority &_auth) const;
119 
122  public: std::string Str() const;
123 
127  public: URIAuthority &operator=(const URIAuthority &_auth);
128 
135  public: static bool Valid(const std::string &_str,
136  bool _emptyHostValid = false);
137 
140  public: bool Valid() const;
141 
148  public: bool Parse(const std::string &_str,
149  bool _emptyHostValid = false);
150 
154  private: std::unique_ptr<URIAuthorityPrivate> dataPtr;
156  };
157 
167  class IGNITION_COMMON_VISIBLE URIPath
168  {
170  public: URIPath();
171 
174  public: URIPath(const URIPath &_path);
175 
178  public: explicit URIPath(const std::string &_str);
179 
181  public: virtual ~URIPath();
182 
184  public: void Clear();
185 
188  public: bool IsAbsolute() const;
189 
195  public: void SetAbsolute(bool _absolute = true);
196 
200  public: void SetRelative();
201 
209  public: void PushFront(const std::string &_part);
210 
219  public: void PushBack(const std::string &_part);
220 
224  public: std::string PopFront();
225 
229  public: std::string PopBack();
230 
234  public: const URIPath &operator/=(const std::string &_part);
235 
240  public: const URIPath operator/(const std::string &_part) const;
241 
245  public: bool operator==(const URIPath &_path) const;
246 
250  public: std::string Str(const std::string &_delim = "/") const;
251 
255  public: URIPath &operator=(const URIPath &_path);
256 
260  public: static bool Valid(const std::string &_str);
261 
264  public: bool Valid() const;
265 
269  public: bool Parse(const std::string &_str);
270 
274  private: std::unique_ptr<URIPathPrivate> dataPtr;
276  };
277 
279  class IGNITION_COMMON_VISIBLE URIQuery
280  {
282  public: URIQuery();
283 
286  public: explicit URIQuery(const std::string &_str);
287 
290  public: URIQuery(const URIQuery &_query);
291 
293  public: virtual ~URIQuery();
294 
296  public: void Clear();
297 
301  public: void Insert(const std::string &_key,
302  const std::string &_value);
303 
307  public: URIQuery &operator=(const URIQuery &_query);
308 
312  public: bool operator==(const URIQuery &_query) const;
313 
318  public: std::string Str(const std::string &_delim = "&") const;
319 
323  public: static bool Valid(const std::string &_str);
324 
327  public: bool Valid() const;
328 
332  public: bool Parse(const std::string &_string);
333 
337  private: std::unique_ptr<URIQueryPrivate> dataPtr;
339  };
340 
342  class IGNITION_COMMON_VISIBLE URIFragment
343  {
345  public: URIFragment();
346 
349  public: explicit URIFragment(const std::string &_str);
350 
353  public: URIFragment(const URIFragment &_fragment);
354 
356  public: virtual ~URIFragment();
357 
359  public: void Clear();
360 
364  public: URIFragment &operator=(const URIFragment &_fragment);
365 
369  public: URIFragment &operator=(const std::string &_fragment);
370 
374  public: bool operator==(const URIFragment &_fragment) const;
375 
378  public: std::string Str() const;
379 
383  public: static bool Valid(const std::string &_str);
384 
387  public: bool Valid() const;
388 
392  public: bool Parse(const std::string &_string);
393 
397  private: std::unique_ptr<URIFragmentPrivate> dataPtr;
399  };
400 
405  // cppcheck-suppress class_X_Y
406  class IGNITION_COMMON_VISIBLE URI
407  {
409  public: URI();
410 
415  public: explicit URI(const std::string &_str,
416  bool _hasAuthority = false);
417 
420  public: URI(const URI &_uri);
421 
423  public: ~URI();
424 
430  public: std::string Str() const;
431 
433  public: void Clear();
434 
437  public: std::string Scheme() const;
438 
441  public: void SetScheme(const std::string &_scheme);
442 
445  public: void SetAuthority(const URIAuthority &_authority);
446 
452  public: std::optional<URIAuthority> Authority() const;
453 
456  public: URIPath &Path();
457 
460  public: const URIPath &Path() const;
461 
464  public: URIQuery &Query();
465 
468  public: const URIQuery &Query() const;
469 
472  public: URIFragment &Fragment();
473 
476  public: const URIFragment &Fragment() const;
477 
481  public: URI &operator=(const URI &_uri);
482 
486  public: bool operator==(const URI &_uri) const;
487 
490  public: bool Valid() const;
491 
495  public: static bool Valid(const std::string &_str);
496 
504  public: bool Parse(const std::string &_str);
505 
509  private: std::unique_ptr<URIPrivate> dataPtr;
511  };
512  }
513 }
514 #endif
bool IsAbsolute() const
Returns whether the path is absolute or not.
void SetEmptyHostValid(bool _valid) const
Set whether an empty host is considered valid. This should only be set to true if the corresponding U...
void Clear()
Remove all parts of the authority.
const URIPath operator/(const std::string &_part) const
Get the current path with the _part added to the end.
bool operator==(const URIPath &_path) const
Return true if the two paths match.
Forward declarations for the common classes.
STL class.
std::string Str(const std::string &_delim="&") const
Get the query as a string.
void SetRelative()
Set the path to be relative.
void SetPort(int _port) const
Set the port number.
URIAuthority & operator=(const URIAuthority &_auth)
Assignment operator.
void SetAuthority(const URIAuthority &_authority)
Set the URI's authority.
URIQuery & operator=(const URIQuery &_query)
Assignment operator.
std::string Scheme() const
Get the URI's scheme.
void Clear()
Remove all components of the URI.
void Clear()
Remove all values of the query.
bool Parse(const std::string &_string)
Parse a string as URIQuery.
std::string Str() const
Get the complete authoriy as a string.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: SuppressWarning.hh:64
std::string PopFront()
Remove the part that's in the front of this path and return it.
bool Valid() const
Validate this URI.
virtual ~URIFragment()
Destructor.
bool Valid() const
Check if this is a valid URI query.
std::string PopBack()
Remove the part that's in the back of this path and return it.
void SetAbsolute(bool _absolute=true)
Set whether the path is to be treated absolute or not.
bool operator==(const URI &_uri) const
Return true if the two URIs match.
A URI path contains a sequence of segments separated by /. The path may be empty in a valid URI....
Definition: URI.hh:167
std::string Host() const
Get the host.
void PushBack(const std::string &_part)
Push a new part onto the back of this path.
A complete URI which has the following components:
Definition: URI.hh:406
The fragment component of a URI.
Definition: URI.hh:342
bool operator==(const URIQuery &_query) const
Return true if the two queries contain the same values.
std::optional< int > Port() const
Get the port.
bool Parse(const std::string &_str)
Parse a string as URIPath.
void SetScheme(const std::string &_scheme)
Set the URI's scheme.
std::string UserInfo() const
Get the user information.
bool Valid() const
Check if this is a valid URI fragment.
const URIPath & operator/=(const std::string &_part)
Compound assignment operator.
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
URIFragment & operator=(const URIFragment &_fragment)
Assignment operator.
void Insert(const std::string &_key, const std::string &_value)
Get this query with a new _key=_value pair added.
The query component of a URI.
Definition: URI.hh:279
std::optional< URIAuthority > Authority() const
Get a copy of the URI's authority. If the authority has no value (as opposed to being empty),...
bool Parse(const std::string &_string)
Parse a string as URIFragment.
virtual ~URIAuthority()
Destructor.
URI & operator=(const URI &_uri)
Assignment operator.
void Clear()
Remove all parts of the path.
std::string Str() const
Get the fragment as a string.
Definition: URI.hh:62
void SetHost(const std::string &_host) const
Set the host.
URIFragment & Fragment()
Get a mutable version of the fragment component.
URIPath & Path()
Get a mutable version of the path component.
URIQuery & Query()
Get a mutable version of the query component.
bool operator==(const URIAuthority &_auth) const
Return true if the two authorities match.
std::string Str() const
Get the URI as a string, which has the form:
virtual ~URIQuery()
Destructor.
virtual ~URIPath()
Destructor.
URIPath & operator=(const URIPath &_path)
Assignment operator.
void PushFront(const std::string &_part)
Push a new part onto the front of this path.
bool Valid() const
Return true if this is a valid path.
bool Parse(const std::string &_str, bool _emptyHostValid=false)
Parse a string as URIAuthority.
bool Valid() const
Return true if this is a valid authority.
void Clear()
Remove all values of the fragment.
void SetUserInfo(const std::string &_userInfo) const
Set the user information.
URI()
Default constructor.
bool Parse(const std::string &_str)
Parse a string as URI. If there's no authority (i.e. Authority().has_value() == false),...
std::string Str(const std::string &_delim="/") const
Get the path as a string.
bool operator==(const URIFragment &_fragment) const
Return true if the two fragments contain the same values.
bool EmptyHostValid() const
True if an empty host is considered valid.