MCPcopy Create free account
hub / github.com/cinder/Cinder / createNativeDoc

Method createNativeDoc

src/cinder/JsonTree.cpp:597–651  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

595/////////////////////////////////////////////////////////////////////////////////////////////////////////////
596
597Json::Value JsonTree::createNativeDoc( WriteOptions writeOptions ) const
598{
599 // Create JsonCpp value
600 Json::Value value( Json::nullValue );
601
602 // Key on node type
603 switch( mNodeType ) {
604 case NODE_ARRAY: {
605 uint32_t i = 0;
606
607 // Add children to array as objects
608 for ( ConstIter childIt = mChildren.begin(); childIt != mChildren.end(); ++childIt, i++ ) {
609 value[ i ] = childIt->createNativeDoc();
610 }
611 }
612 break;
613 case NODE_OBJECT:
614 // Add children as value members
615 for ( ConstIter childIt = mChildren.begin(); childIt != mChildren.end(); ++childIt ) {
616 value[ childIt->getKey() ] = childIt->createNativeDoc();
617 }
618 break;
619 case NODE_VALUE:
620 // Set value with native data type
621 switch ( mValueType ) {
622 case VALUE_BOOL:
623 value = Json::Value( fromString<bool>( mValue ) );
624 break;
625 case VALUE_DOUBLE:
626 value = Json::Value( fromString<double>( mValue ) );
627 break;
628 case VALUE_INT:
629 value = Json::Value( static_cast<Json::Value::Int64>( fromString<int64_t>( mValue ) ) );
630 break;
631 case VALUE_STRING:
632 value = Json::Value( mValue );
633 break;
634 case VALUE_UINT:
635 value = Json::Value( static_cast<Json::Value::UInt64>( fromString<uint64_t>( mValue ) ) );
636 break;
637 }
638 break;
639 default:
640 break;
641 }
642
643 // Return JsonCpp object
644 if ( writeOptions.getCreateDocument() && !value.isNull() ) {
645 Json::Value doc( Json::objectValue );
646 doc[ mKey ] = value;
647 return doc;
648 } else {
649 return value;
650 }
651}
652
653string JsonTree::serialize() const
654{

Callers 1

JsonTree.cppFile · 0.80

Calls 6

getKeyMethod · 0.80
getCreateDocumentMethod · 0.80
isNullMethod · 0.80
ValueClass · 0.50
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected