Browse Source

cmXml.h/c : Added cmXmlNodeDouble() and cmXmlHasChild().

master
kevin 8 years ago
parent
commit
538996549b
2 changed files with 48 additions and 4 deletions
  1. 39
    0
      cmXml.c
  2. 9
    4
      cmXml.h

+ 39
- 0
cmXml.c View File

@@ -944,6 +944,23 @@ cmXmlRC_t          cmXmlNodeIntV(const cmXmlNode_t* np, int* retRef, va_list vl
944 944
 cmXmlRC_t          cmXmlNodeUIntV(const cmXmlNode_t* np, unsigned* retRef, va_list vl )
945 945
 { return cmXmlNodeIntV(np,(int*)retRef,vl); }
946 946
 
947
+cmXmlRC_t          cmXmlNodeDoubleV(const cmXmlNode_t* np, double* retRef, va_list vl )
948
+{
949
+  const cmChar_t* valueStr;
950
+  if((valueStr = cmXmlNodeValueV(np,vl)) == NULL )
951
+    return kNodeNotFoundXmlRC;
952
+
953
+  errno = 0;
954
+
955
+  // convert the string to a double
956
+  *retRef = strtod(valueStr,NULL);
957
+    
958
+  if( errno != 0 )
959
+    return kInvalidTypeXmlRC;
960
+  
961
+  return kOkXmlRC;
962
+}
963
+
947 964
 cmXmlRC_t          cmXmlNodeInt( const cmXmlNode_t* np, int* retRef, ... )
948 965
 {
949 966
   cmXmlRC_t rc;
@@ -964,6 +981,28 @@ cmXmlRC_t          cmXmlNodeUInt( const cmXmlNode_t* np, unsigned* retRef, ... )
964 981
   return rc;
965 982
 }
966 983
 
984
+cmXmlRC_t          cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...)
985
+{
986
+  cmXmlRC_t rc;
987
+  va_list vl;
988
+  va_start(vl,retRef);
989
+  rc = cmXmlNodeDoubleV(np,retRef,vl);
990
+  va_end(vl);
991
+  return rc;
992
+
993
+}
994
+
995
+bool    cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label )
996
+{
997
+  const cmXmlNode_t* cnp = np->children;
998
+  for(; cnp!=NULL; cnp=cnp->sibling)
999
+    if( cmTextCmp(cnp->label,label) == 0 )
1000
+      return true;
1001
+
1002
+  return false;
1003
+}
1004
+
1005
+
967 1006
 
968 1007
 cmXmlRC_t _cmXmlPrintScore( cmXmlH_t h )
969 1008
 {

+ 9
- 4
cmXml.h View File

@@ -73,11 +73,16 @@ extern "C" {
73 73
   const cmChar_t*    cmXmlNodeValueV( const cmXmlNode_t* np, va_list vl );
74 74
   const cmChar_t*    cmXmlNodeValue( const cmXmlNode_t* np, ... );
75 75
 
76
-  cmXmlRC_t          cmXmlNodeIntV( const cmXmlNode_t* np, int* retRef, va_list vl );
77
-  cmXmlRC_t          cmXmlNodeUIntV(const cmXmlNode_t* np, unsigned* retRef, va_list vl );
76
+  cmXmlRC_t          cmXmlNodeIntV(    const cmXmlNode_t* np, int* retRef, va_list vl );
77
+  cmXmlRC_t          cmXmlNodeUIntV(   const cmXmlNode_t* np, unsigned* retRef, va_list vl );
78
+  cmXmlRC_t          cmXmlNodeDoubleV( const cmXmlNode_t* np, double*   retRef, va_list vl );
79
+
80
+  cmXmlRC_t          cmXmlNodeInt(   const cmXmlNode_t* np, int* retRef, ... );
81
+  cmXmlRC_t          cmXmlNodeUInt(  const cmXmlNode_t* np, unsigned* retRef, ... );
82
+  cmXmlRC_t          cmXmlNodeDouble(const cmXmlNode_t* np, double* retRef, ...);
83
+  
84
+  bool               cmXmlNodeHasChild( const cmXmlNode_t* np, const cmChar_t* label );
78 85
 
79
-  cmXmlRC_t          cmXmlNodeInt(  const cmXmlNode_t* np, int* retRef, ... );
80
-  cmXmlRC_t          cmXmlNodeUInt( const cmXmlNode_t* np, unsigned* retRef, ... );
81 86
   
82 87
   cmXmlRC_t cmXmlTest( cmCtx_t* ctx, const cmChar_t* fn );
83 88
   

Loading…
Cancel
Save