当前位置: 首页>>代码示例>>C++>>正文


C++ Value::removeIndex方法代码示例

本文整理汇总了C++中json::Value::removeIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ Value::removeIndex方法的具体用法?C++ Value::removeIndex怎么用?C++ Value::removeIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在json::Value的用法示例。


在下文中一共展示了Value::removeIndex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: deleteContributor

	void deleteContributor(StaticFunctionTag*, BSFixedString characterName)
	{
		Json::Value jsonDisplayList = ReadDisplayData();
		
		for (auto & jsonDisplay : jsonDisplayList.getMemberNames())
		{
			Json::Value jsonDisplayData = jsonDisplayList[jsonDisplay.c_str()];
			Json::Value jsonContributors;
			if (jsonDisplayData.isMember("contributors"))
				jsonContributors = jsonDisplayData["contributors"];
			
			//Remove this character as a contributor
			for (int index = 0; index < jsonContributors.size(); ++index)
			{
				if (jsonContributors[index].asString() == characterName.data)
				{
					_MESSAGE("Removing %s from list of contributors.", characterName.data);
					Json::Value removed;
					jsonContributors.removeIndex(index, &removed);
					index--; //duplicate names shouldn't be a thing, but you never know
					jsonDisplayData["contributors"] = jsonContributors;
				}
			}

			//If this character was the only contributor, remove the entry entirely
			if (!jsonDisplayData.isMember("contributors") || (jsonDisplayData.isMember("contributors") && !jsonContributors.size()))
			{
				_MESSAGE("Last contributor was removed, deleting entry for %s!", jsonDisplay.c_str());
				jsonDisplayList.removeMember(jsonDisplay.c_str());
			}
			else {
				jsonDisplayList[jsonDisplay.c_str()] = jsonDisplayData;
			}
		}
		WriteDisplayData(jsonDisplayList);
	}
开发者ID:Verteiron,项目名称:PersistentLegacy,代码行数:36,代码来源:PapyrusDBM_Utils.cpp

示例2: saveDisplayStatus

bool saveDisplayStatus(Json::Value &jsonDisplayList, TESObjectREFR* pObject, const char * playerName = nullptr)
{
	std::string formString = GetJCFormString(pObject);

	Json::Value jsonDisplayData;
	if (jsonDisplayList.isMember(formString.c_str()))
		jsonDisplayData = jsonDisplayList[formString.c_str()];
	
	
	//kFlagUnk_0x800 is the Disabled flag
	if ((pObject->flags & TESForm::kFlagUnk_0x800) && jsonDisplayList.isMember(formString.c_str()))
	{
		//_MESSAGE("Display %s is disabled, but exists on the list.", formString.c_str());
		//Display is disabled, but exists on the list
		Json::Value jsonContributors;
		if (jsonDisplayData.isMember("contributors"))
			jsonContributors = jsonDisplayData["contributors"];

		//Remove this character as a contributor
		for (int index = 0; index < jsonContributors.size(); ++index)
		{
			if (jsonContributors[index].asString() == playerName)
			{
				_MESSAGE("Removing %s from list of contributors.", playerName);
				Json::Value removed;
				jsonContributors.removeIndex(index, &removed);
				index--; //duplicate names shouldn't be a thing, but you never know
				jsonDisplayData["contributors"] = jsonContributors;
			}
		}

		//If this character was the only contributor, remove the entry entirely
		if (!jsonDisplayData.isMember("contributors") || (jsonDisplayData.isMember("contributors") && !jsonContributors.size()))
		{
			_MESSAGE("Last contributor was removed, deleting entry for %s!", formString.c_str());
			jsonDisplayList.removeMember(formString.c_str());
		}
		else {
			jsonDisplayList[formString.c_str()] = jsonDisplayData;
		}
	}
	else if (!(pObject->flags & TESForm::kFlagUnk_0x800)) //If the display is NOT disabled
	{
		_MESSAGE("Display %s is enabled.", formString.c_str());
		
		std::string name = getName(pObject);
		if (name.length() > 0)
		{
			jsonDisplayData["name"] = name.c_str();
		}

		//If playerName is set, add the player's name to the list
		if (playerName)
		{
			Json::Value jsonContributors;
			if (jsonDisplayData.isMember("contributors"))
				jsonContributors = jsonDisplayData["contributors"];
			bool addMe = true;
			for (int index = 0; index < jsonContributors.size(); ++index)
			{
				if (jsonContributors[index].asString() == playerName)
				{
					_MESSAGE("  %s is already in the contributor list.", playerName);
					addMe = false;
				}
			}
			if (addMe)
			{
				_MESSAGE("  Adding %s to the contributor list.", playerName);
				jsonContributors.append(playerName);
				jsonDisplayData["contributors"] = jsonContributors;
			}
		}

		jsonDisplayList[formString.c_str()] = jsonDisplayData;
	}
	return true;
}
开发者ID:Verteiron,项目名称:PersistentLegacy,代码行数:78,代码来源:PapyrusDBM_Utils.cpp


注:本文中的json::Value::removeIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。