diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-04-09 10:08:29 +0200 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-04-09 10:08:29 +0200 |
commit | 3953d8833e070fa1d6cc7b264dd19ed56c909f02 (patch) | |
tree | b57091d0bfc1dd6234be9d09b6ba55e77948c8e4 /include/call.h | |
parent | 614d95ad69f4e1d3457f2831abc94ecb0809c12e (diff) |
added support for accessing array keys by other value objects, support for unsetting array members, support for array_key_exists(), isset() and unset() functions (feature request in from issue #71)
Diffstat (limited to 'include/call.h')
-rw-r--r-- | include/call.h | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/include/call.h b/include/call.h index 3ad4776..6c5dd8f 100644 --- a/include/call.h +++ b/include/call.h @@ -44,17 +44,41 @@ Value call(const char *name, Params&&... params) * make the code run on the highway), it is not expected that these functions * are going to be used very often anyway. */ -inline Value array_keys(const Value &value) { return call("array_keys", value); } -inline Value array_values(const Value &value) { return call("array_values", value); } -inline Value echo(const char *input) { out << input; return nullptr; } -inline Value echo(const std::string &input) { out << input; return nullptr; } -inline Value empty(const Value &value) { return value.isNull() || !value.boolValue(); } -inline Value empty(const HashMember<std::string> &member) { return !member.exists() || empty(member.value()); } -inline Value empty(const HashMember<int> &member) { return !member.exists() || empty(member.value()); } -inline Value ini_get(const Value &value) { return call("ini_get", value); } -//inline Value isset(const Value &value) { return call("isset", value); } -//inline Value isset(const HashMember<std::string> &member) { return member.exists() && isset(member.value()); } -//inline Value isset(const HashMember<int> &member) { return member.exists() && isset(member.value()); } +inline Value array_key_exists(const Value &key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(int key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(const char *key, const Value &array) { return array.contains(key); } +inline Value array_key_exists(const std::string &key, const Value &array) { return array.contains(key); } +inline Value array_keys(const Value &value) { return call("array_keys", value); } +inline Value array_values(const Value &value) { return call("array_values", value); } +inline Value echo(const char *input) { out << input; return nullptr; } +inline Value echo(const std::string &input) { out << input; return nullptr; } +inline Value empty(const Value &value) { return value.isNull() || !value.boolValue(); } +inline Value empty(const HashMember<std::string> &member) { return !member.exists() || empty(member.value()); } +inline Value empty(const HashMember<int> &member) { return !member.exists() || empty(member.value()); } +inline Value ini_get(const Value &value) { return call("ini_get", value); } +inline Value is_array(const Value &value) { return value.isArray(); } +inline void unset(HashMember<std::string> &member) { member.unset(); } +inline void unset(HashMember<int> &member) { member.unset(); } +inline void unset(HashMember<Value> &member) { member.unset(); } + +/** + * The isset function conflicts with the 'isset' macro defined by the Zend engine + */ +#pragma push_macro("isset"); +#undef isset + +/** + * Define the isset function + */ +inline Value isset(const Value &value) { return call("isset", value); } +inline Value isset(const HashMember<std::string> &member) { return member.exists() && isset(member.value()); } +inline Value isset(const HashMember<int> &member) { return member.exists() && isset(member.value()); } +inline Value isset(const HashMember<Value> &member) { return member.exists() && isset(member.value()); } + +/** + * Re-install the ISSET macro + */ +#pragma pop_macro("isset"); /** * End of namespace |