summaryrefslogtreecommitdiffstats
path: root/var.c
diff options
context:
space:
mode:
Diffstat (limited to 'var.c')
-rw-r--r--var.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/var.c b/var.c
index 3c6a101d..4df56a16 100644
--- a/var.c
+++ b/var.c
@@ -89,6 +89,41 @@ CODESTARTobjDebugPrint(var)
ENDobjDebugPrint(var)
+/* duplicates a var instance
+ * rgerhards, 2008-02-25
+ */
+static rsRetVal
+Duplicate(var_t *pThis, var_t **ppNew)
+{
+ DEFiRet;
+ var_t *pNew = NULL;
+ cstr_t *pstr;
+
+ ISOBJ_TYPE_assert(pThis, var);
+ assert(ppNew != NULL);
+
+ CHKiRet(varConstruct(&pNew));
+ CHKiRet(varConstructFinalize(pNew));
+
+ /* we have the object, now copy value */
+ pNew->varType = pThis->varType;
+ if(pThis->varType == VARTYPE_NUMBER) {
+ pNew->val.num = pThis->val.num;
+ } else if(pThis->varType == VARTYPE_STR) {
+ CHKiRet(rsCStrConstructFromCStr(&pstr, pThis->val.pStr));
+ pNew->val.pStr = pstr;
+ }
+
+ *ppNew = pNew;
+
+finalize_it:
+ if(iRet != RS_RET_OK && pNew != NULL)
+ varDestruct(&pNew);
+
+ RETiRet;
+}
+
+
/* free the current values (destructs objects if necessary)
*/
static rsRetVal
@@ -340,6 +375,7 @@ CODESTARTobjQueryInterface(var)
pIf->ConvToNumber = ConvToNumber;
pIf->ConvToBool = ConvToBool;
pIf->ConvToString = ConvToString;
+ pIf->Duplicate = Duplicate;
finalize_it:
ENDobjQueryInterface(var)