Skip to content

Commit 0b2fa01

Browse files
committed
Replace uses of fmt as far as possible with std::format
Also adds helpers like join and toUnderlying to replace currently missing format capabilities
1 parent da516e6 commit 0b2fa01

52 files changed

Lines changed: 194 additions & 180 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ include_directories(
334334
target_link_libraries(imgui_platform glfw)
335335

336336
add_definitions(-DGLM_ENABLE_EXPERIMENTAL)
337-
add_definitions(-DSPDLOG_FMT_EXTERNAL)
337+
add_definitions(-DSPDLOG_USE_STD_FORMAT)
338338

339339
# ------------------------------------
340340
# Libraries for awe

src/awe/binfolfile.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
*/
2020

2121
#include <memory>
22+
#include <format>
23+
24+
#include "src/common/exception.h"
2225

2326
#include "src/awe/path.h"
2427
#include "src/awe/binfolfile.h"
@@ -29,7 +32,7 @@ BINFOLFile::BINFOLFile(Common::ReadStream &binfol) {
2932

3033
const auto version = binfol.readUint32LE();
3134
if (version != 19)
32-
throw std::runtime_error(fmt::format("Unsupported version {}. Expected 19", version));
35+
throw Common::SourceException("Unsupported version {}. Expected 19", version);
3336

3437
const auto meshDataSize = binfol.readUint32LE();
3538
std::unique_ptr<Common::ReadStream> binmshStream(binfol.readStream(meshDataSize));

src/awe/binmshfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void BINMSHFile::load(Common::ReadStream &binmsh) {
3939
const uint32_t version = binmsh.readUint32LE();
4040

4141
if (version != 21 && version != 20 && version != 19)
42-
throw std::runtime_error(fmt::format("Unsupported version {}", version));
42+
throw std::runtime_error(std::format("Unsupported version {}", version));
4343

4444
const uint32_t vertexBufferSize = binmsh.readUint32LE();
4545
const uint32_t indicesCount = binmsh.readUint32LE();

src/awe/foliagedatafile.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
#include <stdexcept>
2222
#include <regex>
2323

24-
#include <fmt/format.h>
24+
#include "src/common/exception.h"
2525

26-
#include "foliagedatafile.h"
26+
#include "src/awe/foliagedatafile.h"
2727

2828
namespace AWE {
2929

3030
FoliageDataFile::FoliageDataFile(Common::ReadStream &foliageData) {
3131
const uint32_t version = foliageData.readUint32LE();
3232
if (version != 9)
33-
throw std::runtime_error(fmt::format("Unsupported version, expected 9, got {}", version));
33+
throw Common::SourceException("Unsupported version, expected 9, got {}", version);
3434

3535
const uint32_t numFoliages = foliageData.readUint32LE();
3636
_foliages.resize(numFoliages);

src/awe/havokfile.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <map>
2525

2626
#include <glm/glm.hpp>
27-
#include <fmt/format.h>
2827
#include <spdlog/spdlog.h>
2928

3029
#include "src/common/exception.h"
@@ -1370,7 +1369,7 @@ void HavokFile::setHeader(std::string headerVersion) {
13701369
else if (headerVersion == "hk_2010.2.0-r1")
13711370
_version = kHavok2010_2_0_r1;
13721371
else
1373-
throw std::runtime_error(fmt::format("Unsupported havok version {}", headerVersion));
1372+
throw std::runtime_error(std::format("Unsupported havok version {}", headerVersion));
13741373

13751374
}
13761375

src/awe/objectxmlwritestream.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
* along with OpenAWE. If not, see <http://www.gnu.org/licenses/>.
1919
*/
2020

21-
#include <fmt/format.h>
2221
#include <glm/gtx/string_cast.hpp>
2322
#include <utility>
2423

@@ -110,7 +109,7 @@ void ObjectXMLWriteStream::variable(const std::string &name, GID &value) {
110109
auto &typeNode = newVariableNode.addNewNode("type");
111110
typeNode.content = std::to_string(value.type);
112111
auto &hashNode = newVariableNode.addNewNode("hash");
113-
hashNode.content = fmt::format("0x{:x}", value.id);
112+
hashNode.content = std::format("0x{:x}", value.id);
114113
}
115114

116115
void ObjectXMLWriteStream::variable(const std::string &name, ObjectID &value) {
@@ -120,7 +119,7 @@ void ObjectXMLWriteStream::variable(const std::string &name, ObjectID &value) {
120119
auto &typeNode = newVariableNode.addNewNode("type");
121120
typeNode.content = std::to_string(value.getType());
122121
auto &hashNode = newVariableNode.addNewNode("id");
123-
hashNode.content = fmt::format("0x{:x}", value.getID());
122+
hashNode.content = std::format("0x{:x}", value.getID());
124123
}
125124

126125
void ObjectXMLWriteStream::variable(const std::string &name, std::vector<bool> &value, size_t fixedSize) {
@@ -182,7 +181,7 @@ void ObjectXMLWriteStream::variable(const std::string &name, std::vector<rid_t>
182181

183182
for (const auto &item: value) {
184183
auto &itemNode = newVariableNode.addNewNode("item");
185-
itemNode.content = fmt::format("{:x}", item);
184+
itemNode.content = std::format("{:x}", item);
186185
}
187186
}
188187

@@ -236,7 +235,7 @@ void ObjectXMLWriteStream::variable(const std::string &name, std::vector<GID> &v
236235
typeNode.content = std::to_string(gid.type);
237236

238237
auto &idNode = itemNode.addNewNode("id");
239-
idNode.content = fmt::format("{:x}", gid.id);
238+
idNode.content = std::format("{:x}", gid.id);
240239
}
241240
}
242241

src/awe/resman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Common::ReadStream *RessourceManager::getResource(const std::string &path) {
114114
return new Common::ReadFile(_rootPath + "/" + path);
115115

116116
for (const auto &dirPath: _paths) {
117-
const auto fullPath = fmt::format("{}/{}", dirPath, path);
117+
const auto fullPath = std::format("{}/{}", dirPath, path);
118118
if (std::filesystem::is_regular_file(fullPath))
119119
return new Common::ReadFile(fullPath);
120120
}

src/awe/rmdblobarchive.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ RMDBlobArchive::RMDBlobArchive(Common::ReadStream &rmdtoc, const std::string &pa
9898
std::make_unique<Common::ReadFile>(
9999
path.empty()
100100
? std::filesystem::path(blobPath).filename().string()
101-
: fmt::format("{}/{}", path, std::filesystem::path(blobPath).filename().string())
101+
: std::format("{}/{}", path, std::filesystem::path(blobPath).filename().string())
102102
)
103103
);
104104
}
@@ -135,8 +135,6 @@ RMDBlobArchive::RMDBlobArchive(Common::ReadStream &rmdtoc, const std::string &pa
135135
for (size_t j = 0; j < fileCount; ++j) {
136136
_files[j + fileIndex].directory = i;
137137
}
138-
139-
fmt::print("{}\n", name);
140138
}
141139

142140
for (unsigned int i = 0; i < fileTableCount; ++i) {

src/awe/rmdparchive.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
#include <vector>
2727
#include <mutex>
2828

29-
#include <fmt/format.h>
30-
3129
#include "src/common/endianreadstream.h"
3230
#include "src/common/strutil.h"
3331
#include "src/common/memreadstream.h"

src/awe/script/bytecode.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <stdexcept>
2222

2323
#include <spdlog/spdlog.h>
24-
#include <fmt/format.h>
2524

2625
#include "src/common/exception.h"
2726

0 commit comments

Comments
 (0)