summaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2015-05-01 17:48:32 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2015-05-06 15:18:03 +0200
commit47fe3421585302f2101691a685ab99b0e1ad5cfc (patch)
tree5f7ff204c5d19f83313487a840748724e04ad8e5 /python
parentbf31003d74f538a9096ef5999b31b0daa58c38c9 (diff)
downloadastra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.gz
astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.bz2
astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.tar.xz
astra-47fe3421585302f2101691a685ab99b0e1ad5cfc.zip
Change XMLNode* to XMLNode
An XMLNode object is already simply a pointer, so no need to dynamically allocate XMLNodes.
Diffstat (limited to 'python')
-rw-r--r--python/astra/PyIncludes.pxd2
-rw-r--r--python/astra/PyXMLDocument.pxd8
-rw-r--r--python/astra/utils.pyx29
3 files changed, 15 insertions, 24 deletions
diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd
index 1d8285b..909f58f 100644
--- a/python/astra/PyIncludes.pxd
+++ b/python/astra/PyIncludes.pxd
@@ -43,7 +43,7 @@ cdef extern from "astra/Config.h" namespace "astra":
cdef cppclass Config:
Config()
void initialize(string rootname)
- XMLNode *self
+ XMLNode self
cdef extern from "astra/VolumeGeometry2D.h" namespace "astra":
cdef cppclass CVolumeGeometry2D:
diff --git a/python/astra/PyXMLDocument.pxd b/python/astra/PyXMLDocument.pxd
index 69781f1..57c447e 100644
--- a/python/astra/PyXMLDocument.pxd
+++ b/python/astra/PyXMLDocument.pxd
@@ -44,14 +44,14 @@ cdef extern from "astra/Globals.h" namespace "astra":
cdef extern from "astra/XMLNode.h" namespace "astra":
cdef cppclass XMLNode:
string getName()
- XMLNode *addChildNode(string name)
- XMLNode *addChildNode(string, string)
+ XMLNode addChildNode(string name)
+ XMLNode addChildNode(string, string)
void addAttribute(string, string)
void addAttribute(string, float32)
void addOption(string, string)
bool hasOption(string)
string getAttribute(string)
- list[XMLNode *] getNodes()
+ list[XMLNode] getNodes()
vector[float32] getContentNumericalArray()
string getContent()
bool hasAttribute(string)
@@ -59,7 +59,7 @@ cdef extern from "astra/XMLNode.h" namespace "astra":
cdef extern from "astra/XMLDocument.h" namespace "astra":
cdef cppclass XMLDocument:
void saveToFile(string sFilename)
- XMLNode *getRootNode()
+ XMLNode getRootNode()
cdef extern from "astra/XMLDocument.h" namespace "astra::XMLDocument":
cdef XMLDocument *createDocument(string rootname)
diff --git a/python/astra/utils.pyx b/python/astra/utils.pyx
index 0439f1b..8f1e0b7 100644
--- a/python/astra/utils.pyx
+++ b/python/astra/utils.pyx
@@ -80,9 +80,9 @@ def wrap_from_bytes(value):
return s
-cdef void readDict(XMLNode * root, _dc):
- cdef XMLNode * listbase
- cdef XMLNode * itm
+cdef void readDict(XMLNode root, _dc):
+ cdef XMLNode listbase
+ cdef XMLNode itm
cdef int i
cdef int j
@@ -102,34 +102,29 @@ cdef void readDict(XMLNode * root, _dc):
itm.addAttribute(< string > six.b('index'), < float32 > index)
itm.addAttribute( < string > six.b('value'), < float32 > val[i, j])
index += 1
- del itm
elif val.ndim == 1:
for i in range(val.shape[0]):
itm = listbase.addChildNode(six.b('ListItem'))
itm.addAttribute(< string > six.b('index'), < float32 > index)
itm.addAttribute(< string > six.b('value'), < float32 > val[i])
index += 1
- del itm
else:
raise Exception("Only 1 or 2 dimensions are allowed")
- del listbase
elif isinstance(val, dict):
if item == six.b('option') or item == six.b('options') or item == six.b('Option') or item == six.b('Options'):
readOptions(root, val)
else:
itm = root.addChildNode(item)
readDict(itm, val)
- del itm
else:
if item == six.b('type'):
root.addAttribute(< string > six.b('type'), <string> wrap_to_bytes(val))
else:
itm = root.addChildNode(item, wrap_to_bytes(val))
- del itm
-cdef void readOptions(XMLNode * node, dc):
- cdef XMLNode * listbase
- cdef XMLNode * itm
+cdef void readOptions(XMLNode node, dc):
+ cdef XMLNode listbase
+ cdef XMLNode itm
cdef int i
cdef int j
for item in dc:
@@ -150,17 +145,14 @@ cdef void readOptions(XMLNode * node, dc):
itm.addAttribute(< string > six.b('index'), < float32 > index)
itm.addAttribute( < string > six.b('value'), < float32 > val[i, j])
index += 1
- del itm
elif val.ndim == 1:
for i in range(val.shape[0]):
itm = listbase.addChildNode(six.b('ListItem'))
itm.addAttribute(< string > six.b('index'), < float32 > index)
itm.addAttribute(< string > six.b('value'), < float32 > val[i])
index += 1
- del itm
else:
raise Exception("Only 1 or 2 dimensions are allowed")
- del listbase
else:
node.addOption(item, wrap_to_bytes(val))
@@ -214,10 +206,10 @@ def stringToPythonValue(inputIn):
return str(input)
-cdef XMLNode2dict(XMLNode * node):
- cdef XMLNode * subnode
- cdef list[XMLNode * ] nodes
- cdef list[XMLNode * ].iterator it
+cdef XMLNode2dict(XMLNode node):
+ cdef XMLNode subnode
+ cdef list[XMLNode] nodes
+ cdef list[XMLNode].iterator it
dct = {}
opts = {}
if node.hasAttribute(six.b('type')):
@@ -230,7 +222,6 @@ cdef XMLNode2dict(XMLNode * node):
opts[castString(subnode.getAttribute('key'))] = stringToPythonValue(subnode.getAttribute('value'))
else:
dct[castString(subnode.getName())] = stringToPythonValue(subnode.getContent())
- del subnode
inc(it)
if len(opts)>0: dct['options'] = opts
return dct