Ignition Common

API Reference

4.4.0
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
The query component of a URI.
Definition: URI.hh:279
#define IGN_COMMON_WARN_RESUME__DLL_INTERFACE_MISSING
Definition: SuppressWarning.hh:67
STL class.
A URI path contains a sequence of segments separated by /. The path may be empty in a valid URI...
Definition: URI.hh:167
A complete URI which has the following components:
Definition: URI.hh:406
The fragment component of a URI.
Definition: URI.hh:342
Definition: URI.hh:62
Forward declarations for the common classes.
#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