Skip to content

Commit

Permalink
Add template variants for get_node() and get_parent()
Browse files Browse the repository at this point in the history
  • Loading branch information
fwsGonzo committed Oct 27, 2024
1 parent e152023 commit 1cb15dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions program/cpp/api/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ inline void print(Args &&...vars) {
/// @brief Get a node by its path. By default, this returns the current node.
/// @param path The path to the node.
/// @return The node at the given path.
inline Node get_node(std::string_view path = ".") {
return Node(path);
template <typename T = Node>
inline T get_node(std::string_view path = ".") {
return T(path);
}

/// @brief Get the parent of the current node.
/// @return The parent node.
inline Node get_parent() {
return Node("..");
template <typename T>
inline T get_parent() {
return T("..");
}

#include <unordered_map>
Expand Down
5 changes: 5 additions & 0 deletions program/cpp/api/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct Node : public Object {
/// @return The Node object.
Node get_node(std::string_view path) const;

template <typename T>
T get_node(std::string_view path) const {
return T(get_node(path));
}

/// @brief Get the number of children of the node.
/// @return The number of children.
unsigned get_child_count() const;
Expand Down

0 comments on commit 1cb15dc

Please sign in to comment.