Skip to content

Instantly share code, notes, and snippets.

@Bueddl
Created January 8, 2017 23:39
Show Gist options
  • Save Bueddl/0aa2ca8b9b1e55897ca0d89ef46c8406 to your computer and use it in GitHub Desktop.
Save Bueddl/0aa2ca8b9b1e55897ca0d89ef46c8406 to your computer and use it in GitHub Desktop.
void node_param_value(std::shared_ptr<tag_node> &node, const std::string &value)
{
auto string = std::make_shared<xmlrpc::tag_node>("string");
string->append_child(std::make_shared<xmlrpc::text_node>(value));
node->append_child(string);
}
void node_param_value(std::shared_ptr<tag_node> &node, int value)
{
auto string = std::make_shared<xmlrpc::tag_node>("int");
string->append_child(std::make_shared<xmlrpc::text_node>(std::to_string(value)));
node->append_child(string);
}
void node_param_value(std::shared_ptr<tag_node> &node, double value)
{
auto string = std::make_shared<xmlrpc::tag_node>("double");
string->append_child(std::make_shared<xmlrpc::text_node>(std::to_string(value)));
node->append_child(string);
}
template<class T>
void node_append_param(std::shared_ptr<tag_node> &node, T &&arg)
{
auto param = std::make_shared<xmlrpc::tag_node>("param");
node->append_child(param);
auto value = std::make_shared<xmlrpc::tag_node>("value");
param->append_child(value);
node_param_value(value, std::forward<T>(arg));
}
template<class T, class ...Ts>
void node_append_param(std::shared_ptr<tag_node> &node, T &&arg, Ts&&... rest)
{
node_append_param(node, std::forward<T>(arg));
node_append_param(node, std::forward<Ts>(rest)...);
}
template<class ...Ts>
std::shared_ptr<node> make_method_call(const std::string &method, Ts&&... args)
{
auto document = std::make_shared<xmlrpc::document_node>("methodCall");
auto method_name = std::make_shared<xmlrpc::tag_node>("methodName");
document->append_child(method_name);
method_name->append_child(std::make_shared<xmlrpc::text_node>(method));
auto params = std::make_shared<xmlrpc::tag_node>("params");
document->append_child(params);
node_append_param(params, std::forward<Ts>(args)...);
return document;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment