aboutsummaryrefslogtreecommitdiff
path: root/works/life/cpp-practicum/Record.cpp
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-12-30 15:37:39 +0800
committercrupest <crupest@outlook.com>2020-12-30 15:37:39 +0800
commite0964bbc4f66e7d193abd249213c9cf762fd0294 (patch)
treeee4f5307fc555ef66a3752e20388dca8f386c2f1 /works/life/cpp-practicum/Record.cpp
parent7e9e803b33a9380d2ff3111c8d11f25f5d2b98ec (diff)
downloadcrupest-e0964bbc4f66e7d193abd249213c9cf762fd0294.tar.gz
crupest-e0964bbc4f66e7d193abd249213c9cf762fd0294.tar.bz2
crupest-e0964bbc4f66e7d193abd249213c9cf762fd0294.zip
import(life): ...
Diffstat (limited to 'works/life/cpp-practicum/Record.cpp')
-rw-r--r--works/life/cpp-practicum/Record.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/works/life/cpp-practicum/Record.cpp b/works/life/cpp-practicum/Record.cpp
new file mode 100644
index 0000000..1041b23
--- /dev/null
+++ b/works/life/cpp-practicum/Record.cpp
@@ -0,0 +1,38 @@
+#include "Record.hpp"
+
+void Record::WriteTo(QFile file) {
+ file.open(QFile::ReadWrite | QFile::Text | QFile::Truncate);
+ QTextStream stream(&file);
+ stream.setCodec("UTF-8");
+
+ stream << books_.size() << ' ' << vendors_.size() << '\n';
+ for (const auto &book : books_) {
+ stream << book << '\n';
+ }
+ for (const auto &vendor : vendors_) {
+ stream << vendor << '\n';
+ }
+}
+
+void Record::ReadFrom(QFile file) {
+ file.open(QFile::ReadOnly | QFile::Text);
+ QTextStream stream(&file);
+ stream.setCodec("UTF-8");
+
+ books_.clear();
+ vendors_.clear();
+
+ int book_count, vendor_count;
+ stream >> book_count >> vendor_count;
+ stream.skipWhiteSpace();
+ for (int i = 0; i < book_count; i++) {
+ Book book;
+ stream >> book;
+ books_.push_back(std::move(book));
+ }
+ for (int i = 0; i < vendor_count; i++) {
+ Vendor vendor;
+ stream >> vendor;
+ vendors_.push_back(std::move(vendor));
+ }
+}