Procházet zdrojové kódy

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

master
kevin před 8 roky
rodič
revize
7e3a3ff0ab
2 změnil soubory, kde provedl 42 přidání a 2 odebrání
  1. 33
    0
      cmJson.c
  2. 9
    2
      cmJson.h

+ 33
- 0
cmJson.c Zobrazit soubor

@@ -1423,6 +1423,39 @@ cmJsRC_t   cmJsonObjectNode( const cmJsonNode_t* vp, cmJsonNode_t **retPtrPtr )
1423 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 1459
 cmJsRC_t      cmJsonUIntMember(    const cmJsonNode_t* np, const char* label, unsigned* retPtr )
1427 1460
 { 
1428 1461
   cmJsonNode_t* vp;

+ 9
- 2
cmJson.h Zobrazit soubor

@@ -172,6 +172,7 @@ extern "C" {
172 172
   const cmJsonNode_t* cmJsonFindPathValueC( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
173 173
   cmJsonNode_t*       cmJsonFindPathValue(  cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
174 174
 
175
+  
175 176
   // Return the node value. If 'np' does not point to the same type as
176 177
   // specified in '*retPtr' then the value is converted if possible.
177 178
   // If the value cannot be converted function returns a 'kNodeCannotCvtJsRC'
@@ -187,10 +188,16 @@ extern "C" {
187 188
 
188 189
 
189 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 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 201
   // Return values associated with the member values in the object
195 202
   // pointed to by object objectNodePtr.
196 203
   cmJsRC_t      cmJsonUIntMember(   const cmJsonNode_t* objectNodePtr, const char* label, unsigned* retPtr );

Načítá se…
Zrušit
Uložit