Skip to content

Commit

Permalink
deprecate getLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhhughes committed Dec 12, 2024
1 parent ab8d426 commit 56363e3
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 25 deletions.
5 changes: 4 additions & 1 deletion include/spark_dsg/node_symbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ class NodeSymbol {
NodeSymbol operator++(int);

//! get a string representation of the symbol
std::string getLabel() const;
[[deprecated("use str() instead")]] std::string getLabel() const;

//! get a string representation of the symbol
std::string str() const;

/**
* @brief output node symbol information
Expand Down
2 changes: 1 addition & 1 deletion include/spark_dsg/printing.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ std::string displayNodeSymbolContainer(const Container& set) {
ss << "[";
auto iter = set.begin();
while (iter != set.end()) {
ss << NodeSymbol(*iter).getLabel();
ss << NodeSymbol(*iter).str();
++iter;
if (iter != set.end()) {
ss << ", ";
Expand Down
6 changes: 3 additions & 3 deletions python/bindings/src/spark_dsg_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ PYBIND11_MODULE(_dsg_bindings, module) {
"value",
[](const NodeSymbol& symbol) { return static_cast<NodeId>(symbol); },
nullptr)
.def("__repr__", &NodeSymbol::getLabel)
.def("__repr__", &NodeSymbol::str)
.def("__hash__",
[](const NodeSymbol& symbol) { return static_cast<NodeId>(symbol); })
.def(pybind11::self == pybind11::self)
Expand Down Expand Up @@ -470,8 +470,8 @@ PYBIND11_MODULE(_dsg_bindings, module) {
[](SceneGraphEdge& edge, const EdgeAttributes& info) { *edge.info = info; })
.def("__repr__", [](const SceneGraphEdge& edge) {
std::stringstream ss;
ss << "Edge<source=" << NodeSymbol(edge.source).getLabel()
<< ", target=" << NodeSymbol(edge.target).getLabel() << ">";
ss << "Edge<source=" << NodeSymbol(edge.source).str()
<< ", target=" << NodeSymbol(edge.target).str() << ">";
return ss.str();
});

Expand Down
4 changes: 2 additions & 2 deletions src/dynamic_scene_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool DynamicSceneGraph::hasEdge(NodeId source, NodeId target) const {
const Node& DynamicSceneGraph::getNode(NodeId node_id) const {
const auto node = findNode(node_id);
if (!node) {
throw std::out_of_range("missing node '" + NodeSymbol(node_id).getLabel() + "'");
throw std::out_of_range("missing node '" + NodeSymbol(node_id).str() + "'");
}

return *node;
Expand Down Expand Up @@ -505,7 +505,7 @@ bool DynamicSceneGraph::empty() const { return numNodes() == 0; }
Eigen::Vector3d DynamicSceneGraph::getPosition(NodeId node_id) const {
auto iter = node_lookup_.find(node_id);
if (iter == node_lookup_.end()) {
throw std::out_of_range("node " + NodeSymbol(node_id).getLabel() +
throw std::out_of_range("node " + NodeSymbol(node_id).str() +
" is not in the graph");
}

Expand Down
4 changes: 3 additions & 1 deletion src/node_symbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ NodeSymbol NodeSymbol::operator++(int) {
return old;
}

std::string NodeSymbol::getLabel() const {
std::string NodeSymbol::str() const {
std::stringstream ss;
ss << *this;
return ss.str();
}

std::string NodeSymbol::getLabel() const { return str(); }

NodeSymbol operator"" _id(const char* str, size_t size) {
if (size < 1) {
throw std::domain_error("invalid literal: must have at least two characters");
Expand Down
3 changes: 1 addition & 2 deletions src/printing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ std::ostream& operator<<(std::ostream& out, const LayerKey& key) {
}

std::ostream& operator<<(std::ostream& out, const SceneGraphNode& node) {
out << "Node<id=" << NodeSymbol(node.id).getLabel() << ", layer=" << node.layer
<< ">";
out << "Node<id=" << NodeSymbol(node.id).str() << ", layer=" << node.layer << ">";
return out;
}

Expand Down
2 changes: 1 addition & 1 deletion src/scene_graph_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Node* SceneGraphLayer::findNode(NodeId node_id) const {
const SceneGraphNode& SceneGraphLayer::getNode(NodeId node_id) const {
const auto node = findNode(node_id);
if (!node) {
throw std::out_of_range("missing node '" + NodeSymbol(node_id).getLabel() + "'");
throw std::out_of_range("missing node '" + NodeSymbol(node_id).str() + "'");
}

return *node;
Expand Down
8 changes: 4 additions & 4 deletions src/serialization/graph_json_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ void read_node_from_json(const serialization::AttributeFactory<NodeAttributes>&
auto attrs = serialization::Visitor::from(factory, record.at("attributes"));
if (!attrs) {
std::stringstream ss;
ss << "invalid attributes for " << NodeSymbol(node_id).getLabel();
ss << "invalid attributes for " << NodeSymbol(node_id).str();
throw std::runtime_error(ss.str());
}

if (!graph.emplaceNode(layer, node_id, std::move(attrs), partition)) {
std::stringstream ss;
ss << "failed to add " << NodeSymbol(node_id).getLabel();
ss << "failed to add " << NodeSymbol(node_id).str();
throw std::runtime_error(ss.str());
}
}
Expand All @@ -101,8 +101,8 @@ void read_edge_from_json(const serialization::AttributeFactory<EdgeAttributes>&

if (!graph.insertEdge(source, target, std::move(attrs))) {
std::stringstream ss;
ss << "failed to add " << NodeSymbol(source).getLabel() << ""
<< NodeSymbol(target).getLabel();
ss << "failed to add " << NodeSymbol(source).str() << ""
<< NodeSymbol(target).str();
throw std::runtime_error(ss.str());
}
}
Expand Down
14 changes: 6 additions & 8 deletions tests/utest_dynamic_scene_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ void testParentRelationship(const DynamicSceneGraph& graph,
const auto& child_node = graph.getNode(child);

EXPECT_TRUE(parent_node.children().count(child_node.id))
<< NodeSymbol(child).getLabel() << " is not child of "
<< NodeSymbol(parent).getLabel();
<< NodeSymbol(child).str() << " is not child of " << NodeSymbol(parent).str();

// note that this depends on the parent id not being 0
EXPECT_EQ(parent_node.id, child_node.getParent().value_or(0))
<< NodeSymbol(parent).getLabel() << " is not parent of "
<< NodeSymbol(child).getLabel();
<< NodeSymbol(parent).str() << " is not parent of " << NodeSymbol(child).str();
}

void testSiblingRelationship(const DynamicSceneGraph& graph,
Expand All @@ -62,12 +60,12 @@ void testSiblingRelationship(const DynamicSceneGraph& graph,
const auto& target_node = graph.getNode(target);

EXPECT_TRUE(source_node.siblings().count(target_node.id))
<< NodeSymbol(target).getLabel() << " is not a sibling of "
<< NodeSymbol(source).getLabel();
<< NodeSymbol(target).str() << " is not a sibling of "
<< NodeSymbol(source).str();

EXPECT_TRUE(target_node.siblings().count(source_node.id))
<< NodeSymbol(source).getLabel() << " is not a sibling of "
<< NodeSymbol(target).getLabel();
<< NodeSymbol(source).str() << " is not a sibling of "
<< NodeSymbol(target).str();
}

} // namespace
Expand Down
4 changes: 2 additions & 2 deletions tests/utest_scene_graph_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct AncestorTestConfig {
};

std::ostream& operator<<(std::ostream& out, const AncestorTestConfig& config) {
out << "{query: " << NodeSymbol(config.query).getLabel()
out << "{query: " << NodeSymbol(config.query).str()
<< ", depth: " << config.depth
<< ", expected: " << displayNodeSymbolContainer(config.expected) << "}";
return out;
Expand All @@ -61,7 +61,7 @@ struct BoundingBoxTestConfig {
};

std::ostream& operator<<(std::ostream& out, const BoundingBoxTestConfig& config) {
out << "{query: " << NodeSymbol(config.query).getLabel()
out << "{query: " << NodeSymbol(config.query).str()
<< ", depth: " << config.depth << ", expected: " << config.expected << "}";
return out;
}
Expand Down

0 comments on commit 56363e3

Please sign in to comment.