summaryrefslogtreecommitdiff
path: root/include/value.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 10:08:29 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-09 10:08:29 +0200
commit3953d8833e070fa1d6cc7b264dd19ed56c909f02 (patch)
treeb57091d0bfc1dd6234be9d09b6ba55e77948c8e4 /include/value.h
parent614d95ad69f4e1d3457f2831abc94ecb0809c12e (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/value.h')
-rw-r--r--include/value.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/include/value.h b/include/value.h
index 95985d7..d1e6c8a 100644
--- a/include/value.h
+++ b/include/value.h
@@ -575,6 +575,18 @@ public:
}
/**
+ * Is a certain key set in the array, when that key is stored as value object
+ * @param key
+ * @return bool
+ */
+ virtual bool contains(const Value &value) const override
+ {
+ if (value.isNumeric()) return contains(value.numericValue());
+ if (value.isString()) return contains(value.rawValue(), value.size());
+ return contains(value.stringValue());
+ }
+
+ /**
* Cast to a number
* @return int32_t
*/
@@ -692,6 +704,18 @@ public:
}
/**
+ * Get access to a certain variant member
+ * @param key
+ * @return Value
+ */
+ virtual Value get(const Value &key) const override
+ {
+ if (key.isNumeric()) return get(key.numericValue());
+ if (key.isString()) return get(key.rawValue(), key.size());
+ return get(key.stringValue());
+ }
+
+ /**
* Set a certain property
* Calling this method will turn the value into an array
* @param index Index of the property to set
@@ -732,6 +756,61 @@ public:
}
/**
+ * Overwrite the value at a certain variant index
+ * @param key
+ * @param value
+ */
+ virtual void set(const Value &key, const Value &value) override
+ {
+ if (key.isNumeric()) return set(key.numericValue(), value);
+ if (key.isString()) return set(key.rawValue(), key.size(), value);
+ return set(key.stringValue(), value);
+ }
+
+ /**
+ * Unset a member by its index
+ * @param index
+ */
+ virtual void unset(int index) override;
+
+ /**
+ * Unset by key name and length of the key
+ * @param key
+ * @param size
+ */
+ void unset(const char *key, int size);
+
+ /**
+ * Unset by key name and length of the key
+ * @param key
+ * @param size
+ */
+ void unset(const char *key)
+ {
+ unset(key, strlen(key));
+ }
+
+ /**
+ * Unset a member by its key
+ * @param key
+ */
+ virtual void unset(const std::string &key) override
+ {
+ return unset(key.c_str(), key.size());
+ }
+
+ /**
+ * Unset a member by its key
+ * @param key
+ */
+ virtual void unset(const Value &key) override
+ {
+ if (key.isNumeric()) return unset(key.numericValue());
+ if (key.isString()) return unset(key.rawValue(), key.size());
+ return unset(key.stringValue());
+ }
+
+ /**
* Array access operator
* This can be used for accessing arrays
* @param index
@@ -787,6 +866,26 @@ public:
{
return get(key);
}
+
+ /**
+ * Index by other value object
+ * @param key
+ * @return HashMember<std::string>
+ */
+ HashMember<Value> operator[](const Value &key);
+
+ /**
+ * Index by other value object
+ * @param key
+ * @return HashMember<std::string>
+ */
+ Value operator[](const Value &key) const
+ {
+ if (key.isNumeric()) return get(key.numericValue());
+ if (key.isString()) return get(key.rawValue(), key.size());
+ return get(key.stringValue());
+ }
+
/**
* Call the function in PHP