diff options
author | Willem Jan Palenstijn <wjp@usecode.org> | 2015-05-01 17:48:32 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-05-06 15:18:03 +0200 |
commit | 47fe3421585302f2101691a685ab99b0e1ad5cfc (patch) | |
tree | 5f7ff204c5d19f83313487a840748724e04ad8e5 /matlab/mex/mexHelpFunctions.cpp | |
parent | bf31003d74f538a9096ef5999b31b0daa58c38c9 (diff) | |
download | astra-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 'matlab/mex/mexHelpFunctions.cpp')
-rw-r--r-- | matlab/mex/mexHelpFunctions.cpp | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/matlab/mex/mexHelpFunctions.cpp b/matlab/mex/mexHelpFunctions.cpp index c0ac711..00d766f 100644 --- a/matlab/mex/mexHelpFunctions.cpp +++ b/matlab/mex/mexHelpFunctions.cpp @@ -185,7 +185,7 @@ Config* structToConfig(string rootname, const mxArray* pStruct) } //----------------------------------------------------------------------------------------- -bool structToXMLNode(XMLNode* node, const mxArray* pStruct) +bool structToXMLNode(XMLNode node, const mxArray* pStruct) { // loop all fields int nfields = mxGetNumberOfFields(pStruct); @@ -199,16 +199,16 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct) if (mxIsChar(pField)) { string sValue = mexToString(pField); if (sFieldName == "type") { - node->addAttribute("type", sValue); + node.addAttribute("type", sValue); } else { - delete node->addChildNode(sFieldName, sValue); + node.addChildNode(sFieldName, sValue); } } // scalar else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) == 1) { string sValue = mexToString(pField); - delete node->addChildNode(sFieldName, sValue); + node.addChildNode(sFieldName, sValue); } // numerical array @@ -217,20 +217,18 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct) mexErrMsgTxt("Numeric input must be double."); return false; } - XMLNode* listbase = node->addChildNode(sFieldName); - listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); + XMLNode listbase = node.addChildNode(sFieldName); + listbase.addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); double* pdValues = mxGetPr(pField); int index = 0; for (unsigned int row = 0; row < mxGetM(pField); row++) { for (unsigned int col = 0; col < mxGetN(pField); col++) { - XMLNode* item = listbase->addChildNode("ListItem"); - item->addAttribute("index", index); - item->addAttribute("value", pdValues[col*mxGetM(pField)+row]); + XMLNode item = listbase.addChildNode("ListItem"); + item.addAttribute("index", index); + item.addAttribute("value", pdValues[col*mxGetM(pField)+row]); index++; - delete item; } } - delete listbase; } // not castable to a single string @@ -240,9 +238,8 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct) if (!ret) return false; } else { - XMLNode* newNode = node->addChildNode(sFieldName); + XMLNode newNode = node.addChildNode(sFieldName); bool ret = structToXMLNode(newNode, pField); - delete newNode; if (!ret) return false; } @@ -254,7 +251,7 @@ bool structToXMLNode(XMLNode* node, const mxArray* pStruct) } //----------------------------------------------------------------------------------------- // Options struct to xml node -bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct) +bool optionsToXMLNode(XMLNode node, const mxArray* pOptionStruct) { // loop all fields int nfields = mxGetNumberOfFields(pOptionStruct); @@ -262,7 +259,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct) std::string sFieldName = std::string(mxGetFieldNameByNumber(pOptionStruct, i)); const mxArray* pField = mxGetFieldByNumber(pOptionStruct, 0, i); - if (node->hasOption(sFieldName)) { + if (node.hasOption(sFieldName)) { mexErrMsgTxt("Duplicate option"); return false; } @@ -270,7 +267,7 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct) // string or scalar if (mxIsChar(pField) || mexIsScalar(pField)) { string sValue = mexToString(pField); - node->addOption(sFieldName, sValue); + node.addOption(sFieldName, sValue); } // numerical array else if (mxIsNumeric(pField) && mxGetM(pField)*mxGetN(pField) > 1) { @@ -279,21 +276,19 @@ bool optionsToXMLNode(XMLNode* node, const mxArray* pOptionStruct) return false; } - XMLNode* listbase = node->addChildNode("Option"); - listbase->addAttribute("key", sFieldName); - listbase->addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); + XMLNode listbase = node.addChildNode("Option"); + listbase.addAttribute("key", sFieldName); + listbase.addAttribute("listsize", mxGetM(pField)*mxGetN(pField)); double* pdValues = mxGetPr(pField); int index = 0; for (unsigned int row = 0; row < mxGetM(pField); row++) { for (unsigned int col = 0; col < mxGetN(pField); col++) { - XMLNode* item = listbase->addChildNode("ListItem"); - item->addAttribute("index", index); - item->addAttribute("value", pdValues[col*mxGetM(pField)+row]); + XMLNode item = listbase.addChildNode("ListItem"); + item.addAttribute("index", index); + item.addAttribute("value", pdValues[col*mxGetM(pField)+row]); index++; - delete item; } } - delete listbase; } else { mexErrMsgTxt("Unsupported option type"); return false; @@ -343,30 +338,29 @@ mxArray* configToStruct(astra::Config* cfg) } //----------------------------------------------------------------------------------------- -mxArray* XMLNodeToStruct(astra::XMLNode* node) +mxArray* XMLNodeToStruct(astra::XMLNode node) { std::map<std::string, mxArray*> mList; std::map<std::string, mxArray*> mOptions; // type_attribute - if (node->hasAttribute("type")) { - mList["type"] = mxCreateString(node->getAttribute("type").c_str()); + if (node.hasAttribute("type")) { + mList["type"] = mxCreateString(node.getAttribute("type").c_str()); } - list<XMLNode*> nodes = node->getNodes(); - for (list<XMLNode*>::iterator it = nodes.begin(); it != nodes.end(); it++) { - XMLNode* subnode = (*it); + list<XMLNode> nodes = node.getNodes(); + for (list<XMLNode>::iterator it = nodes.begin(); it != nodes.end(); it++) { + XMLNode subnode = (*it); // option - if (subnode->getName() == "Option") { - mOptions[subnode->getAttribute("key")] = stringToMxArray(subnode->getAttribute("value")); + if (subnode.getName() == "Option") { + mOptions[subnode.getAttribute("key")] = stringToMxArray(subnode.getAttribute("value")); } // regular content else { - mList[subnode->getName()] = stringToMxArray(subnode->getContent()); + mList[subnode.getName()] = stringToMxArray(subnode.getContent()); } - delete subnode; } if (mOptions.size() > 0) mList["options"] = buildStruct(mOptions); |