Skip to content

Commit ed71092

Browse files
lia-viamgabegottlobstuqdog
authored
Rsdk 11031 (#480)
Co-authored-by: gabegottlob <[email protected]> Co-authored-by: Gabriel Gottlob <[email protected]> Co-authored-by: Ethan <[email protected]>
1 parent b35da5d commit ed71092

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/viam/sdk/resource/resource_api.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,28 @@ const API& RPCSubtype::api() const {
191191
ModelFamily::ModelFamily(std::string namespace_, std::string family)
192192
: namespace_(std::move(namespace_)), family_(std::move(family)) {}
193193

194+
const std::string& ModelFamily::get_namespace() const {
195+
return namespace_;
196+
}
197+
198+
const std::string& ModelFamily::family() const {
199+
return family_;
200+
}
201+
194202
Model::Model(ModelFamily model_family, std::string model_name)
195203
: model_family_(std::move(model_family)), model_name_(std::move(model_name)) {}
196204

197205
Model::Model(std::string namespace_, std::string family, std::string model_name)
198206
: Model(ModelFamily(std::move(namespace_), std::move(family)), std::move(model_name)) {}
199207

208+
const ModelFamily& Model::model_family() const {
209+
return model_family_;
210+
}
211+
212+
const std::string& Model::model_name() const {
213+
return model_name_;
214+
}
215+
200216
Model Model::from_str(std::string model) {
201217
if (std::regex_match(model, MODEL_REGEX)) {
202218
std::vector<std::string> model_parts;

src/viam/sdk/resource/resource_api.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ class RPCSubtype {
113113
class ModelFamily {
114114
public:
115115
ModelFamily(std::string namespace_, std::string family);
116+
117+
const std::string& get_namespace() const;
118+
const std::string& family() const;
119+
116120
std::string to_string() const;
117121

118122
private:
@@ -124,12 +128,15 @@ class ModelFamily {
124128
/// @brief Defines the namespace_, family, and name for a particular resource model.
125129
class Model {
126130
public:
127-
std::string to_string() const;
128-
129131
Model(std::string namespace_, std::string family, std::string model_name);
130132
Model(ModelFamily model, std::string model_name);
131133
Model();
132134

135+
const ModelFamily& model_family() const;
136+
const std::string& model_name() const;
137+
138+
std::string to_string() const;
139+
133140
/// @brief Parses a single model string into a Model, using default values for namespace and
134141
/// family if not provided.
135142
///

src/viam/sdk/tests/test_resource.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,32 @@ BOOST_AUTO_TEST_CASE(test_name) {
7777
BOOST_AUTO_TEST_CASE(test_model) {
7878
ModelFamily mf("ns", "mf");
7979
BOOST_CHECK_EQUAL(mf.to_string(), "ns:mf");
80+
BOOST_CHECK_EQUAL(mf.get_namespace(), "ns");
81+
BOOST_CHECK_EQUAL(mf.family(), "mf");
8082

8183
Model model1(mf, "model1");
8284
BOOST_CHECK_EQUAL(model1.to_string(), "ns:mf:model1");
85+
BOOST_CHECK_EQUAL(model1.model_family().to_string(), "ns:mf");
86+
BOOST_CHECK_EQUAL(model1.model_name(), "model1");
8387
Model model2("ns", "mf", "model2");
8488
BOOST_CHECK_EQUAL(model2.to_string(), "ns:mf:model2");
89+
BOOST_CHECK_EQUAL(model2.model_family().to_string(), "ns:mf");
90+
BOOST_CHECK_EQUAL(model2.model_name(), "model2");
8591

8692
Model model3 = Model::from_str("ns:mf:model3");
8793
BOOST_CHECK_EQUAL(model3.to_string(), "ns:mf:model3");
94+
BOOST_CHECK_EQUAL(model3.model_family().to_string(), "ns:mf");
95+
BOOST_CHECK_EQUAL(model3.model_name(), "model3");
8896
Model model4 = Model::from_str("model4");
8997
BOOST_CHECK_EQUAL(model4.to_string(), "rdk:builtin:model4");
98+
BOOST_CHECK_EQUAL(model4.model_family().to_string(), "rdk:builtin");
99+
BOOST_CHECK_EQUAL(model4.model_name(), "model4");
90100

91101
ModelFamily empty("", "");
92102
Model model5(empty, "model5");
93103
BOOST_CHECK_EQUAL(model5.to_string(), "model5");
104+
BOOST_CHECK_EQUAL(model5.model_family().to_string(), "");
105+
BOOST_CHECK_EQUAL(model5.model_name(), "model5");
94106

95107
BOOST_CHECK_THROW(Model::from_str("@"), Exception);
96108
}

0 commit comments

Comments
 (0)