From 538996549b81a9b396fd56db8a76da8b4fba985c Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 4 Feb 2016 17:55:40 -0500 Subject: [PATCH] cmXml.h/c : Added cmXmlNodeDouble() and cmXmlHasChild(). --- cmXml.c | 39 +++++++++++++++++++++++++++++++++++++++ cmXml.h | 13 +++++++++---- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cmXml.c b/cmXml.c index a3a2cec..c23217a 100644 --- a/cmXml.c +++ b/cmXml.c @@ -944,6 +944,23 @@ cmXmlRC_t cmXmlNodeIntV(const cmXmlNode_t* np, int* retRef, va_list vl cmXmlRC_t cmXmlNodeUIntV(const cmXmlNode_t* np, unsigned* retRef, va_list vl ) { return cmXmlNodeIntV(np,(int*)retRef,vl); } +cmXmlRC_t cmXmlNodeDoubleV(const cmXmlNode_t* np, double* retRef, va_list vl ) +{ + const cmChar_t* valueStr; + if((valueStr = cmXmlNodeValueV(np,vl)) == NULL ) + return kNodeNotFoundXmlRC; + + errno = 0; + + // convert the string to a double + *retRef = strtod(valueStr,NULL); + + if( errno != 0 ) + return kInvalidTypeXmlRC; + + return kOkXmlRC; +} + cmXmlRC_t cmXmlNodeInt( const cmXmlNode_t* np, int* retRef, ... ) { cmXmlRC_t rc; @@ -964,6 +981,28 @@ cmXmlRC_t cmXmlNodeUInt( const cmXmlNode_t* np, unsigned* retRef, ... ) return rc; } +cmXmlRC_t cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...) +{ + cmXmlRC_t rc; + va_list vl; + va_start(vl,retRef); + rc = cmXmlNodeDoubleV(np,retRef,vl); + va_end(vl); + return rc; + +} + +bool cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label ) +{ + const cmXmlNode_t* cnp = np->children; + for(; cnp!=NULL; cnp=cnp->sibling) + if( cmTextCmp(cnp->label,label) == 0 ) + return true; + + return false; +} + + cmXmlRC_t _cmXmlPrintScore( cmXmlH_t h ) { diff --git a/cmXml.h b/cmXml.h index 2ecdda8..a3002a4 100644 --- a/cmXml.h +++ b/cmXml.h @@ -73,11 +73,16 @@ extern "C" { const cmChar_t* cmXmlNodeValueV( const cmXmlNode_t* np, va_list vl ); const cmChar_t* cmXmlNodeValue( const cmXmlNode_t* np, ... ); - cmXmlRC_t cmXmlNodeIntV( const cmXmlNode_t* np, int* retRef, va_list vl ); - cmXmlRC_t cmXmlNodeUIntV(const cmXmlNode_t* np, unsigned* retRef, va_list vl ); + cmXmlRC_t cmXmlNodeIntV( const cmXmlNode_t* np, int* retRef, va_list vl ); + cmXmlRC_t cmXmlNodeUIntV( const cmXmlNode_t* np, unsigned* retRef, va_list vl ); + cmXmlRC_t cmXmlNodeDoubleV( const cmXmlNode_t* np, double* retRef, va_list vl ); + + cmXmlRC_t cmXmlNodeInt( const cmXmlNode_t* np, int* retRef, ... ); + cmXmlRC_t cmXmlNodeUInt( const cmXmlNode_t* np, unsigned* retRef, ... ); + cmXmlRC_t cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...); + + bool cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label ); - cmXmlRC_t cmXmlNodeInt( const cmXmlNode_t* np, int* retRef, ... ); - cmXmlRC_t cmXmlNodeUInt( const cmXmlNode_t* np, unsigned* retRef, ... ); cmXmlRC_t cmXmlTest( cmCtx_t* ctx, const cmChar_t* fn );