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

This commit is contained in:
kevin 2016-07-06 18:54:43 -04:00
parent 3ae46dbb08
commit 7e3a3ff0ab
2 changed files with 42 additions and 2 deletions

View File

@ -1423,6 +1423,39 @@ cmJsRC_t cmJsonObjectNode( const cmJsonNode_t* vp, cmJsonNode_t **retPtrPtr )
return rc; return rc;
} }
cmJsonNode_t* cmJsonFindPair( const cmJsonNode_t* np, const char* label )
{
cmJsRC_t rc = kOkJsRC;
cmJsonNode_t* vnp = NULL;
if((rc = _cmJsonFindMemberValue( np, label, kInvalidTId, &vnp )) != kOkJsRC )
return NULL;
assert( vnp != NULL );
return vnp->ownerPtr;
}
cmJsRC_t cmJsonMemberType( const cmJsonNode_t* np, const char* label, unsigned* typeIdRef )
{
cmJsRC_t rc = kOkJsRC;
cmJsonNode_t* vnp = NULL;
if( typeIdRef != NULL )
*typeIdRef = kInvalidTId;
if((rc = _cmJsonFindMemberValue( np, label, kInvalidTId, &vnp )) != kOkJsRC )
return rc;
assert( vnp != NULL );
if( typeIdRef != NULL )
*typeIdRef = vnp->typeId & kMaskTId;
return rc;
}
cmJsRC_t cmJsonUIntMember( const cmJsonNode_t* np, const char* label, unsigned* retPtr ) cmJsRC_t cmJsonUIntMember( const cmJsonNode_t* np, const char* label, unsigned* retPtr )
{ {
cmJsonNode_t* vp; cmJsonNode_t* vp;

View File

@ -172,6 +172,7 @@ extern "C" {
const cmJsonNode_t* cmJsonFindPathValueC( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask ); const cmJsonNode_t* cmJsonFindPathValueC( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
cmJsonNode_t* cmJsonFindPathValue( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask ); cmJsonNode_t* cmJsonFindPathValue( cmJsonH_t h, const char* path, const cmJsonNode_t* root, unsigned typeIdMask );
// Return the node value. If 'np' does not point to the same type as // Return the node value. If 'np' does not point to the same type as
// specified in '*retPtr' then the value is converted if possible. // specified in '*retPtr' then the value is converted if possible.
// If the value cannot be converted function returns a 'kNodeCannotCvtJsRC' // If the value cannot be converted function returns a 'kNodeCannotCvtJsRC'
@ -187,10 +188,16 @@ extern "C" {
// Return the label from a pair object. // Return the label from a pair object.
const char* cmJsonPairLabel( const cmJsonNode_t* pairPtr ); const char* cmJsonPairLabel( const cmJsonNode_t* pairPtr );
unsigned cmJsonPairTypeId( const cmJsonNode_t* pairPtr ); unsigned cmJsonPairTypeId( const cmJsonNode_t* pairPtr );
cmJsonNode_t* cmJsonPairValue( cmJsonNode_t* pairPtr ); cmJsonNode_t* cmJsonPairValue( cmJsonNode_t* pairPtr );
// Return a labelled pair node from an object.
cmJsonNode_t* cmJsonFindPair( const cmJsonNode_t* objectNodePtr, const char* label );
// Return the type of a member value.
cmJsRC_t cmJsonMemberType( const cmJsonNode_t* objectNodePtr, const char* label, unsigned* typeIdRef );
// Return values associated with the member values in the object // Return values associated with the member values in the object
// pointed to by object objectNodePtr. // pointed to by object objectNodePtr.
cmJsRC_t cmJsonUIntMember( const cmJsonNode_t* objectNodePtr, const char* label, unsigned* retPtr ); cmJsRC_t cmJsonUIntMember( const cmJsonNode_t* objectNodePtr, const char* label, unsigned* retPtr );