1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Merge branch 'recordtype' into 'master'

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

See merge request OpenMW/openmw!1290
This commit is contained in:
Evil Eye 2021-10-13 17:04:32 +00:00
commit ec6451e93a
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)
{
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;
}
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;
}

View File

@ -728,8 +728,8 @@ int MWWorld::ContainerStore::getType (const ConstPtr& ptr)
if (ptr.getType()==ESM::Weapon::sRecordId)
return Type_Weapon;
throw std::runtime_error (
"Object '" + ptr.getCellRef().getRefId() + "' of type " + ptr.getTypeDescription() + " can not be placed into a container");
throw std::runtime_error("Object '" + ptr.getCellRef().getRefId() + "' of type " +
std::string(ptr.getTypeDescription()) + " can not be placed into a container");
}
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;
///< Save LiveCellRef state into \a state.
virtual std::string getTypeDescription() const { return ""; }
virtual std::string_view getTypeDescription() const = 0;
protected:
@ -95,7 +95,7 @@ namespace MWWorld
void save (ESM::ObjectState& state) const override;
///< 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);
///< Check if state is valid and report errors.

View File

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

View File

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

View File

@ -13,7 +13,7 @@ struct Activator
{
static unsigned int sRecordId;
/// 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;
std::string mId, mName, mScript, mModel;

View File

@ -20,7 +20,7 @@ struct Potion
static unsigned int sRecordId;
/// 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
{

View File

@ -17,7 +17,7 @@ struct Apparatus
{
static unsigned int sRecordId;
/// 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
{

View File

@ -67,7 +67,7 @@ struct Armor
{
static unsigned int sRecordId;
/// 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
{

View File

@ -13,7 +13,7 @@ struct BodyPart
{
static unsigned int sRecordId;
/// 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
{

View File

@ -16,7 +16,7 @@ struct Book
{
static unsigned int sRecordId;
/// 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
{

View File

@ -15,7 +15,7 @@ struct BirthSign
{
static unsigned int sRecordId;
/// 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;
std::string mId, mName, mDescription, mTexture;

View File

@ -65,7 +65,7 @@ struct Cell
{
static unsigned int sRecordId;
/// 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
{

View File

@ -19,7 +19,7 @@ struct Class
{
static unsigned int sRecordId;
/// 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
{

View File

@ -19,7 +19,7 @@ struct Clothing
{
static unsigned int sRecordId;
/// 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
{

View File

@ -37,7 +37,7 @@ struct Container
{
static unsigned int sRecordId;
/// 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
{

View File

@ -23,7 +23,7 @@ struct Creature
{
static unsigned int sRecordId;
/// 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?
enum Flags

View File

@ -22,7 +22,7 @@ struct Dialogue
{
static unsigned int sRecordId;
/// 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
{

View File

@ -13,7 +13,7 @@ struct Door
{
static unsigned int sRecordId;
/// 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;
std::string mId, mName, mModel, mScript, mOpenSound, mCloseSound;

View File

@ -19,7 +19,7 @@ struct Enchantment
{
static unsigned int sRecordId;
/// 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
{

View File

@ -32,7 +32,7 @@ struct Faction
{
static unsigned int sRecordId;
/// 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;
std::string mId, mName;

View File

@ -19,7 +19,7 @@ struct Global
{
static unsigned int sRecordId;
/// 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;
std::string mId;

View File

@ -20,7 +20,7 @@ struct GameSetting
{
static unsigned int sRecordId;
/// 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;
std::string mId;

View File

@ -22,7 +22,7 @@ struct DialInfo
{
static unsigned int sRecordId;
/// 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
{

View File

@ -17,7 +17,7 @@ struct Ingredient
{
static unsigned int sRecordId;
/// 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
{

View File

@ -21,7 +21,7 @@ struct Land
{
static unsigned int sRecordId;
/// 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();

View File

@ -48,7 +48,7 @@ struct CreatureLevList: LevelledListBase
{
static unsigned int sRecordId;
/// 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
{
@ -68,7 +68,7 @@ struct ItemLevList: LevelledListBase
{
static unsigned int sRecordId;
/// 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
{

View File

@ -18,7 +18,7 @@ struct Light
{
static unsigned int sRecordId;
/// 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
{

View File

@ -13,7 +13,7 @@ struct Lockpick
{
static unsigned int sRecordId;
/// 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
{

View File

@ -20,7 +20,7 @@ struct LandTexture
{
static unsigned int sRecordId;
/// 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.
std::string mId, mTexture;

View File

@ -14,7 +14,7 @@ struct MagicEffect
{
static unsigned int sRecordId;
/// 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;
std::string mId;

View File

@ -18,7 +18,7 @@ struct Miscellaneous
{
static unsigned int sRecordId;
/// 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
{

View File

@ -24,7 +24,7 @@ struct NPC
{
static unsigned int sRecordId;
/// 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
enum Services

View File

@ -17,7 +17,7 @@ struct Pathgrid
{
static unsigned int sRecordId;
/// 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
{

View File

@ -13,7 +13,7 @@ struct Probe
{
static unsigned int sRecordId;
/// 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
{

View File

@ -19,7 +19,7 @@ struct Race
{
static unsigned int sRecordId;
/// 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
{

View File

@ -20,7 +20,7 @@ struct Region
{
static unsigned int sRecordId;
/// 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(1)

View File

@ -13,7 +13,7 @@ struct Repair
{
static unsigned int sRecordId;
/// 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
{

View File

@ -21,7 +21,7 @@ class Script
public:
static unsigned int sRecordId;
/// 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
{

View File

@ -20,7 +20,7 @@ struct Skill
{
static unsigned int sRecordId;
/// 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;
std::string mId;

View File

@ -17,7 +17,7 @@ struct SoundGenerator
{
static unsigned int sRecordId;
/// 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
{

View File

@ -18,7 +18,7 @@ struct Sound
{
static unsigned int sRecordId;
/// 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;
unsigned int mRecordFlags;

View File

@ -15,7 +15,7 @@ struct Spell
{
static unsigned int sRecordId;
/// 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
{

View File

@ -21,7 +21,7 @@ struct StartScript
{
static unsigned int sRecordId;
/// 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;
unsigned int mRecordFlags;

View File

@ -24,7 +24,7 @@ struct Static
{
static unsigned int sRecordId;
/// 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;
std::string mId, mModel;

View File

@ -19,7 +19,7 @@ struct Weapon
{
static unsigned int sRecordId;
/// 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
{