summaryrefslogtreecommitdiff
path: root/include/hiddenpointer.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-10 05:21:18 -0700
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-09-10 05:21:18 -0700
commit85507088051bdfabf8bc71346290949b78c3c914 (patch)
treed3503b8d28ccac78c5b209bea97a094b4a54aeb7 /include/hiddenpointer.h
parente220af8dc07d845efb81082f3159460406ece9ca (diff)
Fixed various crashes because hidden pointers were not persistently stored
Copying the result value of a function has been fixed New C++ nullptr type is supported for Php::Value
Diffstat (limited to 'include/hiddenpointer.h')
-rw-r--r--include/hiddenpointer.h56
1 files changed, 52 insertions, 4 deletions
diff --git a/include/hiddenpointer.h b/include/hiddenpointer.h
index f29082f..3502bc9 100644
--- a/include/hiddenpointer.h
+++ b/include/hiddenpointer.h
@@ -106,25 +106,64 @@ public:
* Retrieve the pointer
* @return Type*
*/
- Type *pointer()
+ Type *pointer() const
{
return _pointer;
}
/**
+ * Change the pointer
+ * @param Type*
+ */
+ void setPointer(Type *pointer)
+ {
+ // store pointer
+ _pointer = pointer;
+
+ // overwrite in data
+ _data.replace(0, sizeof(Type *), (const char *)&_pointer, sizeof(Type *));
+
+ // for safety reasons, we recalculate text pointer
+ _text = _data.c_str() + sizeof(Type *);
+ }
+
+ /**
* Retrieve the text
* @return const char *
*/
- const char *text()
+ const char *text() const
{
return _text;
}
/**
+ * Change the text
+ * @param text
+ * @param size
+ */
+ void setText(const char *text, int size=-1)
+ {
+ // check if size was set
+ if (size < 0) size = strlen(text);
+
+ // reserve enough room for the text and the pointer
+ _data.reserve(size + sizeof(Type *));
+
+ // store the pointer
+ _data.assign(std::string((const char *)&_pointer, sizeof(Type *)));
+
+ // append the text
+ _data.append(text, size);
+
+ // store new text
+ _text = _data.c_str() + sizeof(Type *);
+ }
+
+ /**
* Cast to the pointer
* @return Type*
*/
- operator Type* ()
+ operator Type* () const
{
return _pointer;
}
@@ -133,10 +172,19 @@ public:
* Cast to text
* @return const char *
*/
- operator const char * ()
+ operator const char * () const
{
return _text;
}
+
+ /**
+ * Length of the text
+ * @return int
+ */
+ int length() const
+ {
+ return _data.size() - sizeof(Type *);
+ }
private:
/**