void ff::Dict::Merge(const Dict &rhs)
{
	for (StringRef name: rhs.GetAllNames())
	{
		Value *value = rhs.GetValue(name);
		ff::ValuePtr newValue;

		if (value->IsType(ff::Value::Type::Dict) ||
			value->IsType(ff::Value::Type::SavedDict))
		{
			Value *myValue = GetValue(name);
			if (myValue && (myValue->IsType(ff::Value::Type::Dict) ||
				myValue->IsType(ff::Value::Type::SavedDict)))
			{
				ff::ValuePtr dictValue, myDictValue;
				if (value->Convert(ff::Value::Type::Dict, &dictValue) &&
					myValue->Convert(ff::Value::Type::Dict, &myDictValue))
				{
					Dict myDict = myDictValue->AsDict();
					myDict.Merge(dictValue->AsDict());

					if (ff::Value::CreateDict(std::move(myDict), &newValue))
					{
						value = newValue;
					}
				}
			}
		}

		SetValue(name, value);
	}
}
void ff::Dict::Add(const Dict &rhs)
{
	Vector<String> names = rhs.GetAllNames();

	for (StringRef name: names)
	{
		Value *value = rhs.GetValue(name);
		SetValue(name, value);
	}
}
Beispiel #3
0
void ff::DumpDict(ff::StringRef name, const Dict &dict, Log *log, bool chain, bool debugOnly)
{
	if (debugOnly && !GetThisModule().IsDebugBuild())
	{
		return;
	}

	Log extraLog;
	Log &realLog = log ? *log : extraLog;

	realLog.TraceF(L"+- Options for: %s --\r\n", name.c_str());

	Vector<String> names = dict.GetAllNames(chain, true, false);
	for (const String &key: names)
	{
		Value *value = dict.GetValue(key, chain);
		assert(value);

		String valueString;
		ValuePtr convertedValue;

		if (value->Convert(ff::Value::Type::String, &convertedValue))
		{
			valueString = convertedValue->AsString();
		}
		else if (value->Convert(ff::Value::Type::StringVector, &convertedValue))
		{
			Vector<String> &strs = convertedValue->AsStringVector();

			for (size_t i = 0; i < strs.Size(); i++)
			{
				valueString += String::format_new(L"\r\n|    [%lu]: %s", i, strs[i].c_str());
			}
		}
		else if (value->Convert(ff::Value::Type::Data, &convertedValue))
		{
			valueString.format(L"<data[%lu]>", convertedValue->AsData()->GetSize());
		}
		else
		{
			valueString = L"<data>";
		}

		realLog.TraceF(L"| %s: %s\r\n", key.c_str(), valueString.c_str());
	}

	realLog.Trace(L"+- Done --\r\n");
}