1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 20:39:40 +00:00

Avoid copying std::string in MWWorld::Ptr::getTypeDescription()

This commit is contained in:
Petr Mikheev 2021-10-12 00:18:23 +02:00
parent d6613d3677
commit a8acc19988
46 changed files with 56 additions and 54 deletions

View file

@ -395,12 +395,12 @@ bool CSMTools::TopicInfoCheckStage::verifyId(const std::string& name, const CSMW
if (index == -1) if (index == -1)
{ {
messages.add(id, T::getRecordType() + " '" + name + "' does not exist", "", CSMDoc::Message::Severity_Error); messages.add(id, std::string(T::getRecordType()) + " '" + name + "' does not exist", "", CSMDoc::Message::Severity_Error);
return false; return false;
} }
else if (collection.getRecord(index).isDeleted()) else if (collection.getRecord(index).isDeleted())
{ {
messages.add(id, "Deleted " + T::getRecordType() + " record '" + name + "' is being referenced", "", CSMDoc::Message::Severity_Error); messages.add(id, "Deleted " + std::string(T::getRecordType()) + " record '" + name + "' is being referenced", "", CSMDoc::Message::Severity_Error);
return false; return false;
} }

View file

@ -728,8 +728,8 @@ int MWWorld::ContainerStore::getType (const ConstPtr& ptr)
if (ptr.getType()==ESM::Weapon::sRecordId) if (ptr.getType()==ESM::Weapon::sRecordId)
return Type_Weapon; return Type_Weapon;
throw std::runtime_error ( throw std::runtime_error("Object '" + ptr.getCellRef().getRefId() + "' of type " +
"Object '" + ptr.getCellRef().getRefId() + "' of type " + ptr.getTypeDescription() + " can not be placed into a container"); std::string(ptr.getTypeDescription()) + " can not be placed into a container");
} }
MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id) MWWorld::Ptr MWWorld::ContainerStore::findReplacement(const std::string& id)

View file

@ -41,7 +41,7 @@ namespace MWWorld
virtual void save (ESM::ObjectState& state) const = 0; virtual void save (ESM::ObjectState& state) const = 0;
///< Save LiveCellRef state into \a state. ///< Save LiveCellRef state into \a state.
virtual std::string getTypeDescription() const { return ""; } virtual std::string_view getTypeDescription() const = 0;
protected: protected:
@ -95,7 +95,7 @@ namespace MWWorld
void save (ESM::ObjectState& state) const override; void save (ESM::ObjectState& state) const override;
///< Save LiveCellRef state into \a state. ///< Save LiveCellRef state into \a state.
std::string getTypeDescription() const override { return X::getRecordType(); } std::string_view getTypeDescription() const override { return X::getRecordType(); }
static bool checkState (const ESM::ObjectState& state); static bool checkState (const ESM::ObjectState& state);
///< Check if state is valid and report errors. ///< Check if state is valid and report errors.

View file

@ -37,7 +37,7 @@ namespace MWWorld
unsigned int getType() const; unsigned int getType() const;
std::string getTypeDescription() const std::string_view getTypeDescription() const
{ {
return mRef ? mRef->getTypeDescription() : "nullptr"; return mRef ? mRef->getTypeDescription() : "nullptr";
} }
@ -118,7 +118,7 @@ namespace MWWorld
unsigned int getType() const; unsigned int getType() const;
std::string getTypeDescription() const std::string_view getTypeDescription() const
{ {
return mRef ? mRef->getTypeDescription() : "nullptr"; return mRef ? mRef->getTypeDescription() : "nullptr";
} }

View file

@ -64,8 +64,9 @@ namespace MWWorld
const T *ptr = search(index); const T *ptr = search(index);
if (ptr == nullptr) if (ptr == nullptr)
{ {
const std::string msg = T::getRecordType() + " with index " + std::to_string(index) + " not found"; std::stringstream msg;
throw std::runtime_error(msg); msg << T::getRecordType() << " with index " << index << " not found";
throw std::runtime_error(msg.str());
} }
return ptr; return ptr;
} }
@ -145,8 +146,9 @@ namespace MWWorld
const T *ptr = search(id); const T *ptr = search(id);
if (ptr == nullptr) if (ptr == nullptr)
{ {
const std::string msg = T::getRecordType() + " '" + id + "' not found"; std::stringstream msg;
throw std::runtime_error(msg); msg << T::getRecordType() << " '" << id << "' not found";
throw std::runtime_error(msg.str());
} }
return ptr; return ptr;
} }

View file

@ -13,7 +13,7 @@ struct Activator
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Activator"; } static std::string_view getRecordType() { return "Activator"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId, mName, mScript, mModel; std::string mId, mName, mScript, mModel;

View file

@ -20,7 +20,7 @@ struct Potion
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Potion"; } static std::string_view getRecordType() { return "Potion"; }
struct ALDTstruct struct ALDTstruct
{ {

View file

@ -17,7 +17,7 @@ struct Apparatus
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Apparatus"; } static std::string_view getRecordType() { return "Apparatus"; }
enum AppaType enum AppaType
{ {

View file

@ -67,7 +67,7 @@ struct Armor
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Armor"; } static std::string_view getRecordType() { return "Armor"; }
enum Type enum Type
{ {

View file

@ -13,7 +13,7 @@ struct BodyPart
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "BodyPart"; } static std::string_view getRecordType() { return "BodyPart"; }
enum MeshPart enum MeshPart
{ {

View file

@ -16,7 +16,7 @@ struct Book
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Book"; } static std::string_view getRecordType() { return "Book"; }
struct BKDTstruct struct BKDTstruct
{ {

View file

@ -15,7 +15,7 @@ struct BirthSign
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "BirthSign"; } static std::string_view getRecordType() { return "BirthSign"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId, mName, mDescription, mTexture; std::string mId, mName, mDescription, mTexture;

View file

@ -65,7 +65,7 @@ struct Cell
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Cell"; } static std::string_view getRecordType() { return "Cell"; }
enum Flags enum Flags
{ {

View file

@ -19,7 +19,7 @@ struct Class
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Class"; } static std::string_view getRecordType() { return "Class"; }
enum AutoCalc enum AutoCalc
{ {

View file

@ -19,7 +19,7 @@ struct Clothing
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Clothing"; } static std::string_view getRecordType() { return "Clothing"; }
enum Type enum Type
{ {

View file

@ -37,7 +37,7 @@ struct Container
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Container"; } static std::string_view getRecordType() { return "Container"; }
enum Flags enum Flags
{ {

View file

@ -23,7 +23,7 @@ struct Creature
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Creature"; } static std::string_view getRecordType() { return "Creature"; }
// Default is 0x48? // Default is 0x48?
enum Flags enum Flags

View file

@ -22,7 +22,7 @@ struct Dialogue
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Dialogue"; } static std::string_view getRecordType() { return "Dialogue"; }
enum Type enum Type
{ {

View file

@ -13,7 +13,7 @@ struct Door
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Door"; } static std::string_view getRecordType() { return "Door"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound; std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound;

View file

@ -19,7 +19,7 @@ struct Enchantment
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Enchantment"; } static std::string_view getRecordType() { return "Enchantment"; }
enum Type enum Type
{ {

View file

@ -32,7 +32,7 @@ struct Faction
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Faction"; } static std::string_view getRecordType() { return "Faction"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId, mName; std::string mId, mName;

View file

@ -19,7 +19,7 @@ struct Global
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Global"; } static std::string_view getRecordType() { return "Global"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId; std::string mId;

View file

@ -20,7 +20,7 @@ struct GameSetting
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "GameSetting"; } static std::string_view getRecordType() { return "GameSetting"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId; std::string mId;

View file

@ -22,7 +22,7 @@ struct DialInfo
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "DialInfo"; } static std::string_view getRecordType() { return "DialInfo"; }
enum Gender enum Gender
{ {

View file

@ -17,7 +17,7 @@ struct Ingredient
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Ingredient"; } static std::string_view getRecordType() { return "Ingredient"; }
struct IRDTstruct struct IRDTstruct
{ {

View file

@ -21,7 +21,7 @@ struct Land
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Land"; } static std::string_view getRecordType() { return "Land"; }
Land(); Land();
~Land(); ~Land();

View file

@ -48,7 +48,7 @@ struct CreatureLevList: LevelledListBase
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "CreatureLevList"; } static std::string_view getRecordType() { return "CreatureLevList"; }
enum Flags enum Flags
{ {
@ -68,7 +68,7 @@ struct ItemLevList: LevelledListBase
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "ItemLevList"; } static std::string_view getRecordType() { return "ItemLevList"; }
enum Flags enum Flags
{ {

View file

@ -18,7 +18,7 @@ struct Light
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Light"; } static std::string_view getRecordType() { return "Light"; }
enum Flags enum Flags
{ {

View file

@ -13,7 +13,7 @@ struct Lockpick
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Lockpick"; } static std::string_view getRecordType() { return "Lockpick"; }
struct Data struct Data
{ {

View file

@ -20,7 +20,7 @@ struct LandTexture
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "LandTexture"; } static std::string_view getRecordType() { return "LandTexture"; }
// mId is merely a user friendly name for the texture in the editor. // mId is merely a user friendly name for the texture in the editor.
std::string mId, mTexture; std::string mId, mTexture;

View file

@ -14,7 +14,7 @@ struct MagicEffect
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "MagicEffect"; } static std::string_view getRecordType() { return "MagicEffect"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId; std::string mId;

View file

@ -18,7 +18,7 @@ struct Miscellaneous
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Miscellaneous"; } static std::string_view getRecordType() { return "Miscellaneous"; }
struct MCDTstruct struct MCDTstruct
{ {

View file

@ -24,7 +24,7 @@ struct NPC
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "NPC"; } static std::string_view getRecordType() { return "NPC"; }
// Services // Services
enum Services enum Services

View file

@ -17,7 +17,7 @@ struct Pathgrid
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Pathgrid"; } static std::string_view getRecordType() { return "Pathgrid"; }
struct DATAstruct struct DATAstruct
{ {

View file

@ -13,7 +13,7 @@ struct Probe
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Probe"; } static std::string_view getRecordType() { return "Probe"; }
struct Data struct Data
{ {

View file

@ -19,7 +19,7 @@ struct Race
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Race"; } static std::string_view getRecordType() { return "Race"; }
struct SkillBonus struct SkillBonus
{ {

View file

@ -20,7 +20,7 @@ struct Region
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Region"; } static std::string_view getRecordType() { return "Region"; }
#pragma pack(push) #pragma pack(push)
#pragma pack(1) #pragma pack(1)

View file

@ -13,7 +13,7 @@ struct Repair
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Repair"; } static std::string_view getRecordType() { return "Repair"; }
struct Data struct Data
{ {

View file

@ -21,7 +21,7 @@ class Script
public: public:
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Script"; } static std::string_view getRecordType() { return "Script"; }
struct SCHDstruct struct SCHDstruct
{ {

View file

@ -20,7 +20,7 @@ struct Skill
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Skill"; } static std::string_view getRecordType() { return "Skill"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId; std::string mId;

View file

@ -17,7 +17,7 @@ struct SoundGenerator
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "SoundGenerator"; } static std::string_view getRecordType() { return "SoundGenerator"; }
enum Type enum Type
{ {

View file

@ -18,7 +18,7 @@ struct Sound
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Sound"; } static std::string_view getRecordType() { return "Sound"; }
SOUNstruct mData; SOUNstruct mData;
unsigned int mRecordFlags; unsigned int mRecordFlags;

View file

@ -15,7 +15,7 @@ struct Spell
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Spell"; } static std::string_view getRecordType() { return "Spell"; }
enum SpellType enum SpellType
{ {

View file

@ -21,7 +21,7 @@ struct StartScript
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "StartScript"; } static std::string_view getRecordType() { return "StartScript"; }
std::string mData; std::string mData;
unsigned int mRecordFlags; unsigned int mRecordFlags;

View file

@ -24,7 +24,7 @@ struct Static
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Static"; } static std::string_view getRecordType() { return "Static"; }
unsigned int mRecordFlags; unsigned int mRecordFlags;
std::string mId, mModel; std::string mId, mModel;

View file

@ -19,7 +19,7 @@ struct Weapon
{ {
static unsigned int sRecordId; static unsigned int sRecordId;
/// Return a string descriptor for this record type. Currently used for debugging / error logs only. /// Return a string descriptor for this record type. Currently used for debugging / error logs only.
static std::string getRecordType() { return "Weapon"; } static std::string_view getRecordType() { return "Weapon"; }
enum Type enum Type
{ {