[Repositories] Add more precise types to repository generator (#2391)

* Make utils/scripts/generators/repository-generator.pl aware of more
datatypes

This adds support for unsigned and more integer types. It also avoids
using parsing functions that require casting (still needed in some
cases)

Having the data types in the Repository structs better map to the types
in the database will allow us to avoid casting when we pull data out of
them. And as a benefit, assume something is wrong if we do :)

Hopefully clean up some warnings due to casting too.

Co-authored-by: Akkadius <akkadius1@gmail.com>
This commit is contained in:
Michael Cook (mackal)
2022-08-31 01:04:27 -04:00
committed by GitHub
parent fcf01f6d87
commit 6f7fa98996
183 changed files with 7849 additions and 7818 deletions
@@ -19,12 +19,12 @@
class BaseTraderRepository {
public:
struct Trader {
int char_id;
int item_id;
int serialnumber;
int charges;
int item_cost;
int slot_id;
uint32_t char_id;
uint32_t item_id;
uint32_t serialnumber;
int32_t charges;
uint32_t item_cost;
uint8_t slot_id;
};
static std::string PrimaryKey()
@@ -134,12 +134,12 @@ public:
if (results.RowCount() == 1) {
Trader e{};
e.char_id = atoi(row[0]);
e.item_id = atoi(row[1]);
e.serialnumber = atoi(row[2]);
e.charges = atoi(row[3]);
e.item_cost = atoi(row[4]);
e.slot_id = atoi(row[5]);
e.char_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.item_id = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.serialnumber = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
e.charges = static_cast<int32_t>(atoi(row[3]));
e.item_cost = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
e.slot_id = static_cast<uint8_t>(strtoul(row[5], nullptr, 10));
return e;
}
@@ -274,12 +274,12 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Trader e{};
e.char_id = atoi(row[0]);
e.item_id = atoi(row[1]);
e.serialnumber = atoi(row[2]);
e.charges = atoi(row[3]);
e.item_cost = atoi(row[4]);
e.slot_id = atoi(row[5]);
e.char_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.item_id = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.serialnumber = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
e.charges = static_cast<int32_t>(atoi(row[3]));
e.item_cost = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
e.slot_id = static_cast<uint8_t>(strtoul(row[5], nullptr, 10));
all_entries.push_back(e);
}
@@ -304,12 +304,12 @@ public:
for (auto row = results.begin(); row != results.end(); ++row) {
Trader e{};
e.char_id = atoi(row[0]);
e.item_id = atoi(row[1]);
e.serialnumber = atoi(row[2]);
e.charges = atoi(row[3]);
e.item_cost = atoi(row[4]);
e.slot_id = atoi(row[5]);
e.char_id = static_cast<uint32_t>(strtoul(row[0], nullptr, 10));
e.item_id = static_cast<uint32_t>(strtoul(row[1], nullptr, 10));
e.serialnumber = static_cast<uint32_t>(strtoul(row[2], nullptr, 10));
e.charges = static_cast<int32_t>(atoi(row[3]));
e.item_cost = static_cast<uint32_t>(strtoul(row[4], nullptr, 10));
e.slot_id = static_cast<uint8_t>(strtoul(row[5], nullptr, 10));
all_entries.push_back(e);
}