Skip to content

Commit

Permalink
Support additional variable types. Add method to get a node by name.
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-moreno committed Sep 28, 2024
1 parent b309f8b commit f1fed9a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
17 changes: 12 additions & 5 deletions include/rogue/interfaces/api/Root.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@

namespace rogue::interfaces::api {

typedef boost::variant<Variable<bool>, Variable<int>> node_types;
typedef boost::variant<Variable<bool>,
Variable<int>,
Variable<float>,
Variable<uint8_t>,
Variable<uint32_t>,
Variable<uint64_t>,
Variable<uintmax_t>,
Variable<std::string>
> node_types;

class Root : Node {

Expand All @@ -30,16 +38,15 @@ class Root : Node {
//! Default constuctor
~Root() = default;

/**
template <typename T>
T getNode(const std::string &name) const {
T getNode(std::string name) const {
auto it{_nodes.find(name)};
if (it == _nodes.end()) {
throw rogue::GeneralError::create("Root::getNode",
("Node "+name+" does not exist.").c_str());
}
return boost::any_cast<T>(it->second);
}**/
return boost::get<T>(_nodes.at(name));
}

//! Setup the tree and start the polling thread.
void start();
Expand Down
42 changes: 35 additions & 7 deletions src/rogue/interfaces/api/Root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Root::Root(boost::python::object obj) : Node(obj) {
auto nodes{static_cast<boost::python::list>(obj.attr("nodeList"))};
for (auto i{0}; i < boost::python::len(nodes); ++i) {
// Use both the class and base class name to determine the type of node
// to instantiate.
// to instantiate.
std::string class_name{boost::python::extract<std::string>(
nodes[i].attr("__class__").attr("__name__"))};
std::string base_class{boost::python::extract<std::string>(
Expand All @@ -24,19 +24,47 @@ Root::Root(boost::python::object obj) : Node(obj) {
//if (base_class.compare("BaseVariable") == 0) {
if (class_name.find("Variable") != std::string::npos) {
std::string type{boost::python::extract<std::string>(nodes[i].attr("typeStr"))};
//std::cout << "Class name: " << class_name << std::endl;
//std::cout << "Base class name: " << base_class << std::endl;
//std::cout << "Type: " << type << std::endl;
if (type.compare("bool") == 0) {
std::cout << "Class name: " << class_name << std::endl;
std::cout << "Base class name: " << base_class << std::endl;
std::cout << "Type: " << type << std::endl;
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<bool>{nodes[i]}));
} /**else if (type.compare("int") == 0) {
} else if (type.compare("int") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<int>{nodes[i]}));
}**/
}
} else if (type.compare("str") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<std::string>{nodes[i]}));
} else if (type.compare("float") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<float>{nodes[i]}));
} else if (type.compare("UInt1") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<uint8_t>{nodes[i]}));
} else if (type.compare("UInt32") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<uint32_t>{nodes[i]}));
} else if (type.compare("UInt64") == 0) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<uint64_t>{nodes[i]}));
} /** else if (type.find("UInt") != std::string::npos) {
_nodes.insert(
std::pair<std::string, node_types>(
node_name, Variable<uintmax_t>{nodes[i]}));
}**/ else {
std::cout << "Type not supported: " << type << std::endl;
}
} else {
std::cout << "Class not supported: " << class_name << std::endl;
}
}

}
Expand Down

0 comments on commit f1fed9a

Please sign in to comment.