diff --git a/apps/benchmarks/detournavigator/navmeshtilescache.cpp b/apps/benchmarks/detournavigator/navmeshtilescache.cpp index 976f7a46e1..9ee2d5d435 100644 --- a/apps/benchmarks/detournavigator/navmeshtilescache.cpp +++ b/apps/benchmarks/detournavigator/navmeshtilescache.cpp @@ -5,7 +5,6 @@ #include #include -#include namespace { diff --git a/apps/essimporter/converter.hpp b/apps/essimporter/converter.hpp index ac891e78df..4ae39b0e65 100644 --- a/apps/essimporter/converter.hpp +++ b/apps/essimporter/converter.hpp @@ -2,7 +2,6 @@ #define OPENMW_ESSIMPORT_CONVERTER_H #include -#include #include #include @@ -544,9 +543,7 @@ public: } else { - std::stringstream error; - error << "Invalid weather ID:" << weatherID << std::endl; - throw std::runtime_error(error.str()); + throw std::runtime_error("Invalid weather ID: " + std::to_string(weatherID)); } } diff --git a/apps/opencs/model/filter/andnode.cpp b/apps/opencs/model/filter/andnode.cpp index 7578657178..508202edfc 100644 --- a/apps/opencs/model/filter/andnode.cpp +++ b/apps/opencs/model/filter/andnode.cpp @@ -1,7 +1,5 @@ #include "andnode.hpp" -#include - CSMFilter::AndNode::AndNode (const std::vector >& nodes) : NAryNode (nodes, "and") {} diff --git a/apps/opencs/model/filter/ornode.cpp b/apps/opencs/model/filter/ornode.cpp index 9e6d8b2c46..d6abaca40b 100644 --- a/apps/opencs/model/filter/ornode.cpp +++ b/apps/opencs/model/filter/ornode.cpp @@ -1,7 +1,5 @@ #include "ornode.hpp" -#include - CSMFilter::OrNode::OrNode (const std::vector >& nodes) : NAryNode (nodes, "or") {} diff --git a/apps/opencs/model/tools/mergestages.cpp b/apps/opencs/model/tools/mergestages.cpp index 021cf61d81..9b24f6ccf9 100644 --- a/apps/opencs/model/tools/mergestages.cpp +++ b/apps/opencs/model/tools/mergestages.cpp @@ -1,8 +1,5 @@ - #include "mergestages.hpp" -#include - #include #include "mergestate.hpp" diff --git a/apps/opencs/model/tools/scriptcheck.cpp b/apps/opencs/model/tools/scriptcheck.cpp index 46a74362b0..6fa2dfcfc9 100644 --- a/apps/opencs/model/tools/scriptcheck.cpp +++ b/apps/opencs/model/tools/scriptcheck.cpp @@ -1,5 +1,7 @@ #include "scriptcheck.hpp" +#include + #include #include #include diff --git a/apps/opencs/model/world/scriptcontext.cpp b/apps/opencs/model/world/scriptcontext.cpp index 9b465d7ffb..2b6a9231b1 100644 --- a/apps/opencs/model/world/scriptcontext.cpp +++ b/apps/opencs/model/world/scriptcontext.cpp @@ -1,6 +1,7 @@ #include "scriptcontext.hpp" #include +#include #include diff --git a/apps/opencs/model/world/universalid.cpp b/apps/opencs/model/world/universalid.cpp index 486f3770aa..1f11e21bdc 100644 --- a/apps/opencs/model/world/universalid.cpp +++ b/apps/opencs/model/world/universalid.cpp @@ -1,6 +1,5 @@ #include "universalid.hpp" -#include #include #include #include @@ -405,8 +404,3 @@ bool CSMWorld::operator< (const UniversalId& left, const UniversalId& right) { return left.isLess (right); } - -std::ostream& CSMWorld::operator< (std::ostream& stream, const CSMWorld::UniversalId& universalId) -{ - return stream << universalId.toString(); -} diff --git a/apps/opencs/model/world/universalid.hpp b/apps/opencs/model/world/universalid.hpp index accd1b78da..09fd8f3bb9 100644 --- a/apps/opencs/model/world/universalid.hpp +++ b/apps/opencs/model/world/universalid.hpp @@ -2,7 +2,6 @@ #define CSM_WOLRD_UNIVERSALID_H #include -#include #include #include @@ -199,8 +198,6 @@ namespace CSMWorld bool operator!= (const UniversalId& left, const UniversalId& right); bool operator< (const UniversalId& left, const UniversalId& right); - - std::ostream& operator< (std::ostream& stream, const UniversalId& universalId); } Q_DECLARE_METATYPE (CSMWorld::UniversalId) diff --git a/apps/opencs/view/render/terraintexturemode.cpp b/apps/opencs/view/render/terraintexturemode.cpp index 20467e9514..3127306522 100644 --- a/apps/opencs/view/render/terraintexturemode.cpp +++ b/apps/opencs/view/render/terraintexturemode.cpp @@ -1,7 +1,6 @@ #include "terraintexturemode.hpp" #include -#include #include #include diff --git a/apps/opencs/view/world/scripterrortable.cpp b/apps/opencs/view/world/scripterrortable.cpp index 45809b28c6..a331820a2b 100644 --- a/apps/opencs/view/world/scripterrortable.cpp +++ b/apps/opencs/view/world/scripterrortable.cpp @@ -1,5 +1,7 @@ #include "scripterrortable.hpp" +#include + #include #include diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index e0b88bba12..a8ea3fdf02 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -2,6 +2,7 @@ #include #include +#include #include diff --git a/apps/openmw/mwdialogue/scripttest.cpp b/apps/openmw/mwdialogue/scripttest.cpp index c3d7b12c7d..1b192aec15 100644 --- a/apps/openmw/mwdialogue/scripttest.cpp +++ b/apps/openmw/mwdialogue/scripttest.cpp @@ -19,6 +19,8 @@ #include "filter.hpp" +#include + namespace { diff --git a/apps/openmw/mwgui/journalviewmodel.cpp b/apps/openmw/mwgui/journalviewmodel.cpp index fc3fcc3efe..1d1c954d8a 100644 --- a/apps/openmw/mwgui/journalviewmodel.cpp +++ b/apps/openmw/mwgui/journalviewmodel.cpp @@ -1,7 +1,6 @@ #include "journalviewmodel.hpp" #include -#include #include diff --git a/apps/openmw/mwgui/statswatcher.cpp b/apps/openmw/mwgui/statswatcher.cpp index ccb77de8f2..883fd265cc 100644 --- a/apps/openmw/mwgui/statswatcher.cpp +++ b/apps/openmw/mwgui/statswatcher.cpp @@ -11,6 +11,8 @@ #include "../mwworld/esmstore.hpp" #include "../mwworld/inventorystore.hpp" +#include + namespace MWGui { // mWatchedTimeToStartDrowning = -1 for correct drowning state check, @@ -36,11 +38,8 @@ namespace MWGui { if (stats.getAttribute(i) != mWatchedAttributes[i] || mWatchedStatsEmpty) { - std::stringstream attrname; - attrname << "AttribVal"<<(i+1); - mWatchedAttributes[i] = stats.getAttribute(i); - setValue(attrname.str(), stats.getAttribute(i)); + setValue("AttribVal" + std::to_string(i + 1), stats.getAttribute(i)); } } diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 7ea3b9a205..9005d26975 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -19,7 +19,7 @@ #include "character.hpp" -#include +#include #include #include diff --git a/apps/openmw/mwmechanics/npcstats.cpp b/apps/openmw/mwmechanics/npcstats.cpp index ef49381eff..34dcbb79a4 100644 --- a/apps/openmw/mwmechanics/npcstats.cpp +++ b/apps/openmw/mwmechanics/npcstats.cpp @@ -1,6 +1,7 @@ #include "npcstats.hpp" #include +#include #include #include diff --git a/apps/openmw/mwrender/ripplesimulation.cpp b/apps/openmw/mwrender/ripplesimulation.cpp index 5aa7c29154..037ed4455f 100644 --- a/apps/openmw/mwrender/ripplesimulation.cpp +++ b/apps/openmw/mwrender/ripplesimulation.cpp @@ -1,6 +1,7 @@ #include "ripplesimulation.hpp" #include +#include #include #include diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index f641f0ee4b..b84cc6b222 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/apps/openmw/mwsound/ffmpeg_decoder.hpp b/apps/openmw/mwsound/ffmpeg_decoder.hpp index c57740ff55..0af9a77d98 100644 --- a/apps/openmw/mwsound/ffmpeg_decoder.hpp +++ b/apps/openmw/mwsound/ffmpeg_decoder.hpp @@ -27,7 +27,6 @@ extern "C" #include #include -#include #include "sound_decoder.hpp" diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index b9baee7223..3ee76326f4 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include diff --git a/apps/openmw/mwworld/actionequip.cpp b/apps/openmw/mwworld/actionequip.cpp index 92cd044386..8ce3a130ab 100644 --- a/apps/openmw/mwworld/actionequip.cpp +++ b/apps/openmw/mwworld/actionequip.cpp @@ -65,11 +65,7 @@ namespace MWWorld } if (it == invStore.end()) - { - std::stringstream error; - error << "ActionEquip can't find item " << object.getCellRef().getRefId(); - throw std::runtime_error(error.str()); - } + throw std::runtime_error("ActionEquip can't find item " + object.getCellRef().getRefId()); // equip the item in the first free slot std::vector::const_iterator slot=slots_.first.begin(); diff --git a/apps/openmw/mwworld/esmstore.hpp b/apps/openmw/mwworld/esmstore.hpp index dd0be016c2..defefccb9c 100644 --- a/apps/openmw/mwworld/esmstore.hpp +++ b/apps/openmw/mwworld/esmstore.hpp @@ -2,7 +2,6 @@ #define OPENMW_MWWORLD_ESMSTORE_H #include -#include #include #include diff --git a/apps/openmw/mwworld/livecellref.cpp b/apps/openmw/mwworld/livecellref.cpp index ad9cdabb38..53c936564b 100644 --- a/apps/openmw/mwworld/livecellref.cpp +++ b/apps/openmw/mwworld/livecellref.cpp @@ -1,5 +1,7 @@ #include "livecellref.hpp" +#include + #include #include @@ -78,3 +80,20 @@ unsigned int MWWorld::LiveCellRefBase::getType() const { return mClass->getType(); } + +namespace MWWorld +{ + std::string makeDynamicCastErrorMessage(const LiveCellRefBase* value, std::string_view recordType) + { + std::stringstream message; + + message << "Bad LiveCellRef cast to " << recordType << " from "; + + if (value != nullptr) + message << value->getTypeDescription(); + else + message << "an empty object"; + + return message.str(); + } +} diff --git a/apps/openmw/mwworld/livecellref.hpp b/apps/openmw/mwworld/livecellref.hpp index 1ead0395fd..bee6f2ba57 100644 --- a/apps/openmw/mwworld/livecellref.hpp +++ b/apps/openmw/mwworld/livecellref.hpp @@ -5,6 +5,8 @@ #include "refdata.hpp" +#include + namespace ESM { struct ObjectState; @@ -16,6 +18,9 @@ namespace MWWorld class ESMStore; class Class; + template + struct LiveCellRef; + /// Used to create pointers to hold any type of LiveCellRef<> object. struct LiveCellRefBase { @@ -46,6 +51,12 @@ namespace MWWorld unsigned int getType() const; ///< @see MWWorld::Class::getType + template + static const LiveCellRef* dynamicCast(const LiveCellRefBase* value); + + template + static LiveCellRef* dynamicCast(LiveCellRefBase* value); + protected: void loadImp (const ESM::ObjectState& state); @@ -70,6 +81,24 @@ namespace MWWorld return cellRef.mRef.getRefNum()==refNum; } + std::string makeDynamicCastErrorMessage(const LiveCellRefBase* value, std::string_view recordType); + + template + const LiveCellRef* LiveCellRefBase::dynamicCast(const LiveCellRefBase* value) + { + if (const LiveCellRef* ref = dynamic_cast*>(value)) + return ref; + throw std::runtime_error(makeDynamicCastErrorMessage(value, T::getRecordType())); + } + + template + LiveCellRef* LiveCellRefBase::dynamicCast(LiveCellRefBase* value) + { + if (LiveCellRef* ref = dynamic_cast*>(value)) + return ref; + throw std::runtime_error(makeDynamicCastErrorMessage(value, T::getRecordType())); + } + /// A reference to one object (of any type) in a cell. /// /// Constructing this with a CellRef instance in the constructor means that @@ -125,7 +154,6 @@ namespace MWWorld { return checkStateImp (state); } - } #endif diff --git a/apps/openmw/mwworld/projectilemanager.cpp b/apps/openmw/mwworld/projectilemanager.cpp index 6ede604eea..3894569682 100644 --- a/apps/openmw/mwworld/projectilemanager.cpp +++ b/apps/openmw/mwworld/projectilemanager.cpp @@ -1,9 +1,10 @@ #include "projectilemanager.hpp" #include - +#include #include #include + #include #include diff --git a/apps/openmw/mwworld/ptr.hpp b/apps/openmw/mwworld/ptr.hpp index 33e062df90..af5a632a98 100644 --- a/apps/openmw/mwworld/ptr.hpp +++ b/apps/openmw/mwworld/ptr.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include "livecellref.hpp" @@ -76,19 +75,8 @@ namespace MWWorld throw std::runtime_error("Cannot get class of an empty object"); } - template - TypeTransform> *get() const - { - TypeTransform> *ref = dynamic_cast>*>(mRef); - if(ref) return ref; - - std::stringstream str; - str<< "Bad LiveCellRef cast to "< + auto* get() const { return LiveCellRefBase::dynamicCast(mRef); } LiveCellRefBaseType *getBase() const { diff --git a/apps/openmw_test_suite/detournavigator/operators.hpp b/apps/openmw_test_suite/detournavigator/operators.hpp index 60e1400764..c2d9424db2 100644 --- a/apps/openmw_test_suite/detournavigator/operators.hpp +++ b/apps/openmw_test_suite/detournavigator/operators.hpp @@ -6,9 +6,7 @@ #include #include -#include #include -#include #include diff --git a/components/bsa/memorystream.hpp b/components/bsa/memorystream.hpp index 0b7e0da9e2..f36f1e23f4 100644 --- a/components/bsa/memorystream.hpp +++ b/components/bsa/memorystream.hpp @@ -27,7 +27,7 @@ #define BSA_MEMORY_STREAM_H #include -#include +#include #include namespace Bsa diff --git a/components/compiler/scanner.cpp b/components/compiler/scanner.cpp index 6cf2d6e7c0..161de1bb76 100644 --- a/components/compiler/scanner.cpp +++ b/components/compiler/scanner.cpp @@ -1,6 +1,7 @@ #include "scanner.hpp" #include +#include #include "exception.hpp" #include "errorhandler.hpp" diff --git a/components/compiler/scanner.hpp b/components/compiler/scanner.hpp index 7a77811f2a..7c80f622ee 100644 --- a/components/compiler/scanner.hpp +++ b/components/compiler/scanner.hpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "tokenloc.hpp" diff --git a/components/compiler/streamerrorhandler.hpp b/components/compiler/streamerrorhandler.hpp index ad34166953..f70c64d25d 100644 --- a/components/compiler/streamerrorhandler.hpp +++ b/components/compiler/streamerrorhandler.hpp @@ -1,8 +1,6 @@ #ifndef COMPILER_STREAMERRORHANDLER_H_INCLUDED #define COMPILER_STREAMERRORHANDLER_H_INCLUDED -#include - #include "errorhandler.hpp" namespace Compiler diff --git a/components/crashcatcher/windows_crashcatcher.cpp b/components/crashcatcher/windows_crashcatcher.cpp index e9eb60e845..d31fdac578 100644 --- a/components/crashcatcher/windows_crashcatcher.cpp +++ b/components/crashcatcher/windows_crashcatcher.cpp @@ -2,7 +2,6 @@ #include #include -#include #include #include diff --git a/components/crashcatcher/windows_crashmonitor.cpp b/components/crashcatcher/windows_crashmonitor.cpp index 2693f7681d..e76e8897e1 100644 --- a/components/crashcatcher/windows_crashmonitor.cpp +++ b/components/crashcatcher/windows_crashmonitor.cpp @@ -5,9 +5,7 @@ #include -#include #include -#include #include #include diff --git a/components/esm/format.cpp b/components/esm/format.cpp index b41d81d57d..7ed109a580 100644 --- a/components/esm/format.cpp +++ b/components/esm/format.cpp @@ -2,6 +2,9 @@ #include +#include +#include + namespace ESM { namespace diff --git a/components/esm/format.hpp b/components/esm/format.hpp index acd93b4075..6bb5e270c1 100644 --- a/components/esm/format.hpp +++ b/components/esm/format.hpp @@ -4,7 +4,7 @@ #include "defs.hpp" #include -#include +#include #include namespace ESM diff --git a/components/files/constrainedfilestream.hpp b/components/files/constrainedfilestream.hpp index bed4242ec4..c32c719f22 100644 --- a/components/files/constrainedfilestream.hpp +++ b/components/files/constrainedfilestream.hpp @@ -4,7 +4,7 @@ #include "constrainedfilestreambuf.hpp" #include "streamwithbuffer.hpp" -#include +#include #include #include #include diff --git a/components/files/hash.hpp b/components/files/hash.hpp index 13d56d5824..a39961e4d5 100644 --- a/components/files/hash.hpp +++ b/components/files/hash.hpp @@ -3,7 +3,7 @@ #include #include -#include +#include #include namespace Files diff --git a/components/fx/pass.hpp b/components/fx/pass.hpp index 7f2e643c8c..829fb716cf 100644 --- a/components/fx/pass.hpp +++ b/components/fx/pass.hpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include diff --git a/components/nif/nifkey.hpp b/components/nif/nifkey.hpp index 7736ab7ad9..bcf186f333 100644 --- a/components/nif/nifkey.hpp +++ b/components/nif/nifkey.hpp @@ -5,7 +5,6 @@ #include "nifstream.hpp" -#include #include #include "niffile.hpp" @@ -103,9 +102,7 @@ struct KeyMapT { } else if (count != 0) { - std::stringstream error; - error << "Unhandled interpolation type: " << mInterpolationType; - nif->file->fail(error.str()); + nif->file->fail("Unhandled interpolation type: " + std::to_string(mInterpolationType)); } if (morph && nif->getVersion() > NIFStream::generateVersion(10,1,0,0)) diff --git a/components/nif/node.hpp b/components/nif/node.hpp index 725511e997..29c0f03e78 100644 --- a/components/nif/node.hpp +++ b/components/nif/node.hpp @@ -130,9 +130,7 @@ struct NiBoundingVolume } default: { - std::stringstream error; - error << "Unhandled NiBoundingVolume type: " << type; - nif->file->fail(error.str()); + nif->file->fail("Unhandled NiBoundingVolume type: " + std::to_string(type)); } } } diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index ec86e2ccb5..424a45d65a 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/components/shader/shadermanager.cpp b/components/shader/shadermanager.cpp index 97162a8986..8136bab447 100644 --- a/components/shader/shadermanager.cpp +++ b/components/shader/shadermanager.cpp @@ -4,12 +4,10 @@ #include #include #include +#include #include -#include -#include - #include #include #include diff --git a/components/stereo/frustum.cpp b/components/stereo/frustum.cpp index 31104d66f3..d9727e9ea6 100644 --- a/components/stereo/frustum.cpp +++ b/components/stereo/frustum.cpp @@ -13,7 +13,6 @@ #include #include -#include #include #include diff --git a/components/stereo/stereomanager.cpp b/components/stereo/stereomanager.cpp index 829cb6cc9c..7964c5c134 100644 --- a/components/stereo/stereomanager.cpp +++ b/components/stereo/stereomanager.cpp @@ -14,7 +14,6 @@ #include #include -#include #include #include diff --git a/components/terrain/chunkmanager.cpp b/components/terrain/chunkmanager.cpp index badca42977..ae4fd339aa 100644 --- a/components/terrain/chunkmanager.cpp +++ b/components/terrain/chunkmanager.cpp @@ -1,7 +1,5 @@ #include "chunkmanager.hpp" -#include - #include #include diff --git a/components/vfs/registerarchives.cpp b/components/vfs/registerarchives.cpp index 9e1b13fede..ebe2683edd 100644 --- a/components/vfs/registerarchives.cpp +++ b/components/vfs/registerarchives.cpp @@ -1,8 +1,8 @@ #include "registerarchives.hpp" #include -#include #include +#include #include @@ -33,9 +33,7 @@ namespace VFS } else { - std::stringstream message; - message << "Archive '" << *archive << "' not found"; - throw std::runtime_error(message.str()); + throw std::runtime_error("Archive '" + *archive + "' not found"); } }