Viam C++ SDK current
Loading...
Searching...
No Matches
resource_api.hpp
1#pragma once
2
3#include <string>
4
5#include <viam/sdk/common/proto_convert.hpp>
6
7namespace viam {
8namespace common {
9namespace v1 {
10
11class ResourceName;
12
13}
14} // namespace common
15} // namespace viam
16
17namespace viam {
18namespace sdk {
19
21class API {
22 public:
23 // Choosing to make this a friend rather than exposing public setters for everyone.
24 friend class ResourceConfig;
25
26 static API from_string(std::string api);
27
28 API() = default;
29 API(std::string ns, std::string resource_type, std::string resource_subtype);
30
31 std::string to_string() const;
32
33 const std::string& type_namespace() const;
34 const std::string& resource_type() const;
35 const std::string& resource_subtype() const;
36
37 bool is_component_type();
38 bool is_service_type();
39
40 friend bool operator==(API const& lhs, API const& rhs);
41 friend bool operator<(const API& lhs, const API& rhs);
42
43 friend std::ostream& operator<<(std::ostream& os, const API& v);
44
45 template <typename T>
46 struct traits;
47
48 template <typename T>
49 static API get() {
50 return traits<T>::api();
51 }
52
53 private:
54 std::string namespace_;
55 std::string resource_type_;
56 std::string resource_subtype_;
57};
58
61class Name {
62 public:
63 static Name from_string(std::string name);
64
65 Name(API api, std::string remote_name, std::string name);
66 Name() = default;
67
68 std::string short_name() const;
69 std::string to_string() const;
70
71 const API& api() const;
72 const std::string& name() const;
73 const std::string& remote_name() const;
74
75 friend bool operator==(const Name& lhs, const Name& rhs);
76 friend std::ostream& operator<<(std::ostream& os, const Name& v);
77
78 private:
79 API api_;
80 std::string remote_name_;
81 std::string name_;
82};
83
84namespace proto_convert_details {
85
86template <>
88 void operator()(const Name&, common::v1::ResourceName*) const;
89};
90
91template <>
92struct from_proto_impl<common::v1::ResourceName> {
93 Name operator()(const common::v1::ResourceName*) const;
94};
95
96} // namespace proto_convert_details
97
99 public:
100 RPCSubtype(API api);
101 RPCSubtype(API api, std::string proto_service_name);
102
103 const API& api() const;
104 const std::string& proto_service_name() const;
105
106 friend bool operator==(const RPCSubtype& lhs, const RPCSubtype& rhs);
107
108 private:
109 API api_;
110 std::string proto_service_name_;
111};
112
114 public:
115 ModelFamily(std::string namespace_, std::string family);
116 std::string to_string() const;
117
118 private:
119 std::string namespace_;
120 std::string family_;
121};
122
125class Model {
126 public:
127 std::string to_string() const;
128
129 Model(std::string namespace_, std::string family, std::string model_name);
130 Model(ModelFamily model, std::string model_name);
131 Model();
132
137 static Model from_str(std::string model);
138 friend bool operator==(const Model& lhs, const Model& rhs);
139
140 private:
141 ModelFamily model_family_;
142 std::string model_name_;
143};
144
145} // namespace sdk
146} // namespace viam
147
148template <>
149struct std::hash<::viam::sdk::Name> {
150 size_t operator()(::viam::sdk::Name const& key) const noexcept {
151 return std::hash<std::string>()(key.to_string());
152 }
153};
154
155template <>
156struct std::hash<::viam::sdk::RPCSubtype> {
157 size_t operator()(::viam::sdk::RPCSubtype const& key) const noexcept {
158 const ::viam::sdk::API& api = key.api();
159 std::string hash = api.to_string() + key.proto_service_name();
160 return std::hash<std::string>()(hash);
161 };
162};
163
164template <>
165struct std::hash<::viam::sdk::API> {
166 size_t operator()(const ::viam::sdk::API& key) const noexcept {
167 return std::hash<std::string>()(key.to_string());
168 };
169};
Definition resource_api.hpp:21
Definition resource_api.hpp:113
Defines the namespace_, family, and name for a particular resource model.
Definition resource_api.hpp:125
static Model from_str(std::string model)
Parses a single model string into a Model, using default values for namespace and family if not provi...
A name for specific instances of resources.
Definition resource_api.hpp:61
Definition resource_api.hpp:98
Definition resource.hpp:31
Definition resource_api.hpp:46