Browse Source

cmJson.h/c : Added cmJsonFindPair() and cmJsonMemberType().

master
kevin 8 years ago
parent
commit
7e3a3ff0ab
2 changed files with 42 additions and 2 deletions
  1. 33
    0
      cmJson.c
  2. 9
    2
      cmJson.h

+ 33
- 0
cmJson.c View File

1423
   return rc;
1423
   return rc;
1424
 }
1424
 }
1425
 
1425
 
1426
+cmJsonNode_t* cmJsonFindPair( const cmJsonNode_t* np, const char* label )
1427
+{
1428
+  cmJsRC_t rc = kOkJsRC;
1429
+  cmJsonNode_t* vnp = NULL;
1430
+
1431
+  if((rc = _cmJsonFindMemberValue( np, label, kInvalidTId, &vnp )) != kOkJsRC )
1432
+    return NULL;
1433
+
1434
+  assert( vnp != NULL );
1435
+  
1436
+
1437
+  return vnp->ownerPtr;
1438
+}
1439
+
1440
+cmJsRC_t      cmJsonMemberType( const cmJsonNode_t* np, const char* label, unsigned* typeIdRef )
1441
+{
1442
+  cmJsRC_t rc = kOkJsRC;
1443
+  cmJsonNode_t* vnp = NULL;
1444
+
1445
+  if( typeIdRef != NULL )
1446
+    *typeIdRef = kInvalidTId;
1447
+  
1448
+  if((rc = _cmJsonFindMemberValue( np, label, kInvalidTId, &vnp )) != kOkJsRC )
1449
+    return rc;
1450
+
1451
+  assert( vnp != NULL );
1452
+  
1453
+  if( typeIdRef != NULL )
1454
+    *typeIdRef = vnp->typeId & kMaskTId;
1455
+
1456
+  return rc;
1457
+}
1458
+
1426
 cmJsRC_t      cmJsonUIntMember(    const cmJsonNode_t* np, const char* label, unsigned* retPtr )
1459
 cmJsRC_t      cmJsonUIntMember(    const cmJsonNode_t* np, const char* label, unsigned* retPtr )
1427
 { 
1460
 { 
1428
   cmJsonNode_t* vp;
1461
   cmJsonNode_t* vp;

+ 9
- 2
cmJson.h View File

172
   const cmJsonNode_t* cmJsonFindPathValueC( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
172
   const cmJsonNode_t* cmJsonFindPathValueC( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
173
   cmJsonNode_t*       cmJsonFindPathValue(  cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
173
   cmJsonNode_t*       cmJsonFindPathValue(  cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
174
 
174
 
175
+  
175
   // Return the node value. If 'np' does not point to the same type as
176
   // Return the node value. If 'np' does not point to the same type as
176
   // specified in '*retPtr' then the value is converted if possible.
177
   // specified in '*retPtr' then the value is converted if possible.
177
   // If the value cannot be converted function returns a 'kNodeCannotCvtJsRC'
178
   // If the value cannot be converted function returns a 'kNodeCannotCvtJsRC'
187
 
188
 
188
 
189
 
189
   // Return the label from a pair object.
190
   // Return the label from a pair object.
190
-  const char* cmJsonPairLabel(  const cmJsonNode_t* pairPtr );
191
-  unsigned    cmJsonPairTypeId( const cmJsonNode_t* pairPtr );
191
+  const char*   cmJsonPairLabel(  const cmJsonNode_t* pairPtr );
192
+  unsigned      cmJsonPairTypeId( const cmJsonNode_t* pairPtr );
192
   cmJsonNode_t* cmJsonPairValue( cmJsonNode_t* pairPtr );
193
   cmJsonNode_t* cmJsonPairValue( cmJsonNode_t* pairPtr );
193
 
194
 
195
+  // Return a labelled pair node from an object.
196
+  cmJsonNode_t* cmJsonFindPair( const cmJsonNode_t* objectNodePtr, const char* label );
197
+  
198
+  // Return the type of a member value.
199
+  cmJsRC_t     cmJsonMemberType( const cmJsonNode_t* objectNodePtr, const char* label, unsigned* typeIdRef );
200
+  
194
   // Return values associated with the member values in the object
201
   // Return values associated with the member values in the object
195
   // pointed to by object objectNodePtr.
202
   // pointed to by object objectNodePtr.
196
   cmJsRC_t      cmJsonUIntMember(   const cmJsonNode_t* objectNodePtr, const char* label, unsigned* retPtr );
203
   cmJsRC_t      cmJsonUIntMember(   const cmJsonNode_t* objectNodePtr, const char* label, unsigned* retPtr );

Loading…
Cancel
Save