Skip to content

Commit

Permalink
remove implicit bool conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanhhughes committed Sep 14, 2024
1 parent 616200d commit e1fd6ba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
5 changes: 2 additions & 3 deletions include/spark_dsg/layer_prefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
namespace spark_dsg {

struct LayerKey {
static constexpr LayerId UNKNOWN_LAYER = DsgLayers::UNKNOWN;
LayerId layer;
uint32_t prefix = 0;
bool dynamic = false;
Expand All @@ -56,13 +55,13 @@ struct LayerKey {

bool isParent(const LayerKey& other) const;

bool valid() const;

bool operator==(const LayerKey& other) const;

inline bool operator!=(const LayerKey& other) const {
return !this->operator==(other);
}

inline operator bool() const { return layer != UNKNOWN_LAYER; }
};

std::ostream& operator<<(std::ostream& out, const LayerKey& key);
Expand Down
12 changes: 9 additions & 3 deletions src/dynamic_scene_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ DynamicSceneGraph::LayerIds getDefaultLayerIds() {
DynamicSceneGraph::DynamicSceneGraph() : DynamicSceneGraph(getDefaultLayerIds()) {}

DynamicSceneGraph::DynamicSceneGraph(const LayerIds& layer_ids) : layer_ids(layer_ids) {
for (const auto layer_id : layer_ids) {
if (layer_id == DsgLayers::UNKNOWN) {
throw std::domain_error("cannot instantiate layer with unknown layer id!");
}
}

if (layer_ids.empty()) {
throw std::domain_error("scene graph cannot be initialized without layers");
}
Expand Down Expand Up @@ -236,7 +242,7 @@ bool DynamicSceneGraph::insertEdge(NodeId source,
return false;
}

if (!source_key || !target_key) {
if (!source_key.valid() || !target_key.valid()) {
return false;
}

Expand Down Expand Up @@ -267,7 +273,7 @@ bool DynamicSceneGraph::insertParentEdge(NodeId source,
return false;
}

if (!source_key || !target_key) {
if (!source_key.valid() || !target_key.valid()) {
return false;
}

Expand Down Expand Up @@ -467,7 +473,7 @@ bool DynamicSceneGraph::removeEdge(NodeId source, NodeId target) {
return false;
}

if (!source_key || !target_key) {
if (!source_key.valid() || !target_key.valid()) {
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions src/layer_prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@

namespace spark_dsg {

LayerKey::LayerKey() : layer(LayerKey::UNKNOWN_LAYER) {}
LayerKey::LayerKey() : layer(DsgLayers::UNKNOWN) {}

LayerKey::LayerKey(LayerId layer_id) : layer(layer_id) {}

LayerKey::LayerKey(LayerId layer_id, uint32_t prefix)
: layer(layer_id), prefix(prefix), dynamic(true) {}

bool LayerKey::isParent(const LayerKey& other) const { return layer > other.layer; }

bool LayerKey::valid() const { return layer != DsgLayers::UNKNOWN; }

bool LayerKey::operator==(const LayerKey& other) const {
if (dynamic != other.dynamic) {
return false;
Expand All @@ -59,8 +63,6 @@ bool LayerKey::operator==(const LayerKey& other) const {
return same_layer && prefix == other.prefix;
}

bool LayerKey::isParent(const LayerKey& other) const { return layer > other.layer; }

std::ostream& operator<<(std::ostream& out, const LayerKey& key) {
if (key.dynamic) {
out << key.layer << "(" << key.prefix << ")";
Expand Down
2 changes: 1 addition & 1 deletion src/scene_graph_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void getAncestorsOfLayer(const DynamicSceneGraph& graph,
return;
}

if (node->layer <= child_layer) {
if (node->layer <= child_layer.layer) {
return;
}

Expand Down
7 changes: 0 additions & 7 deletions tests/utest_layer_prefix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ TEST(LayerKeyTests, TestIsParent) {
EXPECT_FALSE(key6.isParent(key4));
}

TEST(LayerKeyTests, TestKeyTruthValues) {
EXPECT_FALSE(LayerKey());
EXPECT_TRUE(LayerKey(1));
EXPECT_TRUE(LayerKey(2, 0));
EXPECT_TRUE(LayerKey(0));
}

TEST(LayerPrefixTests, TestMatches) {
LayerPrefix a('a');
EXPECT_TRUE(a.matches(NodeSymbol('a', 0)));
Expand Down

0 comments on commit e1fd6ba

Please sign in to comment.