farm-ng-core
uri.h
Go to the documentation of this file.
1 // Copyright 2022, farm-ng inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include "farm_ng/core/enum/enum.h"
18 
19 namespace farm_ng {
20 
21 /// https://en.wikipedia.org/w/index.php?title=Uniform_Resource_Identifier&oldid=1072892451#Syntax
22 struct Uri {
23  Uri() {}
24 
25  /// Creates Uri.
26  Uri(std::string const& scheme,
27  std::string const& authority,
28  std::string const& path,
29  std::string const& query = "")
31 
32  /// Returns string representation of uri.
33  [[nodiscard]] std::string string() const {
34  if (query.empty()) {
35  return scheme + "://" + authority + "/" + path;
36  }
37  return scheme + "://" + authority + "/" + path + "?" + query;
38  }
39  /// The uri scheme.
40  std::string scheme;
41 
42  /// If scheme is device, then authority is `[robot_name]`.
43  std::string authority;
44 
45  /// if scheme is device, then path is path to underlying sensor such as
46  /// `sensor_rig_name/camera_stream_name`.
47  std::string path;
48 
49  /// If URI is used in component, then query is used to denote inputs or
50  /// outputs.
51  /// For instance: '?in=input_channel_name`.
52  std::string query;
53 
54  friend inline bool operator<(Uri const& lhs, Uri const& rhs) {
55  return lhs.string() < rhs.string();
56  }
57 };
58 } // namespace farm_ng
farm_ng
Definition: backtrace.cpp:102
enum.h
farm_ng::Uri::path
std::string path
if scheme is device, then path is path to underlying sensor such as sensor_rig_name/camera_stream_nam...
Definition: uri.h:47
farm_ng::Uri::string
std::string string() const
Returns string representation of uri.
Definition: uri.h:33
farm_ng::Uri::operator<
friend bool operator<(Uri const &lhs, Uri const &rhs)
Definition: uri.h:54
farm_ng::Uri
https://en.wikipedia.org/w/index.php?title=Uniform_Resource_Identifier&oldid=1072892451#Syntax
Definition: uri.h:22
farm_ng::Uri::authority
std::string authority
If scheme is device, then authority is [robot_name].
Definition: uri.h:43
farm_ng::Uri::scheme
std::string scheme
The uri scheme.
Definition: uri.h:40
farm_ng::Uri::Uri
Uri()
Definition: uri.h:23
farm_ng::Uri::query
std::string query
If URI is used in component, then query is used to denote inputs or outputs. For instance: '?...
Definition: uri.h:52
farm_ng::Uri::Uri
Uri(std::string const &scheme, std::string const &authority, std::string const &path, std::string const &query="")
Creates Uri.
Definition: uri.h:26