/* * Copyright 2015 Cloudius Systems */ #ifndef API_API_HH_ #define API_API_HH_ #include "http/httpd.hh" #include "database.hh" #include #include #include namespace api { struct http_context { sstring api_dir; http_server_control http_server; distributed& db; http_context(distributed& _db) : db(_db) {} }; future<> set_server(http_context& ctx); template std::vector container_to_vec(const T& container) { std::vector res; for (auto i : container) { res.push_back(boost::lexical_cast(i)); } return res; } template std::vector map_to_key_value(const std::map& map) { std::vector res; for (auto i : map) { res.push_back(T()); res.back().key = i.first; res.back().value = i.second; } return res; } template std::vector& map_to_key_value(const MAP& map, std::vector& res) { for (auto i : map) { T val; val.key = boost::lexical_cast(i.first); val.value = boost::lexical_cast(i.second); res.push_back(val); } return res; } template T map_sum(T&& dest, const S& src) { for (auto i : src) { dest[i.first] += i.second; } return dest; } template std::vector map_keys(const MAP& map) { std::vector res; for (const auto& i : map) { res.push_back(boost::lexical_cast(i.first)); } return res; } /** * General sstring splitting function */ inline std::vector split(const sstring& text, const char* separator) { if (text == "") { return std::vector(); } std::vector tokens; return boost::split(tokens, text, boost::is_any_of(separator)); } /** * Split a column family parameter */ inline std::vector split_cf(const sstring& cf) { return split(cf, ","); } } #endif /* API_API_HH_ */