Skip to content

Commit 985148c

Browse files
committed
working to make calchart parsing better.
1 parent d5e41a0 commit 985148c

19 files changed

+804
-929
lines changed

ccvers.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@
2828
#define CC_VERSION \
2929
MK_CC_VERSION(CC_MAJOR_VERSION, CC_MINOR_VERSION, CC_PATCH_VERSION)
3030

31+
static constexpr uint32_t kVersion = (CC_MAJOR_VERSION << 8) | CC_MINOR_VERSION;

src/CalChartFrame.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -625,22 +625,15 @@ void CalChartFrame::OnCmdPasteSheet(wxCommandEvent&)
625625
if (numPoints != GetShow()->GetNumPoints()) {
626626
wxMessageBox(wxString::Format("Cannot paste - number of points in pasted sheet (%i) does not match number of points in current show (%i)",
627627
numPoints, GetShow()->GetNumPoints()));
628+
wxTheClipboard->Close();
628629
return;
629630
}
630-
std::stringstream sheetStream;
631-
sheetStream.write((char*)(clipboardObject.GetData()) + sizeof(numPoints),
632-
clipboardObject.GetDataSize() - sizeof(numPoints));
631+
auto reader = CalChart::Reader({ (uint8_t const*)(clipboardObject.GetData()) + sizeof(numPoints),
632+
clipboardObject.GetDataSize() - sizeof(numPoints) });
633+
reader.Get<uint32_t>();
634+
reader.Get<uint32_t>();
633635

634-
CalChart::ReadLong(sheetStream);
635-
CalChart::ReadLong(sheetStream);
636-
637-
sheetStream.unsetf(std::ios_base::skipws);
638-
std::istream_iterator<uint8_t> theBegin(sheetStream);
639-
std::istream_iterator<uint8_t> theEnd{};
640-
std::vector<uint8_t> data(theBegin, theEnd);
641-
642-
CalChart::Show::Sheet_container_t sht(
643-
1, CalChart::Sheet(numPoints, data.data(), data.size()));
636+
CalChart::Show::Sheet_container_t sht(1, CalChart::Sheet(numPoints, reader));
644637
GetFieldView()->DoInsertSheets(sht, GetFieldView()->GetCurrentSheetNum());
645638
}
646639
wxTheClipboard->Close();

src/core/CalChartContinuity.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,16 @@ std::vector<std::unique_ptr<ContProcedure>> ParseContinuity(std::string const& s
6262
}
6363
}
6464

65-
std::vector<std::unique_ptr<ContProcedure>> Deserialize(std::vector<uint8_t> const& data)
65+
std::vector<std::unique_ptr<ContProcedure>> Deserialize(Reader reader)
6666
{
6767
auto result = std::vector<std::unique_ptr<ContProcedure>>{};
6868

69-
auto begin = data.data();
70-
auto end = data.data() + data.size();
71-
while (std::distance(begin, end) > 0) {
72-
auto next_result = std::unique_ptr<ContProcedure>{};
73-
std::tie(next_result, begin) = DeserializeContProcedure(begin, end);
69+
while (reader.size() > 0) {
70+
auto [ next_result, new_reader ] = DeserializeContProcedure(reader);
7471
result.push_back(std::move(next_result));
72+
reader = new_reader;
7573
}
76-
if (begin != end) {
74+
if (reader.size() != 0) {
7775
throw std::runtime_error("Error, did not parse all the data correctly");
7876
}
7977
return result;
@@ -99,8 +97,8 @@ Continuity::Continuity(std::vector<std::unique_ptr<ContProcedure>> from_cont)
9997
{
10098
}
10199

102-
Continuity::Continuity(std::vector<uint8_t> const& data)
103-
: m_parsedContinuity(Deserialize(data))
100+
Continuity::Continuity(Reader reader)
101+
: m_parsedContinuity(Deserialize(reader))
104102
{
105103
}
106104

@@ -175,7 +173,8 @@ void Continuity_serialize_test()
175173
}) {
176174
auto uut1 = Continuity{ i };
177175
auto serialize_result = uut1.Serialize();
178-
auto uut2 = Continuity{ serialize_result };
176+
auto reader = Reader({ serialize_result.data(), serialize_result.size()});
177+
auto uut2 = Continuity{ reader };
179178
assert(uut1 == uut2);
180179
}
181180
}

src/core/CalChartContinuity.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Continuity {
5050
// this could throw runtime_error on bad parses.
5151
Continuity(std::string const& s = "", ParseErrorHandlers const* correction = nullptr);
5252
Continuity(std::vector<std::unique_ptr<ContProcedure>>);
53-
Continuity(std::vector<uint8_t> const&);
53+
Continuity(Reader);
5454
~Continuity();
5555

5656
Continuity(Continuity const&);

0 commit comments

Comments
 (0)