mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
add const where possible
This commit is contained in:
@@ -167,7 +167,7 @@ void AddCSVWindow::onOk(wxCommandEvent&) {
|
|||||||
/// Perform the import
|
/// Perform the import
|
||||||
wxBusyCursor wait;
|
wxBusyCursor wait;
|
||||||
// Read the file
|
// Read the file
|
||||||
auto file = std::ifstream(file_path->GetValue().ToStdString());
|
auto& file = std::ifstream(file_path->GetValue().ToStdString());
|
||||||
if (file.fail()) {
|
if (file.fail()) {
|
||||||
queue_message(MESSAGE_ERROR, _ERROR_("add card csv file not found"));
|
queue_message(MESSAGE_ERROR, _ERROR_("add card csv file not found"));
|
||||||
EndModal(wxID_ABORT);
|
EndModal(wxID_ABORT);
|
||||||
|
|||||||
@@ -139,14 +139,14 @@ void AddJSONWindow::onBrowseFiles(wxCommandEvent&) {
|
|||||||
queue_message(MESSAGE_ERROR, _ERROR_("add card json empty array"));
|
queue_message(MESSAGE_ERROR, _ERROR_("add card json empty array"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
auto& card = card_array[0];
|
const auto& first_card = card_array[0];
|
||||||
if (!card.is_object()) {
|
if (!first_card.is_object()) {
|
||||||
queue_message(MESSAGE_ERROR, _ERROR_("add card json path not valid"));
|
queue_message(MESSAGE_ERROR, _ERROR_("add card json path not valid"));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Get headers
|
// Get headers
|
||||||
for (int i = 0; i < count; ++i) {
|
for (int i = 0; i < count; ++i) {
|
||||||
auto& card = card_array[i].as_object();
|
const auto& card = card_array[i].as_object();
|
||||||
for (auto it = card.begin(); it != card.end(); ++it) {
|
for (auto it = card.begin(); it != card.end(); ++it) {
|
||||||
boost::json::string_view jview = it->key();
|
boost::json::string_view jview = it->key();
|
||||||
std::string_view stdview = std::string_view(jview.data(), jview.size());
|
std::string_view stdview = std::string_view(jview.data(), jview.size());
|
||||||
@@ -162,7 +162,7 @@ void AddJSONWindow::onBrowseFiles(wxCommandEvent&) {
|
|||||||
std::vector<ScriptValueP> row;
|
std::vector<ScriptValueP> row;
|
||||||
auto& card = card_array[i].as_object();
|
auto& card = card_array[i].as_object();
|
||||||
for (int h = 0; h < headers_out.size(); ++h) {
|
for (int h = 0; h < headers_out.size(); ++h) {
|
||||||
auto& value = card[headers_out[h].ToStdString()];
|
const auto& value = card[headers_out[h].ToStdString()];
|
||||||
row.push_back(json_to_mse(value, set.get()));
|
row.push_back(json_to_mse(value, set.get()));
|
||||||
}
|
}
|
||||||
table_out.push_back(row);
|
table_out.push_back(row);
|
||||||
@@ -174,7 +174,7 @@ void AddJSONWindow::onOk(wxCommandEvent&) {
|
|||||||
/// Perform the import
|
/// Perform the import
|
||||||
wxBusyCursor wait;
|
wxBusyCursor wait;
|
||||||
// Read the file
|
// Read the file
|
||||||
auto file = std::ifstream(file_path->GetValue().ToStdString());
|
auto& file = std::ifstream(file_path->GetValue().ToStdString());
|
||||||
if (file.fail()) {
|
if (file.fail()) {
|
||||||
queue_message(MESSAGE_ERROR, _ERROR_("add card json file not found"));
|
queue_message(MESSAGE_ERROR, _ERROR_("add card json file not found"));
|
||||||
EndModal(wxID_ABORT);
|
EndModal(wxID_ABORT);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------- : JSON to String
|
// ----------------------------------------------------------------------------- : JSON to String
|
||||||
|
|
||||||
inline static void pretty_print(std::ostream& os, boost::json::value const& jv, std::string* indent = nullptr)
|
inline static void pretty_print(std::ostream& os, const boost::json::value& jv, std::string* indent = nullptr)
|
||||||
{
|
{
|
||||||
std::string indent_;
|
std::string indent_;
|
||||||
if(! indent)
|
if(! indent)
|
||||||
@@ -106,21 +106,21 @@ inline static void pretty_print(std::ostream& os, boost::json::value const& jv,
|
|||||||
os << "\n";
|
os << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static String json_pretty_print(boost::json::value const& jv, std::string* indent = nullptr) {
|
inline static String json_pretty_print(const boost::json::value& jv, std::string* indent = nullptr) {
|
||||||
std::ostringstream stream;
|
std::ostringstream stream;
|
||||||
pretty_print(stream, jv, indent);
|
pretty_print(stream, jv, indent);
|
||||||
String string = wxString(stream.str().c_str());
|
String string = wxString(stream.str().c_str());
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static String json_ugly_print(boost::json::value const& jv) {
|
inline static String json_ugly_print(const boost::json::value& jv) {
|
||||||
String string = wxString(boost::json::serialize(jv).c_str());
|
String string = wxString(boost::json::serialize(jv).c_str());
|
||||||
return string;
|
return string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : JSON to MSE
|
// ----------------------------------------------------------------------------- : JSON to MSE
|
||||||
|
|
||||||
inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set);
|
inline static ScriptValueP json_to_mse(const boost::json::value& jv, Set* set);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void read(T& out, boost::json::object& jv, const char value_name[]) {
|
static void read(T& out, boost::json::object& jv, const char value_name[]) {
|
||||||
@@ -301,7 +301,7 @@ inline static SetP json_to_mse_set(boost::json::object& jv) {
|
|||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set) {
|
inline static ScriptValueP json_to_mse(const boost::json::value& jv, Set* set) {
|
||||||
if (jv == nullptr) return script_nil;
|
if (jv == nullptr) return script_nil;
|
||||||
else if (jv.is_null()) return script_nil;
|
else if (jv.is_null()) return script_nil;
|
||||||
else if (jv.is_bool()) return to_script(jv.get_bool());
|
else if (jv.is_bool()) return to_script(jv.get_bool());
|
||||||
@@ -358,7 +358,7 @@ inline static ScriptValueP json_to_mse(boost::json::value& jv, Set* set) {
|
|||||||
return script_nil;
|
return script_nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline static ScriptValueP json_to_mse(String& string, Set* set) {
|
inline static ScriptValueP json_to_mse(const String& string, Set* set) {
|
||||||
try {
|
try {
|
||||||
boost::system::error_code ec;
|
boost::system::error_code ec;
|
||||||
boost::json::parse_options options;
|
boost::json::parse_options options;
|
||||||
@@ -372,7 +372,7 @@ inline static ScriptValueP json_to_mse(String& string, Set* set) {
|
|||||||
return script_nil;
|
return script_nil;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inline static ScriptValueP json_to_mse(ScriptValueP& sv, Set* set) {
|
inline static ScriptValueP json_to_mse(const ScriptValueP& sv, Set* set) {
|
||||||
try {
|
try {
|
||||||
String string = sv->toString();
|
String string = sv->toString();
|
||||||
return json_to_mse(string, set);
|
return json_to_mse(string, set);
|
||||||
@@ -386,7 +386,7 @@ inline static ScriptValueP json_to_mse(ScriptValueP& sv, Set* set) {
|
|||||||
// ----------------------------------------------------------------------------- : MSE to JSON
|
// ----------------------------------------------------------------------------- : MSE to JSON
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static void write(boost::json::object& out, const String& name, T& value) {
|
static void write(boost::json::object& out, const String& name, const T& value) {
|
||||||
wxStringOutputStream stream;
|
wxStringOutputStream stream;
|
||||||
Writer writer(stream);
|
Writer writer(stream);
|
||||||
writer.indentation = -1000;
|
writer.indentation = -1000;
|
||||||
|
|||||||
Reference in New Issue
Block a user