示例#1
0
//-----------------------------------------------------------------------------
void Profile::SetDoubleValues(const char* key, const double* vals, int num_vals)
{
    JSON* value = NULL;
    int val_count = 0;
    if (ValMap.Get(key, &value))
    {
        if (value->Type == JSON_Array)
        {
            // truncate the existing array if fewer entries provided
            int num_existing_vals = value->GetArraySize();
            for (int i=num_vals; i<num_existing_vals; i++)
                value->RemoveLast();
            
            JSON* item = value->GetFirstItem();
            while (item && val_count < num_vals)
            {
                if (item->Type == JSON_Number)
                    item->dValue = vals[val_count];

                item = value->GetNextItem(item);
                val_count++;
            }
        }
        else
        {
            return;  // Maybe we should change the data type?
        }
    }
    else
    {
        value = JSON::CreateArray();
        value->Name = key;

        Values.PushBack(value);
        ValMap.Set(key, value);
    }

    for (; val_count < num_vals; val_count++)
        value->AddArrayNumber(vals[val_count]);
}