Gazebo Common

API Reference

4.7.0
gz/common/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 <gz/common/config.hh>
25 #include <gz/common/Export.hh>
27 
28 namespace ignition
29 {
30  namespace common
31  {
32  // Forward declare private data classes.
33  class URIAuthorityPrivate;
34  class URIPathPrivate;
35  class URIQueryPrivate;
36  class URIFragmentPrivate;
37  class URIPrivate;
38 
63  class IGNITION_COMMON_VISIBLE URIAuthority
64  {
66  public: URIAuthority();
67 
70  public: URIAuthority(const URIAuthority &_path);
71 
74  public: explicit URIAuthority(const std::string &_str);
75 
77  public: virtual ~URIAuthority();
78 
80  public: void Clear();
81 
85  public: std::string UserInfo() const;
86 
89  public: void SetUserInfo(const std::string &_userInfo) const;
90 
93  public: std::string Host() const;
94 
97  public: void SetHost(const std::string &_host) const;
98 
101  public: bool EmptyHostValid() const;
102 
107  public: void SetEmptyHostValid(bool _valid) const;
108 
111  public: std::optional<int> Port() const;
112 
114  public: void SetPort(int _port) const;
115 
119  public: bool operator==(const URIAuthority &_auth) const;
120 
123  public: std::string Str() const;
124 
128  public: URIAuthority &operator=(const URIAuthority &_auth);
129 
136  public: static bool Valid(const std::string &_str,
137  bool _emptyHostValid = false);
138 
141  public: bool Valid() const;
142 
149  public: bool Parse(const std::string &_str,
150  bool _emptyHostValid = false);
151 
155  private: std::unique_ptr<URIAuthorityPrivate> dataPtr;
157  };
158 
168  class IGNITION_COMMON_VISIBLE URIPath
169  {
171  public: URIPath();
172 
175  public: URIPath(const URIPath &_path);
176 
179  public: explicit URIPath(const std::string &_str);
180 
182  public: virtual ~URIPath();
183 
185  public: void Clear();
186 
189  public: bool IsAbsolute() const;
190 
196  public: void SetAbsolute(bool _absolute = true);
197 
201  public: void SetRelative();
202 
210  public: void PushFront(const std::string &_part);
211 
220  public: void PushBack(const std::string &_part);
221 
225  public: std::string PopFront();
226 
230  public: std::string PopBack();
231 
235  public: const URIPath &operator/=(const std::string &_part);
236 
241  public: const URIPath operator/(const std::string &_part) const;
242 
246  public: bool operator==(const URIPath &_path) const;
247 
251  public: std::string Str(const std::string &_delim = "/") const;
252 
256  public: URIPath &operator=(const URIPath &_path);
257 
261  public: static bool Valid(const std::string &_str);
262 
265  public: bool Valid() const;
266 
270  public: bool Parse(const std::string &_str);
271 
275  private: std::unique_ptr<URIPathPrivate> dataPtr;
277  };
278 
280  class IGNITION_COMMON_VISIBLE URIQuery
281  {
283  public: URIQuery();
284 
287  public: explicit URIQuery(const std::string &_str);
288 
291  public: URIQuery(const URIQuery &_query);
292 
294  public: virtual ~URIQuery();
295 
297  public: void Clear();
298 
302  public: void Insert(const std::string &_key,
303  const std::string &_value);
304 
308  public: URIQuery &operator=(const URIQuery &_query);
309 
313  public: bool operator==(const URIQuery &_query) const;
314 
319  public: std::string Str(const std::string &_delim = "&") const;
320 
324  public: static bool Valid(const std::string &_str);
325 
328  public: bool Valid() const;
329 
333  public: bool Parse(const std::string &_string);
334 
338  private: std::unique_ptr<URIQueryPrivate> dataPtr;
340  };
341 
343  class IGNITION_COMMON_VISIBLE URIFragment
344  {
346  public: URIFragment();
347 
350  public: explicit URIFragment(const std::string &_str);
351 
354  public: URIFragment(const URIFragment &_fragment);
355 
357  public: virtual ~URIFragment();
358 
360  public: void Clear();
361 
365  public: URIFragment &operator=(const URIFragment &_fragment);
366 
370  public: URIFragment &operator=(const std::string &_fragment);
371 
375  public: bool operator==(const URIFragment &_fragment) const;
376 
379  public: std::string Str() const;
380 
384  public: static bool Valid(const std::string &_str);
385 
388  public: bool Valid() const;
389 
393  public: bool Parse(const std::string &_string);
394 
398  private: std::unique_ptr<URIFragmentPrivate> dataPtr;
400  };
401 
406  // cppcheck-suppress class_X_Y
407  class IGNITION_COMMON_VISIBLE URI
408  {
410  public: URI();
411 
416  public: explicit URI(const std::string &_str,
417  bool _hasAuthority = false);
418 
421  public: URI(const URI &_uri);
422 
424  public: ~URI();
425 
431  public: std::string Str() const;
432 
434  public: void Clear();
435 
438  public: std::string Scheme() const;
439 
442  public: void SetScheme(const std::string &_scheme);
443 
446  public: void SetAuthority(const URIAuthority &_authority);
447 
453  public: std::optional<URIAuthority> Authority() const;
454 
457  public: URIPath &Path();
458 
461  public: const URIPath &Path() const;
462 
465  public: URIQuery &Query();
466 
469  public: const URIQuery &Query() const;
470 
473  public: URIFragment &Fragment();
474 
477  public: const URIFragment &Fragment() const;
478 
482  public: URI &operator=(const URI &_uri);
483 
487  public: bool operator==(const URI &_uri) const;
488 
491  public: bool Valid() const;
492 
496  public: static bool Valid(const std::string &_str);
497 
505  public: bool Parse(const std::string &_str);
506 
510  private: std::unique_ptr<URIPrivate> dataPtr;
512  };
513  }
514 }
515 #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.
#define IGN_COMMON_WARN_IGNORE__DLL_INTERFACE_MISSING
Microsoft Visual Studio does not automatically export the interface information for member variables ...
Definition: gz/common/SuppressWarning.hh:65
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.
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: gz/common/URI.hh:168
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: gz/common/URI.hh:407
The fragment component of a URI.
Definition: gz/common/URI.hh:343
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.
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: gz/common/URI.hh:280
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: gz/common/URI.hh:63
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.
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
bool EmptyHostValid() const
True if an empty host is considered valid.