Skip to content

Commit

Permalink
Fix issues with Command.
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-moreno committed Nov 30, 2023
1 parent c6b1058 commit 0b63e4b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 29 deletions.
5 changes: 4 additions & 1 deletion include/rogue/interfaces/api/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include "rogue/interfaces/api/Node.h"

namespace rogue::interfaces::api {

template <typename T> class Command : public Node {

public:
/**
* Constructor.
*/
Command(const boost::python::object &obj) : Node(obj) {};
Command(const boost::python::object &obj) : Node(obj) {
};
// Destructor
~Command() = default;

Expand Down
15 changes: 13 additions & 2 deletions include/rogue/interfaces/api/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class Node {

protected:

//! Boost python object representing this node
boost::python::object _obj;
//! Boost python object representing this node
boost::python::object _obj;


private:

Expand All @@ -22,6 +23,16 @@ class Node {
std::string _path{""};
std::string _base_class{""};

//! String representation of this class
friend auto operator<<(std::ostream& os, Node const& node) -> std::ostream& {
os << "{ Node name: " << node._name << "\n";
os << "\tDescription: " << node._description << "\n";
os << "\tPath: " << node._path << "\n";
os << "\tBase class: " << node._base_class << "\n";
os << "}";
return os;
}


};

Expand Down
3 changes: 2 additions & 1 deletion include/rogue/interfaces/api/Root.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>

#include <boost/python.hpp>
#include <boost/any.hpp>

#include "rogue/interfaces/api/Node.h"
#include "rogue/interfaces/api/Command.h"
Expand Down Expand Up @@ -41,7 +42,7 @@ class Root : Node {

// TODO: This should be an unordered map.
//! List of commands in the tree
std::map<std::string, Node> _commands;
std::map<std::string, boost::any> _commands;

};

Expand Down
4 changes: 2 additions & 2 deletions include/rogue/interfaces/api/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ template <typename T> class Variable : public Node {
public:
Variable(const boost::python::object &obj) : Node(obj) {
try {
value = boost::python::extract<T>(obj.attr("_default"));
//std::cout << "Value: " << value << std::endl;
boost::python::object var_obj{obj.attr("getVariableValue")()};
value = boost::python::extract<T>(var_obj.attr("value"));
} catch (...) {
std::cout << "Value is not set." << std::endl;
return;
Expand Down
7 changes: 0 additions & 7 deletions src/rogue/interfaces/api/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,5 @@ Node::Node(const boost::python::object &obj) {
_base_class = boost::python::extract<std::string>(obj.attr("__class__")
.attr("__bases__")[0].attr("__name__"));

/*
std::cout << "Name: " << _name << std::endl;
std::cout << "Desciption: " << _description << std::endl;
std::cout << "Path: " << _path << std::endl;
std::cout << "Base class: " << _base_class << std::endl;
*/
}

}
38 changes: 22 additions & 16 deletions src/rogue/interfaces/api/Root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ Root::Root(const boost::python::object &obj) : Node(obj) {
// extracts all the attributes.
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.
// Use both the class and base class name to determine the type of node
// 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>(
nodes[i].attr("__class__")
.attr("__bases__")[0].attr("__name__"))};
//std::cout << "Class name: " << class_name << std::endl;
//std::cout << "Base class name: " << base_class << std::endl;
if (class_name.compare("BaseCommand") == 0) {
std::string command_name{boost::python::extract<std::string>(nodes[i].attr("name"))};
// Some commands don't have a return type. In this case, the "retTypeStr"
Expand All @@ -35,34 +37,38 @@ Root::Root(const boost::python::object &obj) : Node(obj) {
boost::python::extract<std::string> ret_type(nodes[i].attr("retTypeStr"));
if (!ret_type.check()) {
//std::cout << "Object with NoneType found." << std::endl;
// _commands[command_name] = Command<char*>(nodes[i]);
_commands[command_name] = Command<char*>(nodes[i]);
} else if (std::string(ret_type).compare("str") == 0) {
//_commands[command_name] = Command<std::string>(nodes[i]);
_commands[command_name] = Command<std::string>(nodes[i]);
}
} else if (class_name.compare("LinkVariable") == 0) {
} else if (class_name.compare("RemoteVariable") == 0) {
} else if (class_name.compare("LocalVariable") == 0) {
} else if (base_class.compare("BaseVariable") == 0) {

std::string type{boost::python::extract<std::string>(nodes[i].attr("typeStr"))};\
//std::cout << "Type: " << type << std::endl;
std::string type{boost::python::extract<std::string>(nodes[i].attr("typeStr"))};
if (type.compare("bool") == 0) {
_nodes.push_back(Variable<bool>(nodes[i]));
} else if (type.compare("str") == 0) {
_nodes.push_back(Variable<std::string>(nodes[i]));
} else if (type.compare("float") == 0) {
_nodes.push_back(Variable<float>(nodes[i]));
} else if (type.compare("UInt32") == 0) {
_nodes.push_back(Variable<char*>(nodes[i]));
_nodes.push_back(Variable<uint32_t>(nodes[i]));
} else if (type.compare("UInt1") == 0) {
_nodes.push_back(Variable<uint8_t>(nodes[i]));
} else if (type.compare("UInt64") == 0) {
_nodes.push_back(Variable<uint64_t>(nodes[i]));
} else if (type.compare("int") == 0) {
_nodes.push_back(Variable<int>(nodes[i]));
} else {
std::cout << "class: " << class_name << std::endl;
std::cout << "base class: " << base_class << std::endl;
std::cout << "Type not supported: " << type << std::endl;
}
}
} else if (type.compare("list") == 0) {
} // else {
// std::cout << "class: " << class_name << std::endl;
// std::cout << "base class: " << base_class << std::endl;
// std::cout << "Type not supported: " << type << std::endl;
//}
}
}

std::cout << "Total nodes added: " << _nodes.size() << std::endl;
//for (auto & node : _nodes) std::cout << node << "\n";
}

void Root::start() {
Expand Down

0 comments on commit 0b63e4b

Please sign in to comment.