summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/member.h92
-rw-r--r--src/argument.cpp6
-rw-r--r--src/callable.cpp7
3 files changed, 44 insertions, 61 deletions
diff --git a/include/member.h b/include/member.h
index 86e3554..49ac246 100644
--- a/include/member.h
+++ b/include/member.h
@@ -36,68 +36,22 @@ public:
virtual ~Member() {}
/**
- * Assign a numeric value
- * @param value
- * @return Member
- */
- Member &operator=(long value)
- {
- _value->set(_index, value);
- return *this;
- }
-
- /**
- * Assign a numeric value
- * @param value
- * @return Member
- */
- Member &operator=(int value)
- {
- _value->set(_index, value);
- return *this;
- }
-
- /**
- * Assign a double value
+ * Assign a value object to the array
* @param value
* @return Member
*/
- Member &operator=(double value)
- {
- _value->set(_index, value);
- return *this;
- }
-
- /**
- * Assign a boolean value
- * @param value
- * @return Member
- */
- Member &operator=(bool value)
- {
- _value->set(_index, value);
- return *this;
- }
-
- /**
- * Assign a string value
- * @param value
- * @return Member
- */
- Member &operator=(const std::string &value)
- {
- _value->set(_index, value);
- return *this;
- }
-
- /**
- * Assign a byte array value
- * @param value
- * @return Member
- */
- Member &operator=(const char *value)
+ Member &operator=(const Value &value)
{
+ // set property in parent array
_value->set(_index, value);
+
+ // leap out if this is not a nested array access
+ //if (!_parent) return *this;
+
+ // nested array access, we need to update the parent too
+ //_parent->operator=(*_value);
+
+ // done
return *this;
}
@@ -174,7 +128,7 @@ public:
{
return _value->get(_index)[index];
}
-
+
/**
* Array access operator
* This can be used for accessing associative arrays
@@ -212,6 +166,16 @@ private:
Member(const Member<Type> &member) : _value(member._value), _index(member._index) {}
/**
+ * Set the member
+ * @param member
+ */
+ Member<Type> &add(Member *parent)
+ {
+ _parent = parent;
+ return *this;
+ }
+
+ /**
* The array of which this is a member
* @var Value
*/
@@ -224,6 +188,18 @@ private:
Type _index;
/**
+ * Parent member
+ *
+ * When accessing nested arrays a["a"]["b"] = 'true', the member
+ * object that represents the "b" entry holds a pointer to the member
+ * object that represents "a", so that it can tell its parent to
+ * store itself in the top array too
+ *
+ * @var Member
+ */
+ Member *_parent = nullptr;
+
+ /**
* Value objects may create members
*/
friend class Value;
diff --git a/src/argument.cpp b/src/argument.cpp
index fc9d720..627ee05 100644
--- a/src/argument.cpp
+++ b/src/argument.cpp
@@ -22,7 +22,7 @@ namespace PhpCpp {
*/
Argument::Argument(const std::string &name, const std::string &classname, bool null, bool ref)
{
- _refcount = new int[1];
+ _refcount = new int(1);
_info = new ArgInfo(name, classname, null, ref);
}
@@ -35,7 +35,7 @@ Argument::Argument(const std::string &name, const std::string &classname, bool n
*/
Argument::Argument(const std::string &name, Type type, bool ref)
{
- _refcount = new int[1];
+ _refcount = new int(1);
_info = new ArgInfo(name, type, ref);
}
@@ -46,7 +46,7 @@ Argument::Argument(const std::string &name, Type type, bool ref)
*/
Argument::Argument(const std::string &name, bool ref)
{
- _refcount = new int[1];
+ _refcount = new int(1);
_info = new ArgInfo(name, ref);
}
diff --git a/src/callable.cpp b/src/callable.cpp
index 929f39c..7cba919 100644
--- a/src/callable.cpp
+++ b/src/callable.cpp
@@ -160,6 +160,13 @@ int Callable::invoke(INTERNAL_FUNCTION_PARAMETERS)
ret["2"] = 3;
+// ret["hmm"]["s"] = 456;
+
+ Value sub;
+ sub["something"] = "yes";
+
+ ret["b"] = sub;
+
std::cout << "done setting properties" << std::endl;