summaryrefslogtreecommitdiff
path: root/include/value.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/value.h')
-rw-r--r--include/value.h58
1 files changed, 55 insertions, 3 deletions
diff --git a/include/value.h b/include/value.h
index c6b1af9..2fe940a 100644
--- a/include/value.h
+++ b/include/value.h
@@ -100,7 +100,7 @@ public:
* @param value
*/
template <typename T>
- Value(const std::map<std::string,T> &value)
+ Value(const std::map<std::string,T> &value) : Value(Type::Array)
{
// set all elements
for (auto &iter : value) setRaw(iter.first.c_str(), iter.first.size(), iter.second);
@@ -322,6 +322,17 @@ public:
bool operator> (const char *value) const { return ::strcmp(rawValue(), value) > 0; }
/**
+ * Comparison operators for hardcoded Value
+ * @param value
+ */
+ bool operator==(const Value &value) const;
+ bool operator!=(const Value &value) const { return !operator==(value); }
+ bool operator< (const Value &value) const;
+ bool operator> (const Value &value) const { return value.operator<(*this); }
+ bool operator<=(const Value &value) const { return !operator>(value); }
+ bool operator>=(const Value &value) const { return !operator<(value); }
+
+ /**
* Comparison operators
* @param value
*/
@@ -376,7 +387,7 @@ public:
* variables - other variables return nullptr.
*
* If you are going to write to the buffer, make sure that you first call
- * the resize() method to ensure that the buffer is big enough.
+ * the reserve() method to ensure that the buffer is big enough.
*
* @return char *
*/
@@ -385,7 +396,7 @@ public:
/**
* Resize buffer space. If you want to write directly to the buffer (which
* is returned by the buffer() method), you should first reserve enough
- * space in it. This can be done with this resize() method. This will also
+ * space in it. This can be done with this reserve() method. This will also
* turn the Value object into a string (if it was not already a string).
* The writable buffer is returned.
*
@@ -489,6 +500,9 @@ public:
// result variable
std::map<std::string,T> result;
+
+ // loop through the original map, and copy everything to the result
+ for (auto &iter : map) result[iter.first] = iter.second;
// done
return result;
@@ -951,6 +965,37 @@ public:
// try casting it
return dynamic_cast<T*>(base);
}
+
+ /**
+ * Check whether this object is an instance of a certain class
+ *
+ * If you set the parameter 'allowString' to true, and the Value object
+ * holds a string, the string will be treated as class name.
+ *
+ * @param classname The class of which this should be an instance
+ * @param size Length of the classname string
+ * @param allowString Is it allowed for 'this' to be a string
+ * @return bool
+ */
+ bool instanceOf(const char *classname, size_t size, bool allowString = false) const;
+ bool instanceOf(const char *classname, bool allowString = false) const { return instanceOf(classname, strlen(classname), allowString); }
+ bool instanceOf(const std::string &classname, bool allowString = false) const { return instanceOf(classname.c_str(), classname.size(), allowString); }
+
+ /**
+ * Check whether this object is derived from a certain class.
+ *
+ * If you set the parameter 'allowString' to true, and the Value object
+ * holds a string, the string will be treated as class name.
+ *
+ * @param classname The class of which this should be an instance
+ * @param size Length of the classname string
+ * @param allowString Is it allowed for 'this' to be a string
+ * @return bool
+ */
+ bool derivedFrom(const char *classname, size_t size, bool allowString = false) const;
+ bool derivedFrom(const char *classname, bool allowString = false) const { return derivedFrom(classname, strlen(classname), allowString); }
+ bool derivedFrom(const std::string &classname, bool allowString = false) const { return derivedFrom(classname.c_str(), classname.size(), allowString); }
+
private:
/**
@@ -1036,6 +1081,13 @@ protected:
iterator createIterator(bool begin) const;
/**
+ * Retrieve the class entry
+ * @param allowString Allow the 'this' object to be a string
+ * @return zend_class_entry
+ */
+ struct _zend_class_entry *classEntry(bool allowString = true) const;
+
+ /**
* The Globals and Member classes can access the zval directly
*/
friend class Globals;