Commit 73130e7e authored by Gauthier Quesnel's avatar Gauthier Quesnel
Browse files

io: use c++ stream to fix Win32 FS API

parent 33871967
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "imnodes.hpp" #include "imnodes.hpp"
#include <filesystem> #include <filesystem>
#include <fstream>
#include <future> #include <future>
#include <mutex> #include <mutex>
#include <string> #include <string>
...@@ -733,13 +734,15 @@ struct editor ...@@ -733,13 +734,15 @@ struct editor
if (!path.empty() && ImGui::MenuItem("Save")) { if (!path.empty() && ImGui::MenuItem("Save")) {
log_w.log(3, "Write into file %s\n", path.string().c_str()); log_w.log(3, "Write into file %s\n", path.string().c_str());
writer w(std::fopen(path.string().c_str(), "w")); if (auto os = std::ofstream(path); os.is_open()) {
writer w(os);
auto ret = w(sim); auto ret = w(sim);
if (is_success(ret)) if (is_success(ret))
log_w.log(5, "success\n"); log_w.log(5, "success\n");
else else
log_w.log(4, "error writing\n"); log_w.log(4, "error writing\n");
} }
}
if (ImGui::MenuItem("Save as...")) if (ImGui::MenuItem("Save as..."))
show_save_file_dialog = true; show_save_file_dialog = true;
...@@ -788,7 +791,8 @@ struct editor ...@@ -788,7 +791,8 @@ struct editor
if (load_file_dialog(path)) { if (load_file_dialog(path)) {
show_load_file_dialog = false; show_load_file_dialog = false;
log_w.log(5, "Load file from %s\n", path.string().c_str()); log_w.log(5, "Load file from %s\n", path.string().c_str());
reader r(std::fopen(path.string().c_str(), "r")); if (auto is = std::ifstream(path); is.is_open()) {
reader r(is);
auto ret = r(sim); auto ret = r(sim);
if (is_success(ret)) if (is_success(ret))
log_w.log(5, "success\n"); log_w.log(5, "success\n");
...@@ -796,6 +800,7 @@ struct editor ...@@ -796,6 +800,7 @@ struct editor
log_w.log(4, "error writing\n"); log_w.log(4, "error writing\n");
} }
} }
}
if (show_save_file_dialog) { if (show_save_file_dialog) {
static std::string out; static std::string out;
...@@ -809,7 +814,8 @@ struct editor ...@@ -809,7 +814,8 @@ struct editor
log_w.log(5, "Save file to %s\n", path.string().c_str()); log_w.log(5, "Save file to %s\n", path.string().c_str());
log_w.log(3, "Write into file %s\n", path.string().c_str()); log_w.log(3, "Write into file %s\n", path.string().c_str());
writer w(std::fopen(path.string().c_str(), "w")); if (auto os = std::ofstream(path); os.is_open()) {
writer w(os);
auto ret = w(sim); auto ret = w(sim);
if (is_success(ret)) if (is_success(ret))
log_w.log(5, "success\n"); log_w.log(5, "success\n");
...@@ -817,6 +823,7 @@ struct editor ...@@ -817,6 +823,7 @@ struct editor
log_w.log(4, "error writing\n"); log_w.log(4, "error writing\n");
} }
} }
}
ImGui::Text("X -- delete selected nodes and/or connections /" ImGui::Text("X -- delete selected nodes and/or connections /"
" D -- duplicate selected nodes"); " D -- duplicate selected nodes");
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <fmt/format.h> #include <fmt/format.h>
#include <cstdio> #include <iostream>
struct file_output struct file_output
{ {
...@@ -859,8 +859,7 @@ main() ...@@ -859,8 +859,7 @@ main()
expect(sim.models.can_alloc(2)); expect(sim.models.can_alloc(2));
expect( expect(
irt::is_success(sim.alloc(gen, sim.generator_models.get_id(gen)))); irt::is_success(sim.alloc(gen, sim.generator_models.get_id(gen))));
expect( expect(irt::is_success(sim.alloc(cnt, sim.counter_models.get_id(cnt))));
irt::is_success(sim.alloc(cnt, sim.counter_models.get_id(cnt))));
expect(sim.connect(gen.y[0], cnt.x[0]) == irt::status::success); expect(sim.connect(gen.y[0], cnt.x[0]) == irt::status::success);
...@@ -1013,7 +1012,7 @@ main() ...@@ -1013,7 +1012,7 @@ main()
expect(sim.connect(integrator_b.y[0], quantifier_b.x[0]) == expect(sim.connect(integrator_b.y[0], quantifier_b.x[0]) ==
irt::status::success); irt::status::success);
irt::dot_writer dw(stdout); irt::dot_writer dw(std::cout);
dw(sim); dw(sim);
file_output fo_a("lotka-volterra_a.csv"); file_output fo_a("lotka-volterra_a.csv");
...@@ -1193,7 +1192,7 @@ main() ...@@ -1193,7 +1192,7 @@ main()
irt::status::success); irt::status::success);
expect(sim.connect(constant.y[0], sum_d.x[1]) == irt::status::success); expect(sim.connect(constant.y[0], sum_d.x[1]) == irt::status::success);
irt::dot_writer dw(stdout); irt::dot_writer dw(std::cout);
dw(sim); dw(sim);
file_output fo_a("izhikevitch_a.csv"); file_output fo_a("izhikevitch_a.csv");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment