示例#1
0
static void __print_container (string & result
        , json::value const & value
        , print_spec const & pspec
        , int indent)
{
    if (value.size() == 0) { 
        __print_open_brace(result, value, pspec);
        __print_close_brace(result, value, pspec);
        return;
    }
    
    json::value::const_iterator it_begin = value.cbegin();
    json::value::const_iterator it_end   = value.cend();
    json::value::const_iterator it       = it_begin;
    json::value::const_iterator it_next  = it_begin;
        
    ++it_next;
    
    indent += pspec.base_indent;
    
    __print_open_brace(result, value, pspec);
    result.append(pspec.new_line); // container content always begin after new line
    
    for (; it != it_end; ++it, ++it_next) {
        if (it == it_begin) {
            __print_indent(result, pspec, indent);
            
            if (pspec.comma_position == json::comma_next_line) {
                __print_indent(result, pspec, pspec.first_item_indent);
            }
        }
        
        if (value.is_object()) {
            __print_value(result, it.key(), *it, pspec, indent);
        } else {
            __print_value(result, *it, pspec, indent);
        }
        
        if (it_next != it_end) {
            __print_comma(result, pspec, indent);
        }
    }
    
    indent -= pspec.base_indent;    
    
    result.append(pspec.new_line);
    __print_indent(result, pspec, indent);
    __print_close_brace(result, value, pspec);
}
示例#2
0
    bool node::update(const json::value& new_data, unsigned keep_update_size_percent)
    {
        if ( new_data == data_ )
            return false;

        const std::size_t max_size = new_data.size() * keep_update_size_percent / 100;

        if ( max_size != 0 )
        {
            std::pair<bool, json::value> update_instruction = delta(data_, new_data, max_size);

            if ( update_instruction.first )
                updates_.insert(updates_.length(), update_instruction.second);

        }

        data_ = new_data;
        ++version_;

        remove_old_versions(max_size);

        return true;
    }