Skip to content

Commit

Permalink
[API] add get_nodes method to DSRGraph (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuanCarlosgg authored Jan 10, 2025
1 parent bec4b84 commit c81408c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions api/dsr_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,22 @@ std::vector<DSR::Node> DSRGraph::get_nodes_by_type(const std::string &type)
return nodes_;
}

std::vector<Node> DSRGraph::get_nodes()
{
std::shared_lock<std::shared_mutex> lock(_mutex);

std::vector<Node> nodes_;
nodes_.reserve(nodes.size());

for (auto &[id, N]: nodes)
{
nodes_.emplace_back(N.read_reg());
}
return nodes_;

}


std::vector<DSR::Node> DSRGraph::get_nodes_by_types(const std::vector<std::string> &types)
{
std::shared_lock<std::shared_mutex> lock(_mutex);
Expand Down
1 change: 1 addition & 0 deletions api/include/dsr/api/dsr_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ namespace DSR
std::optional<Node> get_node_root() { return get_node("root"); };
std::vector<Node> get_nodes_by_type(const std::string &type);
std::vector<Node> get_nodes_by_types(const std::vector<std::string> &types);
std::vector<Node> get_nodes();
std::optional<std::string> get_name_from_id(uint64_t id);
std::optional<uint64_t> get_id_from_name(const std::string &name);
std::optional<std::int32_t> get_node_level(const Node &n);
Expand Down

0 comments on commit c81408c

Please sign in to comment.