| 595 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 596 | |
| 597 | Json::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 | |
| 653 | string JsonTree::serialize() const |
| 654 | { |
no test coverage detected