-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pattern-based registrations/subscriptions #97
Changes from all commits
9f77998
b065b58
2dcc7c5
2989b6b
2c518d6
af3fb6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,78 @@ using wamp_kw_arguments = std::unordered_map<std::string, msgpack::object>; | |
static const msgpack::object EMPTY_ARGUMENTS(std::array<msgpack::object, 0>(), nullptr); | ||
static const msgpack::object EMPTY_KW_ARGUMENTS(wamp_kw_arguments(), nullptr); | ||
|
||
|
||
//msgpack map utilities. | ||
//TODO: refactor event & invocation to used these | ||
template <typename T> | ||
inline T value_for_key(const msgpack::object& object, const std::string& key) | ||
{ | ||
if (object.type != msgpack::type::MAP) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the size of indentations that the web interface is showing, it appears that this commit uses tabs to indent rather than spaces. This is inconsistent with the code so far and might lead to weird-looking code in some people's editors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Pls no tabs at all. |
||
throw msgpack::type_error(); | ||
} | ||
for (std::size_t i = 0; i < object.via.map.size; ++i) { | ||
const msgpack::object_kv& kv = object.via.map.ptr[i]; | ||
if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size | ||
&& key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) | ||
{ | ||
return kv.val.as<T>(); | ||
} | ||
} | ||
throw std::out_of_range(key + " keyword argument doesn't exist"); | ||
} | ||
|
||
template <typename T> | ||
inline T value_for_key(const msgpack::object& object, const char* key) | ||
{ | ||
if (m_kw_arguments.type != msgpack::type::MAP) { | ||
throw msgpack::type_error(); | ||
} | ||
std::size_t key_size = strlen(key); | ||
for (std::size_t i = 0; i < object.via.map.size; ++i) { | ||
const msgpack::object_kv& kv = object.via.map.ptr[i]; | ||
if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size | ||
&& memcmp(key, kv.key.via.str.ptr, key_size) == 0) | ||
{ | ||
return kv.val.as<T>(); | ||
} | ||
} | ||
throw std::out_of_range(std::string(key) + " keyword argument doesn't exist"); | ||
} | ||
|
||
template <typename T> | ||
inline T value_for_key_or(const msgpack::object& object, const std::string& key, const T& fallback) | ||
{ | ||
if (object.type != msgpack::type::MAP) { | ||
throw msgpack::type_error(); | ||
} | ||
for (std::size_t i = 0; i < object.via.map.size; ++i) { | ||
const msgpack::object_kv& kv = object.via.map.ptr[i]; | ||
if (kv.key.type == msgpack::type::STR && key.size() == kv.key.via.str.size | ||
&& key.compare(0, key.size(), kv.key.via.str.ptr, kv.key.via.str.size) == 0) | ||
{ | ||
return kv.val.as<T>(); | ||
} | ||
} | ||
return fallback; | ||
} | ||
|
||
template <typename T> | ||
inline T value_for_key_or(const msgpack::object& object, const char* key, const T& fallback) | ||
{ | ||
if (object.type != msgpack::type::MAP) { | ||
throw msgpack::type_error(); | ||
} | ||
std::size_t key_size = strlen(key); | ||
for (std::size_t i = 0; i < object.via.map.size; ++i) { | ||
const msgpack::object_kv& kv = object.via.map.ptr[i]; | ||
if (kv.key.type == msgpack::type::STR && key_size == kv.key.via.str.size | ||
&& memcmp(key, kv.key.via.str.ptr, key_size) == 0) | ||
{ | ||
return kv.val.as<T>(); | ||
} | ||
} | ||
throw fallback; | ||
} | ||
} // namespace autobahn | ||
|
||
#endif // AUTOBAHN_WAMP_ARGUMENTS_HPP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the amount of stuff to ignore for VS is ridiculous