22#ifndef __PLUGINS_PLEXIL_UTILS_H_
23#define __PLUGINS_PLEXIL_UTILS_H_
34replace_tokens(std::string &s)
36 std::map<std::string, std::string> tokens = {{
"@CFGDIR@", CONFDIR},
37 {
"@BASEDIR@", BASEDIR},
38 {
"@FAWKES_BASEDIR@", FAWKES_BASEDIR},
39 {
"@RESDIR@", RESDIR}};
41 for (
const auto &token : tokens) {
42 std::string::size_type pos;
43 if ((pos = s.find(token.first)) != std::string::npos) {
44 s.replace(pos, token.first.size(), token.second);
50verify_args(
const std::vector<PLEXIL::Value> & args,
51 const std::string & func,
52 const std::vector<std::pair<std::string, PLEXIL::ValueType>> &types)
54 if (args.size() != types.size()) {
55 warn(func <<
": Command requires " << types.size() <<
" arguments, got " << args.size());
56 for (
size_t i = 0; i < args.size(); ++i) {
57 warn(func <<
": Argument " << i <<
" = " << args[i]);
61 for (
size_t i = 0; i < args.size(); ++i) {
63 if (types[i].second == PLEXIL::UNKNOWN_TYPE)
66 if (args[i].valueType() != types[i].second) {
68 <<
"Command argument " << i <<
"(" << types[i].first <<
") expected to be of type "
69 << PLEXIL::valueTypeName(types[i].second) <<
", but is of type "
70 << PLEXIL::valueTypeName(args[i].valueType()));
85get_xml_config_value(
const pugi::xml_node &config,
const std::string &name)
87 pugi::xml_attribute xml_attr = config.attribute(name.c_str());
89 return xml_attr.value();
91 for (
const auto &c : config.children()) {
92 if (strcmp(c.name(),
"Parameter") == 0) {
93 pugi::xml_attribute xml_key_attr = c.attribute(
"key");
94 if (xml_key_attr && strcmp(xml_key_attr.value(), name.c_str()) == 0) {
95 return c.text().get();