Gazebo Common

API Reference

4.8.1
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 
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
Definition: gz/common/URI.hh:64
std::string UserInfo() const
Get the user information.
void SetHost(const std::string &_host) const
Set the host.
bool operator==(const URIAuthority &_auth) const
Return true if the two authorities match.
URIAuthority(const std::string &_str)
Construct a URIAuthority object from a string.
void SetPort(int _port) const
Set the port number.
void SetEmptyHostValid(bool _valid) const
Set whether an empty host is considered valid. This should only be set to true if the corresponding U...
bool Valid() const
Return true if this is a valid authority.
URIAuthority & operator=(const URIAuthority &_auth)
Assignment operator.
URIAuthority(const URIAuthority &_path)
Copy constructor.
bool Parse(const std::string &_str, bool _emptyHostValid=false)
Parse a string as URIAuthority.
std::optional< int > Port() const
Get the port.
static bool Valid(const std::string &_str, bool _emptyHostValid=false)
Return true if the string is a valid path.
void Clear()
Remove all parts of the authority.
std::string Str() const
Get the complete authoriy as a string.
bool EmptyHostValid() const
True if an empty host is considered valid.
void SetUserInfo(const std::string &_userInfo) const
Set the user information.
virtual ~URIAuthority()
Destructor.
std::string Host() const
Get the host.
The fragment component of a URI.
Definition: gz/common/URI.hh:344
bool Valid() const
Check if this is a valid URI fragment.
URIFragment(const std::string &_str)
Construct a URIFragment object from a string.
virtual ~URIFragment()
Destructor.
URIFragment & operator=(const URIFragment &_fragment)
Assignment operator.
bool Parse(const std::string &_string)
Parse a string as URIFragment.
static bool Valid(const std::string &_str)
Check if a string is a valid URI fragment.
void Clear()
Remove all values of the fragment.
std::string Str() const
Get the fragment as a string.
bool operator==(const URIFragment &_fragment) const
Return true if the two fragments contain the same values.
URIFragment & operator=(const std::string &_fragment)
Assignment operator.
URIFragment(const URIFragment &_fragment)
Copy constructor.
A URI path contains a sequence of segments separated by /. The path may be empty in a valid URI....
Definition: gz/common/URI.hh:169
std::string PopBack()
Remove the part that's in the back of this path and return it.
bool operator==(const URIPath &_path) const
Return true if the two paths match.
URIPath & operator=(const URIPath &_path)
Assignment operator.
virtual ~URIPath()
Destructor.
const URIPath & operator/=(const std::string &_part)
Compound assignment operator.
URIPath(const URIPath &_path)
Copy constructor.
const URIPath operator/(const std::string &_part) const
Get the current path with the _part added to the end.
bool Valid() const
Return true if this is a valid path.
void SetRelative()
Set the path to be relative.
void PushFront(const std::string &_part)
Push a new part onto the front of this path.
void SetAbsolute(bool _absolute=true)
Set whether the path is to be treated absolute or not.
std::string Str(const std::string &_delim="/") const
Get the path as a string.
static bool Valid(const std::string &_str)
Return true if the string is a valid path.
void Clear()
Remove all parts of the path.
URIPath(const std::string &_str)
Construct a URIPath object from a string.
std::string PopFront()
Remove the part that's in the front of this path and return it.
void PushBack(const std::string &_part)
Push a new part onto the back of this path.
bool IsAbsolute() const
Returns whether the path is absolute or not.
bool Parse(const std::string &_str)
Parse a string as URIPath.
The query component of a URI.
Definition: gz/common/URI.hh:281
URIQuery(const std::string &_str)
Construct a URIQuery object from a string.
void Insert(const std::string &_key, const std::string &_value)
Get this query with a new _key=_value pair added.
bool Valid() const
Check if this is a valid URI query.
URIQuery & operator=(const URIQuery &_query)
Assignment operator.
bool Parse(const std::string &_string)
Parse a string as URIQuery.
static bool Valid(const std::string &_str)
Check if a string is a valid URI query.
void Clear()
Remove all values of the query.
bool operator==(const URIQuery &_query) const
Return true if the two queries contain the same values.
std::string Str(const std::string &_delim="&") const
Get the query as a string.
URIQuery(const URIQuery &_query)
Copy constructor.
virtual ~URIQuery()
Destructor.
A complete URI which has the following components:
Definition: gz/common/URI.hh:408
void SetAuthority(const URIAuthority &_authority)
Set the URI's authority.
const URIQuery & Query() const
Get a const reference of the query component.
void SetScheme(const std::string &_scheme)
Set the URI's scheme.
URIQuery & Query()
Get a mutable version of the query component.
bool Valid() const
Validate this URI.
URI & operator=(const URI &_uri)
Assignment operator.
const URIPath & Path() const
Get a const reference of the path component.
URIPath & Path()
Get a mutable version of the path component.
URI(const URI &_uri)
Copy constructor.
URI()
Default constructor.
bool operator==(const URI &_uri) const
Return true if the two URIs match.
static bool Valid(const std::string &_str)
Validate a string as URI.
void Clear()
Remove all components of the URI.
std::string Str() const
Get the URI as a string, which has the form:
URIFragment & Fragment()
Get a mutable version of the fragment component.
std::optional< URIAuthority > Authority() const
Get a copy of the URI's authority. If the authority has no value (as opposed to being empty),...
std::string Scheme() const
Get the URI's scheme.
const URIFragment & Fragment() const
Get a const reference of the fragment component.
bool Parse(const std::string &_str)
Parse a string as URI. If there's no authority (i.e. Authority().has_value() == false),...
URI(const std::string &_str, bool _hasAuthority=false)
Default constructor.
#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
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: gz/common/SuppressWarning.hh:68
Forward declarations for the common classes.