本文整理汇总了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);
}
示例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;
}