summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-22 13:39:21 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-10-22 13:39:21 -0700
commitf96fc6c53bc8bd8888aeb291441f61a65b439413 (patch)
tree030815351f20cfa6dfb36c816c5c0d737516e784 /include
parentf16847ab29d474e2b20d7f8c9f3a0f229b54c850 (diff)
Initial setup for dealing with object properties
Diffstat (limited to 'include')
-rw-r--r--include/base.h27
-rw-r--r--include/hashmember.h11
-rw-r--r--include/properties.h72
3 files changed, 110 insertions, 0 deletions
diff --git a/include/base.h b/include/base.h
index 6acd805..1dc131e 100644
--- a/include/base.h
+++ b/include/base.h
@@ -17,6 +17,11 @@ class Base
{
public:
/**
+ * Constructor
+ */
+ Base() {}
+
+ /**
* Virtual destructor
*/
virtual ~Base() {}
@@ -66,6 +71,28 @@ public:
*/
virtual void __destruct() {}
+ /**
+ * Get access to a property by name
+ * @param string
+ * @return Property
+ */
+// Property operator[](const char *name);
+
+ /**
+ * Alternative way to access a property
+ * @param string
+ * @return Property
+ */
+// Property operator[](const std::string &name);
+
+protected:
+ /**
+ * All properties of the object
+ * @var Properties
+ */
+// Properties _properties;
+
+private:
};
/**
diff --git a/include/hashmember.h b/include/hashmember.h
index d476b55..e0964a5 100644
--- a/include/hashmember.h
+++ b/include/hashmember.h
@@ -213,8 +213,19 @@ private:
* Only value objects may construct members
*/
friend class Value;
+ friend class Properties;
};
+
+/**
+ * Custom output stream operator
+ * @param stream
+ * @param value
+ * @return ostream
+ */
+std::ostream &operator<<(std::ostream &stream, const HashMember<int> &value);
+std::ostream &operator<<(std::ostream &stream, const HashMember<std::string> &value);
+
/**
* End of namespace
diff --git a/include/properties.h b/include/properties.h
new file mode 100644
index 0000000..cb8b38e
--- /dev/null
+++ b/include/properties.h
@@ -0,0 +1,72 @@
+/**
+ * Properties.h
+ *
+ * The properties of a class are accessible using the protected _properties
+ * member. This is a class that implements the [] operator, so that all
+ * properties can be accessed using ["name"].
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * Class properties
+ */
+class Properties
+{
+public:
+ /**
+ * Destructor
+ */
+ virtual ~Properties() {}
+
+ /**
+ * Get access to a property by name
+ * @param name
+ * @return HashMember
+ */
+ HashMember<std::string> operator[](const char *name)
+ {
+ // map to value
+ return _value[name];
+ }
+
+ /**
+ * Another way to get access to a property
+ * @param name
+ * @return HashMember
+ */
+ HashMember<std::string> operator[](const std::string &name)
+ {
+ // map to value
+ return _value[name];
+ }
+
+private:
+ /**
+ * Private constructor - outside users are not supposed to instantiate this object
+ * @param zval
+ */
+ Properties(struct _zval_struct *zval) : _value(zval) {}
+
+ /**
+ * The value object
+ * @var Value
+ */
+ Value _value;
+
+ /**
+ * Only the base class can create properties
+ */
+ friend class Base;
+};
+
+/**
+ * End of namespace
+ */
+}