Make Class::getName return string_view

pull/3228/head
Evil Eye 2 years ago
parent 856fcb7742
commit 4ff12d8945

@ -2,6 +2,7 @@
#define GAME_MWBASE_JOURNAL_H
#include <string>
#include <string_view>
#include <deque>
#include <map>
@ -63,7 +64,7 @@ namespace MWBase
virtual void addTopic (const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) = 0;
/// \note topicId must be lowercase
virtual void removeLastAddedTopicResponse (const std::string& topicId, const std::string& actorName) = 0;
virtual void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) = 0;
///< Removes the last topic response added for the given topicId and actor name.
/// \note topicId must be lowercase

@ -70,7 +70,7 @@ namespace MWClass
return true;
}
std::string Activator::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Activator::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
@ -95,7 +95,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Activator> *ref = ptr.get<ESM::Activator>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())

@ -23,7 +23,7 @@ namespace MWClass
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override;
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -39,7 +39,7 @@ namespace MWClass
return getClassModel<ESM::Apparatus>(ptr);
}
std::string Apparatus::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Apparatus::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Apparatus> *ref = ptr.get<ESM::Apparatus>();
const std::string& name = ref->mBase->mName;
@ -89,7 +89,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Apparatus> *ref = ptr.get<ESM::Apparatus>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -97,7 +98,8 @@ namespace MWClass
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}

@ -20,7 +20,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -47,7 +47,7 @@ namespace MWClass
return getClassModel<ESM::Armor>(ptr);
}
std::string Armor::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Armor::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
const std::string& name = ref->mBase->mName;
@ -195,13 +195,14 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Armor> *ref = ptr.get<ESM::Armor>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
// get armor type string (light/medium/heavy)
std::string typeText;
std::string_view typeText;
if (ref->mBase->mData.mWeight == 0)
{
// no type
@ -224,12 +225,17 @@ namespace MWClass
text += "\n#{sCondition}: " + MWGui::ToolTips::toString(remainingHealth) + "/"
+ MWGui::ToolTips::toString(ref->mBase->mData.mHealth);
if (typeText != "")
text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight) + " (" + typeText + ")";
if (!typeText.empty())
{
text += "\n#{sWeight}: " + MWGui::ToolTips::toString(ref->mBase->mData.mWeight) + " (";
text += typeText;
text += ')';
}
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}

@ -20,7 +20,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -28,9 +28,9 @@ namespace MWClass
}
}
std::string BodyPart::getName(const MWWorld::ConstPtr &ptr) const
std::string_view BodyPart::getName(const MWWorld::ConstPtr &ptr) const
{
return std::string();
return {};
}
bool BodyPart::hasToolTip(const MWWorld::ConstPtr& ptr) const

@ -19,7 +19,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName (const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -44,7 +44,7 @@ namespace MWClass
return getClassModel<ESM::Book>(ptr);
}
std::string Book::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Book::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
const std::string& name = ref->mBase->mName;
@ -106,7 +106,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Book> *ref = ptr.get<ESM::Book>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -114,7 +115,8 @@ namespace MWClass
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -42,7 +42,7 @@ namespace MWClass
return getClassModel<ESM::Clothing>(ptr);
}
std::string Clothing::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Clothing::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
const std::string& name = ref->mBase->mName;
@ -153,7 +153,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Clothing> *ref = ptr.get<ESM::Clothing>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -161,7 +162,8 @@ namespace MWClass
text += MWGui::ToolTips::getWeightString(ref->mBase->mData.mWeight, "#{sWeight}");
text += MWGui::ToolTips::getValueString(ref->mBase->mData.mValue, "#{sValue}");
if (MWBase::Environment::get().getWindowManager()->getFullHelp()) {
if (MWBase::Environment::get().getWindowManager()->getFullHelp())
{
text += MWGui::ToolTips::getCellRefString(ptr.getCellRef());
text += MWGui::ToolTips::getMiscString(ref->mBase->mScript, "Script");
}

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -210,7 +210,7 @@ namespace MWClass
}
}
std::string Container::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Container::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
const std::string& name = ref->mBase->mName;
@ -245,7 +245,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Container> *ref = ptr.get<ESM::Container>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
std::string text;
int lockLevel = ptr.getCellRef().getLockLevel();

@ -47,7 +47,7 @@ namespace MWClass
void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override;
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override;
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -211,7 +211,7 @@ namespace MWClass
}
}
std::string Creature::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Creature::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
const std::string& name = ref->mBase->mName;
@ -589,7 +589,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Creature> *ref = ptr.get<ESM::Creature>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
std::string text;
if (MWBase::Environment::get().getWindowManager()->getFullHelp())

@ -51,7 +51,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip(const MWWorld::ConstPtr& ptr) const override;

@ -57,9 +57,9 @@ namespace MWClass
MWBase::Environment::get().getWorld()->adjustPosition(creature, force);
}
std::string CreatureLevList::getName (const MWWorld::ConstPtr& ptr) const
std::string_view CreatureLevList::getName(const MWWorld::ConstPtr& ptr) const
{
return "";
return {};
}
bool CreatureLevList::hasToolTip(const MWWorld::ConstPtr& ptr) const

@ -15,7 +15,7 @@ namespace MWClass
public:
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -100,7 +100,7 @@ namespace MWClass
return getClassModel<ESM::Door>(ptr);
}
std::string Door::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Door::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
const std::string& name = ref->mBase->mName;
@ -115,8 +115,8 @@ namespace MWClass
const std::string &openSound = ref->mBase->mOpenSound;
const std::string &closeSound = ref->mBase->mCloseSound;
const std::string lockedSound = "LockedDoor";
const std::string trapActivationSound = "Disarm Trap Fail";
const std::string_view lockedSound = "LockedDoor";
const std::string_view trapActivationSound = "Disarm Trap Fail";
MWWorld::ContainerStore &invStore = actor.getClass().getContainerStore(actor);
@ -267,7 +267,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Door> *ref = ptr.get<ESM::Door>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
std::string text;
@ -282,7 +283,7 @@ namespace MWClass
text += "\n#{sLockLevel}: " + MWGui::ToolTips::toString(ptr.getCellRef().getLockLevel());
else if (ptr.getCellRef().getLockLevel() < 0)
text += "\n#{sUnlocked}";
if (ptr.getCellRef().getTrap() != "")
if (!ptr.getCellRef().getTrap().empty())
text += "\n#{sTrapped}";
if (MWBase::Environment::get().getWindowManager()->getFullHelp())

@ -29,7 +29,7 @@ namespace MWClass
bool useAnim() const override;
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -41,7 +41,7 @@ namespace MWClass
return getClassModel<ESM::Ingredient>(ptr);
}
std::string Ingredient::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Ingredient::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>();
const std::string& name = ref->mBase->mName;
@ -101,7 +101,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Ingredient> *ref = ptr.get<ESM::Ingredient>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -9,9 +9,9 @@ namespace MWClass
{
}
std::string ItemLevList::getName (const MWWorld::ConstPtr& ptr) const
std::string_view ItemLevList::getName(const MWWorld::ConstPtr& ptr) const
{
return "";
return {};
}
bool ItemLevList::hasToolTip(const MWWorld::ConstPtr& ptr) const

@ -13,7 +13,7 @@ namespace MWClass
public:
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -72,12 +72,12 @@ namespace MWClass
return getClassModel<ESM::Light>(ptr);
}
std::string Light::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Light::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
if (ref->mBase->mModel.empty())
return std::string();
return {};
const std::string& name = ref->mBase->mName;
return !name.empty() ? name : ref->mBase->mId;
@ -150,7 +150,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Light> *ref = ptr.get<ESM::Light>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -23,7 +23,7 @@ namespace MWClass
bool useAnim() const override;
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -41,7 +41,7 @@ namespace MWClass
return getClassModel<ESM::Lockpick>(ptr);
}
std::string Lockpick::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Lockpick::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Lockpick> *ref = ptr.get<ESM::Lockpick>();
const std::string& name = ref->mBase->mName;
@ -100,7 +100,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Lockpick> *ref = ptr.get<ESM::Lockpick>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -51,7 +51,7 @@ namespace MWClass
return getClassModel<ESM::Miscellaneous>(ptr);
}
std::string Miscellaneous::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Miscellaneous::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Miscellaneous> *ref = ptr.get<ESM::Miscellaneous>();
const std::string& name = ref->mBase->mName;
@ -80,7 +80,7 @@ namespace MWClass
if (ptr.getCellRef().getGoldValue() > 1 && ptr.getRefData().getCount() == 1)
value = ptr.getCellRef().getGoldValue();
if (ptr.getCellRef().getSoul() != "")
if (!ptr.getCellRef().getSoul().empty())
{
const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().search(ref->mRef.getSoul());
if (creature)
@ -142,7 +142,8 @@ namespace MWClass
else // gold displays its count also if it's 1.
countString = " (" + std::to_string(count) + ")";
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + countString + MWGui::ToolTips::getSoulString(ptr.getCellRef());
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;
@ -171,7 +172,7 @@ namespace MWClass
if (isGold(ptr)) {
int goldAmount = getValue(ptr) * count;
std::string base = "Gold_001";
std::string_view base = "Gold_001";
if (goldAmount >= 100)
base = "Gold_100";
else if (goldAmount >= 25)
@ -203,7 +204,7 @@ namespace MWClass
std::unique_ptr<MWWorld::Action> Miscellaneous::use (const MWWorld::Ptr& ptr, bool force) const
{
const std::string soulgemPrefix = "misc_soulgem";
const std::string_view soulgemPrefix = "misc_soulgem";
if (::Misc::StringUtils::ciCompareLen(ptr.getCellRef().getRefId(), soulgemPrefix, soulgemPrefix.length()) == 0)
return std::make_unique<MWWorld::ActionSoulgem>(ptr);

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -523,7 +523,7 @@ namespace MWClass
}
std::string Npc::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Npc::getName(const MWWorld::ConstPtr& ptr) const
{
if(ptr.getRefData().getCustomData() && ptr.getRefData().getCustomData()->asNpcCustomData().mNpcStats.isWerewolf())
{
@ -1117,7 +1117,8 @@ namespace MWClass
bool fullHelp = MWBase::Environment::get().getWindowManager()->getFullHelp();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr));
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()});
if(fullHelp && !ref->mBase->mName.empty() && ptr.getRefData().getCustomData() && ptr.getRefData().getCustomData()->asNpcCustomData().mNpcStats.isWerewolf())
{
info.caption += " (";

@ -53,7 +53,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
MWMechanics::CreatureStats& getCreatureStats (const MWWorld::Ptr& ptr) const override;

@ -43,7 +43,7 @@ namespace MWClass
return getClassModel<ESM::Potion>(ptr);
}
std::string Potion::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Potion::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Potion> *ref = ptr.get<ESM::Potion>();
const std::string& name = ref->mBase->mName;
@ -94,7 +94,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Potion> *ref = ptr.get<ESM::Potion>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -41,7 +41,7 @@ namespace MWClass
return getClassModel<ESM::Probe>(ptr);
}
std::string Probe::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Probe::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Probe> *ref = ptr.get<ESM::Probe>();
const std::string& name = ref->mBase->mName;
@ -100,7 +100,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Probe> *ref = ptr.get<ESM::Probe>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -38,7 +38,7 @@ namespace MWClass
return getClassModel<ESM::Repair>(ptr);
}
std::string Repair::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Repair::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>();
const std::string& name = ref->mBase->mName;
@ -101,7 +101,8 @@ namespace MWClass
const MWWorld::LiveCellRef<ESM::Repair> *ref = ptr.get<ESM::Repair>();
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
std::string text;

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -44,9 +44,9 @@ namespace MWClass
return getClassModel<ESM::Static>(ptr);
}
std::string Static::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Static::getName(const MWWorld::ConstPtr& ptr) const
{
return "";
return {};
}
bool Static::hasToolTip(const MWWorld::ConstPtr& ptr) const

@ -21,7 +21,7 @@ namespace MWClass
void insertObject(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override;
void insertObjectPhysics(const MWWorld::Ptr& ptr, const std::string& model, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const override;
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
bool hasToolTip (const MWWorld::ConstPtr& ptr) const override;

@ -47,7 +47,7 @@ namespace MWClass
return getClassModel<ESM::Weapon>(ptr);
}
std::string Weapon::getName (const MWWorld::ConstPtr& ptr) const
std::string_view Weapon::getName(const MWWorld::ConstPtr& ptr) const
{
const MWWorld::LiveCellRef<ESM::Weapon> *ref = ptr.get<ESM::Weapon>();
const std::string& name = ref->mBase->mName;
@ -150,7 +150,8 @@ namespace MWClass
const ESM::WeaponType* weaponType = MWMechanics::getWeaponType(ref->mBase->mData.mType);
MWGui::ToolTipInfo info;
info.caption = MyGUI::TextIterator::toTagsString(getName(ptr)) + MWGui::ToolTips::getCountString(count);
std::string_view name = getName(ptr);
info.caption = MyGUI::TextIterator::toTagsString({name.data(), name.size()}) + MWGui::ToolTips::getCountString(count);
info.icon = ref->mBase->mIcon;
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
@ -164,7 +165,7 @@ namespace MWClass
int skill = MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill;
const std::string type = ESM::Skill::sSkillNameIds[skill];
std::string oneOrTwoHanded;
std::string_view oneOrTwoHanded;
if (weaponType->mWeaponClass == ESM::WeaponType::Melee)
{
if (weaponType->mFlags & ESM::WeaponType::TwoHanded)
@ -173,8 +174,9 @@ namespace MWClass
oneOrTwoHanded = "sOneHanded";
}
text += store.get<ESM::GameSetting>().find(type)->mValue.getString() +
((oneOrTwoHanded != "") ? ", " + store.get<ESM::GameSetting>().find(oneOrTwoHanded)->mValue.getString() : "");
text += store.get<ESM::GameSetting>().find(type)->mValue.getString();
if (!oneOrTwoHanded.empty())
text += ", " + store.get<ESM::GameSetting>().find(oneOrTwoHanded)->mValue.getString();
// weapon damage
if (weaponType->mWeaponClass == ESM::WeaponType::Thrown)

@ -18,7 +18,7 @@ namespace MWClass
void insertObjectRendering (const MWWorld::Ptr& ptr, const std::string& model, MWRender::RenderingInterface& renderingInterface) const override;
///< Add reference into a cell for rendering
std::string getName (const MWWorld::ConstPtr& ptr) const override;
std::string_view getName(const MWWorld::ConstPtr& ptr) const override;
///< \return name or ID; can return an empty string.
std::unique_ptr<MWWorld::Action> activate (const MWWorld::Ptr& ptr,

@ -130,7 +130,7 @@ namespace MWDialogue
topic.addEntry (entry);
}
void Journal::removeLastAddedTopicResponse(const std::string &topicId, const std::string &actorName)
void Journal::removeLastAddedTopicResponse(const std::string &topicId, std::string_view actorName)
{
Topic& topic = getTopic (topicId);

@ -41,7 +41,7 @@ namespace MWDialogue
void addTopic (const std::string& topicId, const std::string& infoId, const MWWorld::Ptr& actor) override;
/// \note topicId must be lowercase
void removeLastAddedTopicResponse (const std::string& topicId, const std::string& actorName) override;
void removeLastAddedTopicResponse(const std::string& topicId, std::string_view actorName) override;
///< Removes the last topic response added for the given topicId and actor name.
/// \note topicId must be lowercase

@ -59,7 +59,7 @@ namespace MWDialogue
return mEntries.end();
}
void Topic::removeLastAddedResponse (const std::string& actorName)
void Topic::removeLastAddedResponse(std::string_view actorName)
{
for (std::vector<MWDialogue::Entry>::reverse_iterator it = mEntries.rbegin();
it != mEntries.rend(); ++it)

@ -2,6 +2,7 @@
#define GAME_MWDIALOG_TOPIC_H
#include <string>
#include <string_view>
#include <vector>
#include "journalentry.hpp"
@ -48,7 +49,7 @@ namespace MWDialogue
virtual std::string getName() const;
void removeLastAddedResponse (const std::string& actorName);
void removeLastAddedResponse(std::string_view actorName);
TEntryIter begin() const;
///< Iterator pointing to the begin of the journal for this topic.

@ -197,7 +197,7 @@ namespace MWGui
if (item.getType() != ESM::Ingredient::sRecordId)
continue;
itemNames.insert(item.getClass().getName(item));
itemNames.emplace(item.getClass().getName(item));
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
auto const alchemySkill = player.getClass().getSkill(player, ESM::Skill::Alchemy);

@ -89,7 +89,8 @@ void CompanionWindow::onItemSelected(int index)
if (count > 1 && !shift)
{
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef());
std::string name{object.getClass().getName(object)};
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count);
dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &CompanionWindow::dragItem);

@ -83,7 +83,8 @@ namespace MWGui
if (count > 1 && !shift)
{
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef());
std::string name{object.getClass().getName(object)};
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, "#{sTake}", count);
dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &ContainerWindow::dragItem);

@ -98,7 +98,8 @@ namespace MWGui
}
else
{
mName->setCaption(item.getClass().getName(item));
std::string_view name = item.getClass().getName(item);
mName->setCaption({name.data(), name.size()});
mItemBox->setItem(item);
mItemBox->setUserString ("ToolTipType", "ItemPtr");
mItemBox->setUserData(MWWorld::Ptr(item));

@ -422,7 +422,7 @@ namespace MWGui
void HUD::setSelectedEnchantItem(const MWWorld::Ptr& item, int chargePercent)
{
std::string itemName = item.getClass().getName(item);
std::string_view itemName = item.getClass().getName(item);
if (itemName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;
@ -442,7 +442,7 @@ namespace MWGui
void HUD::setSelectedWeapon(const MWWorld::Ptr& item, int durabilityPercent)
{
std::string itemName = item.getClass().getName(item);
std::string_view itemName = item.getClass().getName(item);
if (itemName != mWeaponName && mWeaponVisible)
{
mWeaponSpellTimer = 5.0f;

@ -293,7 +293,8 @@ namespace MWGui
{
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string message = mTrading ? "#{sQuanityMenuMessage01}" : "#{sTake}";
std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef());
std::string name{object.getClass().getName(object)};
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, message, count);
dialog->eventOkClicked.clear();
if (mTrading)

@ -169,7 +169,8 @@ namespace MWGui
void ItemChargeView::updateLine(const ItemChargeView::Line& line)
{
line.mText->setCaption(line.mItemPtr.getClass().getName(line.mItemPtr));
std::string_view name = line.mItemPtr.getClass().getName(line.mItemPtr);
line.mText->setCaption({name.data(), name.size()});
line.mCharge->setVisible(false);
switch (mDisplayMode)

@ -52,12 +52,13 @@ namespace MWGui
static_cast<MyGUI::TextBox*>(pt)->setCaption(caption);
}
void Layout::setTitle(const std::string& title)
void Layout::setTitle(std::string_view title)
{
MyGUI::Window* window = static_cast<MyGUI::Window*>(mMainWidget);
MyGUI::UString uTitle{title.data(), title.size()};
if (window->getCaption() != title)
window->setCaptionWithReplacing(title);
if (window->getCaption() != uTitle)
window->setCaptionWithReplacing(uTitle);
}
MyGUI::Widget* Layout::getWidget(std::string_view _name)

@ -64,7 +64,7 @@ namespace MWGui
void setText(std::string_view name, const std::string& caption);
// NOTE: this assume that mMainWidget is of type Window.
void setTitle(const std::string& title);
void setTitle(std::string_view title);
MyGUI::Widget* mMainWidget;

@ -67,8 +67,8 @@ void MerchantRepair::setPtr(const MWWorld::Ptr &actor)
int price = MWBase::Environment::get().getMechanicsManager()->getBarterOffer(mActor, x, true);
std::string name = iter->getClass().getName(*iter)
+ " - " + MyGUI::utility::toString(price)
std::string name{iter->getClass().getName(*iter)};
name += " - " + MyGUI::utility::toString(price)
+ MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>()
.find("sgp")->mValue.getString();

@ -188,7 +188,8 @@ namespace MWGui
{
CountDialog* dialog = MWBase::Environment::get().getWindowManager()->getCountDialog();
std::string message = "#{sQuanityMenuMessage02}";
std::string name = object.getClass().getName(object) + MWGui::ToolTips::getSoulString(object.getCellRef());
std::string name{object.getClass().getName(object)};
name += MWGui::ToolTips::getSoulString(object.getCellRef());
dialog->openCountDialog(name, message, count);
dialog->eventOkClicked.clear();
dialog->eventOkClicked += MyGUI::newDelegate(this, &TradeWindow::sellItem);

@ -160,7 +160,7 @@ namespace MWScript
{
// The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory
std::string msgBox;
std::string itemName = itemPtr.getClass().getName(itemPtr);
std::string_view itemName = itemPtr.getClass().getName(itemPtr);
if (count == 1)
{
msgBox = MyGUI::LanguageManager::getInstance().replaceTags("#{sNotifyMessage60}");
@ -256,7 +256,7 @@ namespace MWScript
}
MWWorld::ContainerStore& store = ptr.getClass().getContainerStore (ptr);
std::string itemName;
std::string_view itemName;
for (MWWorld::ConstContainerStoreIterator iter(store.cbegin()); iter != store.cend(); ++iter)
{
if (::Misc::StringUtils::ciEqual(iter->getCellRef().getRefId(), item))

@ -43,7 +43,8 @@ namespace MWWorld
MWBase::Environment::get().getMechanicsManager()->itemTaken(actor, *it, target, itemCount);
actorStore.add(*it, itemCount, actor);
store.remove(*it, itemCount, getTarget());
takenMap[it->getClass().getName(*it)]+=itemCount;
std::string name{it->getClass().getName(*it)};
takenMap[name]+=itemCount;
}
// Spawn a messagebox (only for items added to player's inventory)

@ -84,7 +84,7 @@ namespace MWWorld
///< Add reference into a cell for rendering (default implementation: don't render anything).
virtual void insertObjectPhysics(const Ptr& ptr, const std::string& mesh, const osg::Quat& rotation, MWPhysics::PhysicsSystem& physics) const;
virtual std::string getName (const ConstPtr& ptr) const = 0;
virtual std::string_view getName(const ConstPtr& ptr) const = 0;
///< \return name or ID; can return an empty string.
virtual void adjustPosition(const MWWorld::Ptr& ptr, bool force) const;

@ -16,10 +16,15 @@ namespace Misc::StringUtils
template <typename T>
T argument(T value) noexcept
{
static_assert(!std::is_same_v<T, std::string_view>, "std::string_view is not supported");
return value;
}
template <typename T>
T const * argument(std::basic_string_view<T> const & value) noexcept
{
return value.data();
}
template <typename T>
T const * argument(std::basic_string<T> const & value) noexcept
{

@ -122,14 +122,14 @@ public:
return ch;
}
static std::string lowerCaseUtf8(const std::string& str)
static std::string lowerCaseUtf8(std::string_view str)
{
if (str.empty())
return str;
return std::string{str};
// Decode string as utf8 characters, convert to lower case and pack them to string
std::string out;
Utf8Stream stream (str.c_str());
Utf8Stream stream (str);
while (!stream.eof ())
{
UnicodeChar character = toLowerUtf8(stream.peek());

Loading…
Cancel
Save