diff --git a/ccvers.h.in b/ccvers.h.in index 24d7e5b4..27c75d07 100644 --- a/ccvers.h.in +++ b/ccvers.h.in @@ -28,3 +28,4 @@ #define CC_VERSION \ MK_CC_VERSION(CC_MAJOR_VERSION, CC_MINOR_VERSION, CC_PATCH_VERSION) +static constexpr uint32_t kVersion = (CC_MAJOR_VERSION << 8) | CC_MINOR_VERSION; diff --git a/src/CalChartFrame.cpp b/src/CalChartFrame.cpp index 2c49dee0..c203bcf9 100644 --- a/src/CalChartFrame.cpp +++ b/src/CalChartFrame.cpp @@ -625,22 +625,15 @@ void CalChartFrame::OnCmdPasteSheet(wxCommandEvent&) if (numPoints != GetShow()->GetNumPoints()) { wxMessageBox(wxString::Format("Cannot paste - number of points in pasted sheet (%i) does not match number of points in current show (%i)", numPoints, GetShow()->GetNumPoints())); + wxTheClipboard->Close(); return; } - std::stringstream sheetStream; - sheetStream.write((char*)(clipboardObject.GetData()) + sizeof(numPoints), - clipboardObject.GetDataSize() - sizeof(numPoints)); + auto reader = CalChart::Reader({ (uint8_t const*)(clipboardObject.GetData()) + sizeof(numPoints), + clipboardObject.GetDataSize() - sizeof(numPoints) }); + reader.Get(); + reader.Get(); - CalChart::ReadLong(sheetStream); - CalChart::ReadLong(sheetStream); - - sheetStream.unsetf(std::ios_base::skipws); - std::istream_iterator theBegin(sheetStream); - std::istream_iterator theEnd{}; - std::vector data(theBegin, theEnd); - - CalChart::Show::Sheet_container_t sht( - 1, CalChart::Sheet(numPoints, data.data(), data.size())); + CalChart::Show::Sheet_container_t sht(1, CalChart::Sheet(numPoints, reader)); GetFieldView()->DoInsertSheets(sht, GetFieldView()->GetCurrentSheetNum()); } wxTheClipboard->Close(); diff --git a/src/core/CalChartContinuity.cpp b/src/core/CalChartContinuity.cpp index aa91e8ff..00628915 100644 --- a/src/core/CalChartContinuity.cpp +++ b/src/core/CalChartContinuity.cpp @@ -62,18 +62,16 @@ std::vector> ParseContinuity(std::string const& s } } -std::vector> Deserialize(std::vector const& data) +std::vector> Deserialize(Reader reader) { auto result = std::vector>{}; - auto begin = data.data(); - auto end = data.data() + data.size(); - while (std::distance(begin, end) > 0) { - auto next_result = std::unique_ptr{}; - std::tie(next_result, begin) = DeserializeContProcedure(begin, end); + while (reader.size() > 0) { + auto [ next_result, new_reader ] = DeserializeContProcedure(reader); result.push_back(std::move(next_result)); + reader = new_reader; } - if (begin != end) { + if (reader.size() != 0) { throw std::runtime_error("Error, did not parse all the data correctly"); } return result; @@ -99,8 +97,8 @@ Continuity::Continuity(std::vector> from_cont) { } -Continuity::Continuity(std::vector const& data) - : m_parsedContinuity(Deserialize(data)) +Continuity::Continuity(Reader reader) + : m_parsedContinuity(Deserialize(reader)) { } @@ -175,7 +173,8 @@ void Continuity_serialize_test() }) { auto uut1 = Continuity{ i }; auto serialize_result = uut1.Serialize(); - auto uut2 = Continuity{ serialize_result }; + auto reader = Reader({ serialize_result.data(), serialize_result.size()}); + auto uut2 = Continuity{ reader }; assert(uut1 == uut2); } } diff --git a/src/core/CalChartContinuity.h b/src/core/CalChartContinuity.h index 1a2ad7c0..0c3be157 100644 --- a/src/core/CalChartContinuity.h +++ b/src/core/CalChartContinuity.h @@ -50,7 +50,7 @@ class Continuity { // this could throw runtime_error on bad parses. Continuity(std::string const& s = "", ParseErrorHandlers const* correction = nullptr); Continuity(std::vector>); - Continuity(std::vector const&); + Continuity(Reader); ~Continuity(); Continuity(Continuity const&); diff --git a/src/core/CalChartContinuityToken.cpp b/src/core/CalChartContinuityToken.cpp index 4010e3e7..fc6aabe1 100644 --- a/src/core/CalChartContinuityToken.cpp +++ b/src/core/CalChartContinuityToken.cpp @@ -292,13 +292,14 @@ void DoCounterMarch(const ContProcedure& proc, AnimationCompile& anim, } } -std::tuple, uint8_t const*> DeserializeContProcedure(uint8_t const* begin, uint8_t const* end) +std::tuple, Reader> DeserializeContProcedure(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPoint is not correct"); } auto v = std::unique_ptr(); - switch (static_cast(*begin)) { + auto token = static_cast(reader.Peek()); + switch (token) { case SerializationToken::ContProcUnset: v = std::make_unique(); break; @@ -362,17 +363,18 @@ std::tuple, uint8_t const*> DeserializeContProced default: throw std::runtime_error("Error, did not find ContPoint"); } - auto b = v->Deserialize(begin, end); + auto b = v->Deserialize(reader); return { std::move(v), b }; } -static std::tuple, uint8_t const*> DeserializeContPoint(uint8_t const* begin, uint8_t const* end) +static std::tuple, Reader> DeserializeContPoint(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPoint is not correct"); } auto v = std::unique_ptr(); - switch (static_cast(*begin)) { + auto token = static_cast(reader.Peek()); + switch (token) { case SerializationToken::ContPoint: v = std::make_unique(); break; @@ -391,17 +393,18 @@ static std::tuple, uint8_t const*> DeserializeContPoi default: throw std::runtime_error("Error, did not find ContPoint"); } - auto b = v->Deserialize(begin, end); - return { std::move(v), b }; + auto new_reader = v->Deserialize(reader); + return { std::move(v), new_reader }; } -static std::tuple, uint8_t const*> DeserializeContValue(uint8_t const* begin, uint8_t const* end) +static std::tuple, Reader> DeserializeContValue(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPoint is not correct"); } auto v = std::unique_ptr(); - switch (static_cast(*begin)) { + auto token = static_cast(reader.Peek()); + switch (token) { case SerializationToken::ContValueUnset: v = std::make_unique(); break; @@ -456,17 +459,18 @@ static std::tuple, uint8_t const*> DeserializeContVal default: throw std::runtime_error("Error, did not find ContValue"); } - auto b = v->Deserialize(begin, end); + auto b = v->Deserialize(reader); return { std::move(v), b }; } -static std::tuple, uint8_t const*> DeserializeContValueVar(uint8_t const* begin, uint8_t const* end) +static std::tuple, Reader> DeserializeContValueVar(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPoint is not correct"); } auto v = std::unique_ptr(); - switch (static_cast(*begin)) { + auto token = static_cast(reader.Peek()); + switch (token) { case SerializationToken::ContValueVar: v = std::make_unique(); break; @@ -476,7 +480,7 @@ static std::tuple, uint8_t const*> DeserializeCont default: throw std::runtime_error("Error, did not find ContValueVar"); } - auto b = v->Deserialize(begin, end); + auto b = v->Deserialize(reader); return { std::move(v), b }; } @@ -507,20 +511,18 @@ std::vector ContToken::Serialize() const return result; } -uint8_t const* ContToken::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContToken::Deserialize(Reader reader) { - if (std::distance(begin, end) < 9) { + if (reader.size() < 9) { throw std::runtime_error("Error, size of ContToken is not correct"); } - if (static_cast(*begin) != SerializationToken::ContToken) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContToken) { throw std::runtime_error("Error, token is not SerializationToken::ContToken"); } - ++begin; - line = Parser::get_big_long(begin); - begin += 4; - col = Parser::get_big_long(begin); - begin += 4; - return begin; + line = reader.Get(); + col = reader.Get(); + return reader; } // ContPoint @@ -560,17 +562,16 @@ std::vector ContPoint::Serialize() const return result; } -uint8_t const* ContPoint::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContPoint::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPoint is not correct"); } - if (static_cast(*begin) != SerializationToken::ContPoint) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContPoint) { throw std::runtime_error("Error, token is not SerializationToken::ContPoint"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContPointUnset @@ -605,17 +606,16 @@ std::vector ContPointUnset::Serialize() const return result; } -uint8_t const* ContPointUnset::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContPointUnset::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContPointUnset is not correct"); } - if (static_cast(*begin) != SerializationToken::ContPointUnset) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContPointUnset) { throw std::runtime_error("Error, token is not SerializationToken::ContPointUnset"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContStartPoint @@ -655,17 +655,16 @@ std::vector ContStartPoint::Serialize() const return result; } -uint8_t const* ContStartPoint::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContStartPoint::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContStartPoint is not correct"); } - if (static_cast(*begin) != SerializationToken::ContStartPoint) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContStartPoint) { throw std::runtime_error("Error, token is not SerializationToken::ContStartPoint"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContNextPoint @@ -705,17 +704,16 @@ std::vector ContNextPoint::Serialize() const return result; } -uint8_t const* ContNextPoint::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContNextPoint::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContNextPoint is not correct"); } - if (static_cast(*begin) != SerializationToken::ContNextPoint) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContNextPoint) { throw std::runtime_error("Error, token is not SerializationToken::ContNextPoint"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContRefPoint @@ -761,19 +759,18 @@ std::vector ContRefPoint::Serialize() const return result; } -uint8_t const* ContRefPoint::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContRefPoint::Deserialize(Reader reader) { - if (std::distance(begin, end) < 5) { + if (reader.size() < 5) { throw std::runtime_error("Error, size of ContRefPoint is not correct"); } - if (static_cast(*begin) != SerializationToken::ContRefPoint) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContRefPoint) { throw std::runtime_error("Error, token is not SerializationToken::ContRefPoint"); } - ++begin; - begin = super::Deserialize(begin, end); - refnum = Parser::get_big_long(begin); - begin += 4; - return begin; + reader = super::Deserialize(reader); + refnum = reader.Get(); + return reader; } // ContValue @@ -792,17 +789,16 @@ std::vector ContValue::Serialize() const return result; } -uint8_t const* ContValue::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValue::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValue is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValue) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValue) { throw std::runtime_error("Error, token is not SerializationToken::ContValue"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContValueUnset @@ -838,17 +834,16 @@ std::vector ContValueUnset::Serialize() const return result; } -uint8_t const* ContValueUnset::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueUnset::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueUnset is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueUnset) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueUnset) { throw std::runtime_error("Error, token is not SerializationToken::ContValueUnset"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContValueFloat @@ -889,19 +884,18 @@ std::vector ContValueFloat::Serialize() const return result; } -uint8_t const* ContValueFloat::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueFloat::Deserialize(Reader reader) { - if (std::distance(begin, end) < 5) { + if (reader.size() < 5) { throw std::runtime_error("Error, size of ContValueFloat is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueFloat) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueFloat) { throw std::runtime_error("Error, token is not SerializationToken::ContValueFloat"); } - ++begin; - begin = super::Deserialize(begin, end); - val = Parser::get_big_float(begin); - begin += 4; - return begin; + reader = super::Deserialize(reader); + val = reader.Get(); + return reader; } // ContValueDefined @@ -977,19 +971,18 @@ std::vector ContValueDefined::Serialize() const return result; } -uint8_t const* ContValueDefined::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueDefined::Deserialize(Reader reader) { - if (std::distance(begin, end) < 2) { + if (reader.size() < 2) { throw std::runtime_error("Error, size of ContValueDefined is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueDefined) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueDefined) { throw std::runtime_error("Error, token is not SerializationToken::ContValueDefined"); } - ++begin; - begin = super::Deserialize(begin, end); - val = static_cast(*begin); - ++begin; - return begin; + reader = super::Deserialize(reader); + val = static_cast(reader.Get()); + return reader; } // ContValueAdd @@ -1050,19 +1043,19 @@ std::vector ContValueAdd::Serialize() const return result; } -uint8_t const* ContValueAdd::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueAdd::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueAdd is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueAdd) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueAdd) { throw std::runtime_error("Error, token is not SerializationToken::ContValueAdd"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(val1, begin) = DeserializeContValue(begin, end); - std::tie(val2, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(val1, reader) = DeserializeContValue(reader); + std::tie(val2, reader) = DeserializeContValue(reader); + return reader; } // ContValueSub @@ -1123,19 +1116,19 @@ std::vector ContValueSub::Serialize() const return result; } -uint8_t const* ContValueSub::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueSub::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueSub is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueSub) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueSub) { throw std::runtime_error("Error, token is not SerializationToken::ContValueSub"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(val1, begin) = DeserializeContValue(begin, end); - std::tie(val2, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(val1, reader) = DeserializeContValue(reader); + std::tie(val2, reader) = DeserializeContValue(reader); + return reader; } // ContValueMult @@ -1196,19 +1189,19 @@ std::vector ContValueMult::Serialize() const return result; } -uint8_t const* ContValueMult::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueMult::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueMult is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueMult) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueMult) { throw std::runtime_error("Error, token is not SerializationToken::ContValueMult"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(val1, begin) = DeserializeContValue(begin, end); - std::tie(val2, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(val1, reader) = DeserializeContValue(reader); + std::tie(val2, reader) = DeserializeContValue(reader); + return reader; } // ContValueDiv @@ -1275,19 +1268,19 @@ std::vector ContValueDiv::Serialize() const return result; } -uint8_t const* ContValueDiv::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueDiv::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueDiv is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueDiv) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueDiv) { throw std::runtime_error("Error, token is not SerializationToken::ContValueDiv"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(val1, begin) = DeserializeContValue(begin, end); - std::tie(val2, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(val1, reader) = DeserializeContValue(reader); + std::tie(val2, reader) = DeserializeContValue(reader); + return reader; } // ContValueNeg @@ -1342,18 +1335,18 @@ std::vector ContValueNeg::Serialize() const return result; } -uint8_t const* ContValueNeg::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueNeg::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueNeg is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueNeg) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueNeg) { throw std::runtime_error("Error, token is not SerializationToken::ContValueNeg"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(val, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(val, reader) = DeserializeContValue(reader); + return reader; } // ContValueREM @@ -1393,17 +1386,16 @@ std::vector ContValueREM::Serialize() const return result; } -uint8_t const* ContValueREM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueREM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueREM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueREM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueREM) { throw std::runtime_error("Error, token is not SerializationToken::ContValueREM"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContValueVar @@ -1454,19 +1446,18 @@ std::vector ContValueVar::Serialize() const return result; } -uint8_t const* ContValueVar::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueVar::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueVar is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueVar) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueVar) { throw std::runtime_error("Error, token is not SerializationToken::ContValueVar"); } - ++begin; - begin = super::Deserialize(begin, end); - varnum = static_cast(*begin); - ++begin; - return begin; + reader = super::Deserialize(reader); + varnum = reader.Get(); + return reader; } // ContValueVarUnset @@ -1501,17 +1492,16 @@ std::vector ContValueVarUnset::Serialize() const return result; } -uint8_t const* ContValueVarUnset::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContValueVarUnset::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContValueVarUnset is not correct"); } - if (static_cast(*begin) != SerializationToken::ContValueVarUnset) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContValueVarUnset) { throw std::runtime_error("Error, token is not SerializationToken::ContValueVarUnset"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContFuncDir @@ -1573,18 +1563,18 @@ std::vector ContFuncDir::Serialize() const return result; } -uint8_t const* ContFuncDir::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncDir::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncDir is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncDir) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncDir) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncDir"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContFuncDirFrom @@ -1650,19 +1640,19 @@ std::vector ContFuncDirFrom::Serialize() const return result; } -uint8_t const* ContFuncDirFrom::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncDirFrom::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncDirFrom is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncDirFrom) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncDirFrom) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncDirFrom"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt_start, begin) = DeserializeContPoint(begin, end); - std::tie(pnt_end, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt_start, reader) = DeserializeContPoint(reader); + std::tie(pnt_end, reader) = DeserializeContPoint(reader); + return reader; } // ContFuncDist @@ -1721,18 +1711,18 @@ std::vector ContFuncDist::Serialize() const return result; } -uint8_t const* ContFuncDist::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncDist::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncDist is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncDist) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncDist) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncDist"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContFuncDistFrom @@ -1794,19 +1784,19 @@ std::vector ContFuncDistFrom::Serialize() const return result; } -uint8_t const* ContFuncDistFrom::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncDistFrom::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncDistFrom is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncDistFrom) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncDistFrom) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncDistFrom"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt_start, begin) = DeserializeContPoint(begin, end); - std::tie(pnt_end, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt_start, reader) = DeserializeContPoint(reader); + std::tie(pnt_end, reader) = DeserializeContPoint(reader); + return reader; } // ContFuncEither @@ -1887,20 +1877,20 @@ std::vector ContFuncEither::Serialize() const return result; } -uint8_t const* ContFuncEither::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncEither::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncEither is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncEither) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncEither) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncEither"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(dir1, begin) = DeserializeContValue(begin, end); - std::tie(dir2, begin) = DeserializeContValue(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(dir1, reader) = DeserializeContValue(reader); + std::tie(dir2, reader) = DeserializeContValue(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContFuncOpp @@ -1958,18 +1948,18 @@ std::vector ContFuncOpp::Serialize() const return result; } -uint8_t const* ContFuncOpp::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncOpp::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncOpp is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncOpp) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncOpp) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncOpp"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(dir, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(dir, reader) = DeserializeContValue(reader); + return reader; } // ContFuncStep @@ -2035,20 +2025,20 @@ std::vector ContFuncStep::Serialize() const return result; } -uint8_t const* ContFuncStep::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContFuncStep::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContFuncStep is not correct"); } - if (static_cast(*begin) != SerializationToken::ContFuncStep) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContFuncStep) { throw std::runtime_error("Error, token is not SerializationToken::ContFuncStep"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(numbeats, begin) = DeserializeContValue(begin, end); - std::tie(blksize, begin) = DeserializeContValue(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(numbeats, reader) = DeserializeContValue(reader); + std::tie(blksize, reader) = DeserializeContValue(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcedure @@ -2067,17 +2057,16 @@ std::vector ContProcedure::Serialize() const return result; } -uint8_t const* ContProcedure::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcedure::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcedure is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcedure) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcedure) { throw std::runtime_error("Error, token is not SerializationToken::ContProcedure"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContProcUnset @@ -2113,17 +2102,16 @@ std::vector ContProcUnset::Serialize() const return result; } -uint8_t const* ContProcUnset::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcUnset::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcUnset is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcUnset) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcUnset) { throw std::runtime_error("Error, token is not SerializationToken::ContProcUnset"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContProcSet @@ -2210,19 +2198,19 @@ std::vector ContProcSet::Serialize() const return result; } -uint8_t const* ContProcSet::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcSet::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcSet is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcSet) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcSet) { throw std::runtime_error("Error, token is not SerializationToken::ContProcSet"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(var, begin) = DeserializeContValueVar(begin, end); - std::tie(val, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(var, reader) = DeserializeContValueVar(reader); + std::tie(val, reader) = DeserializeContValue(reader); + return reader; } // ContProcBlam @@ -2265,17 +2253,16 @@ std::vector ContProcBlam::Serialize() const return result; } -uint8_t const* ContProcBlam::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcBlam::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcBlam is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcBlam) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcBlam) { throw std::runtime_error("Error, token is not SerializationToken::ContProcBlam"); } - ++begin; - begin = super::Deserialize(begin, end); - return begin; + return super::Deserialize(reader); } // ContProcCM @@ -2352,23 +2339,23 @@ std::vector ContProcCM::Serialize() const return result; } -uint8_t const* ContProcCM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcCM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcCM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcCM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcCM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcCM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt1, begin) = DeserializeContPoint(begin, end); - std::tie(pnt2, begin) = DeserializeContPoint(begin, end); - std::tie(stps, begin) = DeserializeContValue(begin, end); - std::tie(dir1, begin) = DeserializeContValue(begin, end); - std::tie(dir2, begin) = DeserializeContValue(begin, end); - std::tie(numbeats, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt1, reader) = DeserializeContPoint(reader); + std::tie(pnt2, reader) = DeserializeContPoint(reader); + std::tie(stps, reader) = DeserializeContValue(reader); + std::tie(dir1, reader) = DeserializeContValue(reader); + std::tie(dir2, reader) = DeserializeContValue(reader); + std::tie(numbeats, reader) = DeserializeContValue(reader); + return reader; } // ContProcDMCM @@ -2467,20 +2454,20 @@ std::vector ContProcDMCM::Serialize() const return result; } -uint8_t const* ContProcDMCM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcDMCM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcDMCM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcDMCM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcDMCM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcDMCM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt1, begin) = DeserializeContPoint(begin, end); - std::tie(pnt2, begin) = DeserializeContPoint(begin, end); - std::tie(numbeats, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt1, reader) = DeserializeContPoint(reader); + std::tie(pnt2, reader) = DeserializeContPoint(reader); + std::tie(numbeats, reader) = DeserializeContValue(reader); + return reader; } // ContProcDMHS @@ -2569,18 +2556,18 @@ std::vector ContProcDMHS::Serialize() const return result; } -uint8_t const* ContProcDMHS::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcDMHS::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcDMHS is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcDMHS) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcDMHS) { throw std::runtime_error("Error, token is not SerializationToken::ContProcDMHS"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcEven @@ -2649,19 +2636,19 @@ std::vector ContProcEven::Serialize() const return result; } -uint8_t const* ContProcEven::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcEven::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcEven is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcEven) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcEven) { throw std::runtime_error("Error, token is not SerializationToken::ContProcEven"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(stps, begin) = DeserializeContValue(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(stps, reader) = DeserializeContValue(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcEWNS @@ -2735,18 +2722,18 @@ std::vector ContProcEWNS::Serialize() const return result; } -uint8_t const* ContProcEWNS::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcEWNS::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcEWNS is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcEWNS) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcEWNS) { throw std::runtime_error("Error, token is not SerializationToken::ContProcEWNS"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcFountain @@ -2916,28 +2903,28 @@ std::vector ContProcFountain::Serialize() const return result; } -uint8_t const* ContProcFountain::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcFountain::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcFountain is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcFountain) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcFountain) { throw std::runtime_error("Error, token is not SerializationToken::ContProcFountain"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(dir1, begin) = DeserializeContValue(begin, end); - std::tie(dir2, begin) = DeserializeContValue(begin, end); - bool parsestepsize1 = static_cast(*begin++); + reader = super::Deserialize(reader); + std::tie(dir1, reader) = DeserializeContValue(reader); + std::tie(dir2, reader) = DeserializeContValue(reader); + bool parsestepsize1 = reader.Get(); if (parsestepsize1) { - std::tie(stepsize1, begin) = DeserializeContValue(begin, end); + std::tie(stepsize1, reader) = DeserializeContValue(reader); } - bool parsestepsize2 = static_cast(*begin++); + bool parsestepsize2 = reader.Get(); if (parsestepsize2) { - std::tie(stepsize2, begin) = DeserializeContValue(begin, end); + std::tie(stepsize2, reader) = DeserializeContValue(reader); } - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcFM @@ -3010,19 +2997,19 @@ std::vector ContProcFM::Serialize() const return result; } -uint8_t const* ContProcFM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcFM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcFM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcFM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcFM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcFM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(stps, begin) = DeserializeContValue(begin, end); - std::tie(dir, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(stps, reader) = DeserializeContValue(reader); + std::tie(dir, reader) = DeserializeContValue(reader); + return reader; } // ContProcFMTO @@ -3098,18 +3085,18 @@ std::vector ContProcFMTO::Serialize() const return result; } -uint8_t const* ContProcFMTO::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcFMTO::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcFMTO is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcFMTO) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcFMTO) { throw std::runtime_error("Error, token is not SerializationToken::ContProcFMTO"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcGrid @@ -3177,18 +3164,18 @@ std::vector ContProcGrid::Serialize() const return result; } -uint8_t const* ContProcGrid::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcGrid::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcGrid is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcGrid) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcGrid) { throw std::runtime_error("Error, token is not SerializationToken::ContProcGrid"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(grid, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(grid, reader) = DeserializeContValue(reader); + return reader; } // ContProcHSCM @@ -3272,20 +3259,20 @@ std::vector ContProcHSCM::Serialize() const return result; } -uint8_t const* ContProcHSCM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcHSCM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcHSCM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcHSCM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcHSCM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcHSCM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt1, begin) = DeserializeContPoint(begin, end); - std::tie(pnt2, begin) = DeserializeContPoint(begin, end); - std::tie(numbeats, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt1, reader) = DeserializeContPoint(reader); + std::tie(pnt2, reader) = DeserializeContPoint(reader); + std::tie(numbeats, reader) = DeserializeContValue(reader); + return reader; } // ContProcHSDM @@ -3373,18 +3360,18 @@ std::vector ContProcHSDM::Serialize() const return result; } -uint8_t const* ContProcHSDM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcHSDM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcHSDM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcHSDM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcHSDM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcHSDM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcMagic @@ -3443,18 +3430,18 @@ std::vector ContProcMagic::Serialize() const return result; } -uint8_t const* ContProcMagic::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcMagic::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcMagic is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcMagic) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcMagic) { throw std::runtime_error("Error, token is not SerializationToken::ContProcMagic"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcMarch @@ -3558,24 +3545,24 @@ std::vector ContProcMarch::Serialize() const return result; } -uint8_t const* ContProcMarch::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcMarch::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcMarch is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcMarch) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcMarch) { throw std::runtime_error("Error, token is not SerializationToken::ContProcMarch"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(stpsize, begin) = DeserializeContValue(begin, end); - std::tie(stps, begin) = DeserializeContValue(begin, end); - std::tie(dir, begin) = DeserializeContValue(begin, end); - bool parsefacedir = static_cast(*begin++); + reader = super::Deserialize(reader); + std::tie(stpsize, reader) = DeserializeContValue(reader); + std::tie(stps, reader) = DeserializeContValue(reader); + std::tie(dir, reader) = DeserializeContValue(reader); + bool parsefacedir = reader.Get(); if (parsefacedir) { - std::tie(facedir, begin) = DeserializeContValue(begin, end); + std::tie(facedir, reader) = DeserializeContValue(reader); } - return begin; + return reader; } // ContProcMT @@ -3641,19 +3628,19 @@ std::vector ContProcMT::Serialize() const return result; } -uint8_t const* ContProcMT::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcMT::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcMT is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcMT) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcMT) { throw std::runtime_error("Error, token is not SerializationToken::ContProcMT"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(numbeats, begin) = DeserializeContValue(begin, end); - std::tie(dir, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(numbeats, reader) = DeserializeContValue(reader); + std::tie(dir, reader) = DeserializeContValue(reader); + return reader; } // ContProcMTRM @@ -3713,18 +3700,18 @@ std::vector ContProcMTRM::Serialize() const return result; } -uint8_t const* ContProcMTRM::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcMTRM::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcMTRM is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcMTRM) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcMTRM) { throw std::runtime_error("Error, token is not SerializationToken::ContProcMTRM"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(dir, begin) = DeserializeContValue(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(dir, reader) = DeserializeContValue(reader); + return reader; } // ContProcNSEW @@ -3798,18 +3785,18 @@ std::vector ContProcNSEW::Serialize() const return result; } -uint8_t const* ContProcNSEW::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcNSEW::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcNSEW is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcNSEW) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcNSEW) { throw std::runtime_error("Error, token is not SerializationToken::ContProcNSEW"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } // ContProcRotate @@ -3894,20 +3881,20 @@ std::vector ContProcRotate::Serialize() const return result; } -uint8_t const* ContProcRotate::Deserialize(uint8_t const* begin, uint8_t const* end) +Reader ContProcRotate::Deserialize(Reader reader) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, size of ContProcRotate is not correct"); } - if (static_cast(*begin) != SerializationToken::ContProcRotate) { + auto token = static_cast(reader.Get()); + if (token != SerializationToken::ContProcRotate) { throw std::runtime_error("Error, token is not SerializationToken::ContProcRotate"); } - ++begin; - begin = super::Deserialize(begin, end); - std::tie(ang, begin) = DeserializeContValue(begin, end); - std::tie(stps, begin) = DeserializeContValue(begin, end); - std::tie(pnt, begin) = DeserializeContPoint(begin, end); - return begin; + reader = super::Deserialize(reader); + std::tie(ang, reader) = DeserializeContValue(reader); + std::tie(stps, reader) = DeserializeContValue(reader); + std::tie(pnt, reader) = DeserializeContPoint(reader); + return reader; } } diff --git a/src/core/CalChartContinuityToken.h b/src/core/CalChartContinuityToken.h index e425df32..47e56fe6 100644 --- a/src/core/CalChartContinuityToken.h +++ b/src/core/CalChartContinuityToken.h @@ -114,6 +114,7 @@ enum class ContType { }; class ContToken; +class Reader; struct AnimationCompile; // DrawableCont is a structure that describes the continuity for drawing @@ -135,7 +136,7 @@ class ContToken { virtual void replace(ContToken const* which, std::unique_ptr v); virtual std::vector Serialize() const; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end); + virtual Reader Deserialize(Reader); uint32_t line, col; @@ -170,7 +171,7 @@ class ContPoint : public ContToken { virtual std::unique_ptr clone() const; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: // we use the assumption that we've already checked that the types match before calling. @@ -189,7 +190,7 @@ class ContPointUnset : public ContPoint { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContStartPoint : public ContPoint { @@ -203,7 +204,7 @@ class ContStartPoint : public ContPoint { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: // we use the assumption that we've already checked that the types match before calling. @@ -224,7 +225,7 @@ class ContNextPoint : public ContPoint { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: // we use the assumption that we've already checked that the types match before calling. @@ -246,7 +247,7 @@ class ContRefPoint : public ContPoint { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -269,7 +270,7 @@ class ContValue : public ContToken { virtual std::unique_ptr clone() const = 0; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContValueUnset : public ContValue { @@ -282,7 +283,7 @@ class ContValueUnset : public ContValue { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContValueFloat : public ContValue { @@ -297,7 +298,7 @@ class ContValueFloat : public ContValue { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -321,7 +322,7 @@ class ContValueDefined : public ContValue { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -347,7 +348,7 @@ class ContValueAdd : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -375,7 +376,7 @@ class ContValueSub : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -403,7 +404,7 @@ class ContValueMult : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -431,7 +432,7 @@ class ContValueDiv : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -459,7 +460,7 @@ class ContValueNeg : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -482,7 +483,7 @@ class ContValueREM : public ContValue { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: // we use the assumption that we've already checked that the types match before calling. @@ -505,7 +506,7 @@ class ContValueVar : public ContValue { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -527,7 +528,7 @@ class ContValueVarUnset : public ContValueVar { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContFuncDir : public ContValue { @@ -544,7 +545,7 @@ class ContFuncDir : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -571,7 +572,7 @@ class ContFuncDirFrom : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -599,7 +600,7 @@ class ContFuncDist : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -626,7 +627,7 @@ class ContFuncDistFrom : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -654,7 +655,7 @@ class ContFuncEither : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -683,7 +684,7 @@ class ContFuncOpp : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -710,7 +711,7 @@ class ContFuncStep : public ContValue { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -737,7 +738,7 @@ class ContProcedure : public ContToken { virtual bool IsValid() const { return true; } virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContProcUnset : public ContProcedure { @@ -751,7 +752,7 @@ class ContProcUnset : public ContProcedure { virtual bool IsValid() const override { return false; } virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; }; class ContProcSet : public ContProcedure { @@ -770,7 +771,7 @@ class ContProcSet : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -795,7 +796,7 @@ class ContProcBlam : public ContProcedure { virtual std::unique_ptr clone() const override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: // we use the assumption that we've already checked that the types match before calling. @@ -821,7 +822,7 @@ class ContProcCM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -850,7 +851,7 @@ class ContProcDMCM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -879,7 +880,7 @@ class ContProcDMHS : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -907,7 +908,7 @@ class ContProcEven : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -936,7 +937,7 @@ class ContProcEWNS : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -966,7 +967,7 @@ class ContProcFountain : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1010,7 +1011,7 @@ class ContProcFM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1038,7 +1039,7 @@ class ContProcFMTO : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1066,7 +1067,7 @@ class ContProcGrid : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1094,7 +1095,7 @@ class ContProcHSCM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1123,7 +1124,7 @@ class ContProcHSDM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1151,7 +1152,7 @@ class ContProcMagic : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1181,7 +1182,7 @@ class ContProcMarch : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1219,7 +1220,7 @@ class ContProcMT : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1247,7 +1248,7 @@ class ContProcMTRM : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1275,7 +1276,7 @@ class ContProcNSEW : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1303,7 +1304,7 @@ class ContProcRotate : public ContProcedure { virtual void replace(ContToken const* which, std::unique_ptr v) override; virtual std::vector Serialize() const override; - virtual uint8_t const* Deserialize(uint8_t const* begin, uint8_t const* end) override; + virtual Reader Deserialize(Reader) override; protected: virtual bool is_equal(ContToken const& other) const override @@ -1319,6 +1320,6 @@ class ContProcRotate : public ContProcedure { }; // this is the top level Deserialization function -std::tuple, uint8_t const*> DeserializeContProcedure(uint8_t const* begin, uint8_t const* end); +std::tuple, Reader> DeserializeContProcedure(Reader); } diff --git a/src/core/CalChartFileFormat.h b/src/core/CalChartFileFormat.h index f023190d..be13296f 100644 --- a/src/core/CalChartFileFormat.h +++ b/src/core/CalChartFileFormat.h @@ -27,6 +27,8 @@ #include #include +#include "ccvers.h" + namespace CalChart { struct Version_3_3_and_earlier { @@ -229,18 +231,6 @@ struct Current_version_and_later { #define INGL_PONT Make4CharWord('P', 'O', 'N', 'T') #define INGL_END Make4CharWord('E', 'N', 'D', ' ') -template -uint16_t get_big_word(const T* ptr) -{ - return ((ptr[0] & 0xFF) << 8) | ((ptr[1] & 0xFF)); -} - -template -uint32_t get_big_long(const T* ptr) -{ - return ((ptr[0] & 0xFF) << 24) | ((ptr[1] & 0xFF) << 16) | ((ptr[2] & 0xFF) << 8) | ((ptr[3] & 0xFF)); -} - inline void put_big_word(void* p, uint16_t v) { uint8_t* ptr = static_cast(p); @@ -280,230 +270,8 @@ class CC_FileException : public std::runtime_error { : std::runtime_error(reason + " : " + GetErrorFromID(nameID)){}; }; -template -inline uint8_t ReadByte(T& stream) -{ - char data; - stream.read(&data, sizeof(data)); - return data; -} - -template -inline uint32_t ReadLong(T& stream) -{ - char rawd[4]; - stream.read(rawd, sizeof(rawd)); - return get_big_long(rawd); -} - -// return false if you don't read the inname -template -inline void ReadAndCheckID(T& stream, uint32_t inname) -{ - uint32_t name = ReadLong(stream); - if (inname != name) { - throw CC_FileException(inname); - } -} - -// return false if you don't read the inname -template -inline uint32_t ReadGurkSymbolAndGetVersion(T& stream, uint32_t inname) -{ - uint32_t name = ReadLong(stream); - if (inname == name) { - // if we have an exact match, this is version 0 - return 0x0; - } - if ((((name >> 24) & 0xFF) == ((inname >> 24) & 0xFF)) && (((name >> 16) & 0xFF) == ((inname >> 16) & 0xFF))) { - char major_vers = (name >> 8) & 0xFF; - char minor_vers = (name)&0xFF; - if (isdigit(major_vers) && isdigit(minor_vers)) { - return ((major_vers - '0') << 8) | (minor_vers - '0'); - } - } - throw CC_FileException(inname); -} - -// return false if you don't read the inname -template -inline uint32_t ReadCheckIDandSize(T& stream, uint32_t inname) -{ - uint32_t name = ReadLong(stream); - if (inname != name) { - throw CC_FileException(inname); - } - name = ReadLong(stream); - if (4 != name) { - uint8_t rawd[4]; - put_big_long(rawd, inname); - std::stringstream buf; - buf << "Wrong size " << name << " for name " << rawd[0] << rawd[1] - << rawd[2] << rawd[3]; - throw CC_FileException(buf.str()); - } - return ReadLong(stream); -} - -// return false if you don't read the inname -template -inline std::vector ReadCheckIDandFillData(T& stream, uint32_t inname) -{ - uint32_t name = ReadLong(stream); - if (inname != name) { - throw CC_FileException(inname); - } - std::vector data(ReadLong(stream)); - stream.read(reinterpret_cast(&data[0]), data.size()); - return data; -} - -// Just fill the data -template -inline std::vector FillData(T& stream, size_t size) -{ - std::vector data(size); - stream.read(reinterpret_cast(&data[0]), data.size()); - return data; -} - -// Just fill the data -template -inline std::vector FillData(T& stream) -{ - uint32_t name = ReadLong(stream); - return FillData(stream, name); -} - -template -inline void Write(T& stream, const void* data, uint32_t size) -{ - stream.write(reinterpret_cast(data), size); -} - -template -inline void WriteLong(T& stream, uint32_t d) -{ - char rawd[4]; - put_big_long(rawd, d); - Write(stream, rawd, sizeof(rawd)); -} - -template -inline void WriteHeader(T& stream) -{ - WriteLong(stream, INGL_INGL); -} - -template -inline void WriteGurk(T& stream, uint32_t name) -{ - WriteLong(stream, INGL_GURK); - WriteLong(stream, name); -} - -template -inline void WriteGurkAndVersion(T& stream, uint8_t major, uint8_t minor) -{ - uint32_t gurk_version = ((INGL_GURK)&0xFFFF0000) | (('0' + major) << 8) | ('0' + minor); - - WriteLong(stream, gurk_version); -} - -template -inline void WriteChunkHeader(T& stream, uint32_t name, uint32_t size) -{ - WriteLong(stream, name); - WriteLong(stream, size); -} - -template -inline void WriteChunk(T& stream, uint32_t name, uint32_t size, - const void* data) -{ - WriteLong(stream, name); - WriteLong(stream, size); - if (size > 0) - Write(stream, data, size); -} - -template -inline void WriteChunkStr(T& stream, uint32_t name, const char* str) -{ - WriteChunk(stream, name, strlen(str) + 1, - reinterpret_cast(str)); -} - -template -inline void WriteEnd(T& stream, uint32_t name) -{ - WriteLong(stream, INGL_END); - WriteLong(stream, name); -} - -template -inline void WriteStr(T& stream, const char* str) -{ - Write(stream, str, strlen(str) + 1); -} - namespace Parser { - template - uint32_t get_big_long(Iter ptr) - { - uint32_t result = (*ptr++ & 0xFF); - result = (result << 8) | (*ptr++ & 0xFF); - result = (result << 8) | (*ptr++ & 0xFF); - result = (result << 8) | (*ptr++ & 0xFF); - return result; - } - - // oh ick, casting floating point to raw values... Sure hope things are ieee... - template - float get_big_float(Iter ptr) - { - unsigned char rawd[sizeof(float)]; - std::copy(ptr, ptr + sizeof(float), rawd); - ptr += sizeof(float); - float result = 0.f; - void* fptr = &result; - std::memcpy(fptr, rawd, sizeof(float)); - return result; - } - - template - std::vector> ParseOutLabels(Iter begin, - Iter end) - { - std::vector> result; - while (begin != end) { - auto length = std::distance(begin, end); - if (length < 8) { - return result; - } - auto name = get_big_long(begin); - begin += 4; - auto size = get_big_long(begin); - begin += 4; - length = std::distance(begin, end); - if (static_cast(length) < size + 8) { - return result; - } - auto data = begin; - begin += size; - auto end = get_big_long(begin); - begin += 4; - auto end_name = get_big_long(begin); - begin += 4; - if ((end != INGL_END) || (end_name != name)) { - return result; - } - result.push_back(std::tuple(name, data, size)); - } - return result; - } - struct PrintHeader { uint32_t d; }; @@ -593,4 +361,196 @@ namespace Parser { return result; } } + +class Reader +{ +public: + Reader(std::pair data, uint32_t version = kVersion) : data(data), version(version) {} + + auto size() const { return data.second; } + auto first(std::size_t n) const + { + if (size() < n) { + throw std::runtime_error(std::string("not enough data for first. Need ") + std::to_string(n) + ", currently have " + std::to_string(size())); + } + auto copy = *this; + copy.data.second = n; + return copy; + } + auto subspan(std::size_t n) const { auto copy = *this; copy.subspanImpl(n); return copy; } + + template + T Peek() const; + + template + T Get() + { + auto result = Peek(); + subspanImpl(sizeof(T)); + return result; + } + + template + std::vector GetVector(); + + std::vector> ParseOutLabels() + { + std::vector> result; + while (size()) { + auto length = size(); + if (length < 8) { + return result; + } + auto name = Get(); + auto size = Get(); + if (data.second < size + 8) { + return result; + } + auto reader = first(size); + subspanImpl(size); + auto end = Get(); + auto end_name = Get(); + if ((end != INGL_END) || (end_name != name)) { + return result; + } + result.push_back({name, reader}); + } + return result; + } + + void ReadAndCheckID(uint32_t inname) + { + uint32_t name = Get(); + if (inname != name) { + throw CC_FileException(inname); + } + } + + auto ReadCheckIDandSize(uint32_t inname) + { + ReadAndCheckID(inname); + auto size = Get(); + if (4 != size) { + throw CC_FileException(inname); + } + return Get(); + } + + // return false if you don't read the inname + auto ReadCheckIDandFillData(uint32_t inname) + { + ReadAndCheckID(inname); + return GetVector(); + } + + // return false if you don't read the inname + auto ReadGurkSymbolAndGetVersion(uint32_t inname) + { + auto name = Get(); + if (inname == name) { + // if we have an exact match, this is version 0 + return 0x0; + } + if ((((name >> 24) & 0xFF) == ((inname >> 24) & 0xFF)) && (((name >> 16) & 0xFF) == ((inname >> 16) & 0xFF))) { + char major_vers = (name >> 8) & 0xFF; + char minor_vers = (name)&0xFF; + if (isdigit(major_vers) && isdigit(minor_vers)) { + return ((major_vers - '0') << 8) | (minor_vers - '0'); + } + } + throw CC_FileException(inname); + } + +private: + + // privateSubspan + void subspanImpl(std::size_t n) + { + if (data.second < n) { + throw std::runtime_error(std::string("not enough data for subspan. Need ") + std::to_string(n) + ", currently have " + std::to_string(size())); + } + data.first += n; + data.second -= n; + } + + + std::pair data; + uint32_t version; +}; + +template <> +inline uint8_t Reader::Peek() const +{ + if (size() < 1) { + throw std::runtime_error(std::string("not enough data for uint8_t. Need 1, currently have ") + std::to_string(size())); + } + return (data.first[0] & 0xFF); +} + +template <> +inline uint16_t Reader::Peek() const +{ + if (size() < 2) { + throw std::runtime_error(std::string("not enough data for uint16_t. Need 2, currently have ") + std::to_string(size())); + } + return ((data.first[0] & 0xFF) << 8) | (data.first[1] & 0xFF); +} + +template <> +inline uint32_t Reader::Peek() const +{ + if (size() < 4) { + throw std::runtime_error(std::string("not enough data for uint32_t. Need 4, currently have ") + std::to_string(size())); + } + return ((data.first[0] & 0xFF) << 24) | ((data.first[1] & 0xFF) << 16) | ((data.first[2] & 0xFF) << 8) | ((data.first[3] & 0xFF)); +} + +template <> +inline int32_t Reader::Peek() const +{ + if (size() < 4) { + throw std::runtime_error(std::string("not enough data for int32_t. Need 4, currently have ") + std::to_string(size())); + } + return ((data.first[0] & 0xFF) << 24) | ((data.first[1] & 0xFF) << 16) | ((data.first[2] & 0xFF) << 8) | ((data.first[3] & 0xFF)); +} + +template <> +inline float Reader::Peek() const +{ + if (size() < sizeof(float)) { + throw std::runtime_error(std::string("not enough data for float. Need " + std::to_string(sizeof(float)) + ", currently have ") + std::to_string(size())); + } + unsigned char rawd[sizeof(float)]; + std::copy(data.first, data.first + sizeof(float), rawd); + float result = 0.f; + void* fptr = &result; + std::memcpy(fptr, rawd, sizeof(float)); + return result; +} + +template <> +inline std::string Reader::Get() +{ + auto result = std::string(reinterpret_cast(data.first)); + if (size() < (result.size() + 1)) { + throw std::runtime_error(std::string("not enough data for string. Need " + std::to_string(result.size() + 1) + ", currently have ") + std::to_string(size())); + } + subspanImpl(result.size()+1); // +1 for the null terminator + return result; +} + +template +inline std::vector Reader::GetVector() +{ + if (size() < 4) { + throw std::runtime_error(std::string("not enough data for vector size. Need 4, currently have ") + std::to_string(size())); + } + auto size = Get(); + auto result = std::vector(data.first, data.first+size); + subspanImpl(size); + return result; +} + + + } diff --git a/src/core/CalChartImage.cpp b/src/core/CalChartImage.cpp index 09877cea..cbf7a431 100644 --- a/src/core/CalChartImage.cpp +++ b/src/core/CalChartImage.cpp @@ -24,30 +24,19 @@ namespace CalChart { -std::pair CreateImageData(uint8_t const* d) +std::pair CreateImageData(Reader reader) { - auto left = static_cast(get_big_long(d)); - d += 4; - auto top = static_cast(get_big_long(d)); - d += 4; - auto scaled_width = static_cast(get_big_long(d)); - d += 4; - auto scaled_height = static_cast(get_big_long(d)); - d += 4; - auto image_width = static_cast(get_big_long(d)); - d += 4; - auto image_height = static_cast(get_big_long(d)); - d += 4; - auto data_size = get_big_long(d); - d += 4; - auto data = std::vector(d, d + data_size); - d += data_size; - auto alpha_size = get_big_long(d); - d += 4; - auto alpha = std::vector(d, d + alpha_size); + auto left = reader.Get(); + auto top = reader.Get(); + auto scaled_width = reader.Get(); + auto scaled_height = reader.Get(); + auto image_width = reader.Get(); + auto image_height = reader.Get(); + auto data = reader.GetVector(); + auto alpha = reader.GetVector(); scaled_width = (scaled_width == 0) ? image_width : scaled_width; scaled_height = (scaled_height == 0) ? image_height : scaled_height; - return { ImageData{ left, top, scaled_width, scaled_height, image_width, image_height, data, alpha }, d }; + return { ImageData{ left, top, scaled_width, scaled_height, image_width, image_height, data, alpha }, reader }; } std::vector Serialize(ImageData const& image) diff --git a/src/core/CalChartImage.h b/src/core/CalChartImage.h index 1d507c42..112a72fa 100644 --- a/src/core/CalChartImage.h +++ b/src/core/CalChartImage.h @@ -25,6 +25,8 @@ namespace CalChart { +class Reader; + struct ImageData { int left, top; int scaled_width, scaled_height; @@ -33,7 +35,7 @@ struct ImageData { std::vector alpha; }; -std::pair CreateImageData(uint8_t const* d); +std::pair CreateImageData(Reader); std::vector Serialize(ImageData const&); } diff --git a/src/core/CalChartPoint.cpp b/src/core/CalChartPoint.cpp index e54a74d4..3908dddc 100644 --- a/src/core/CalChartPoint.cpp +++ b/src/core/CalChartPoint.cpp @@ -48,36 +48,25 @@ Point::Point(Coord const& p) // reference point ) , BigEndianInt16( x ) , BigEndianInt16( y ) }* ; // POINT_SYMBOL_DATA = BigEndianInt8( which symbol type ) ; // POINT_LABEL_FLIP_DATA = BigEndianInt8( label flipped ) ; -Point::Point(std::vector const& serialized_data) +Point::Point(Reader reader) : mSym(SYMBOL_PLAIN) { - const uint8_t* d = &serialized_data[0]; - { - mPos.x = get_big_word(d); - d += 2; - mPos.y = get_big_word(d); - d += 2; - } + mPos.x = reader.Get(); + mPos.y = reader.Get(); // set all the reference points for (unsigned j = 0; j < Point::kNumRefPoints; j++) { mRef[j] = mPos; } - uint8_t num_ref = *d; - ++d; + auto num_ref = reader.Get(); for (auto i = 0; i < num_ref; ++i) { - uint8_t ref = *d; - ++d; - mRef[ref - 1].x = get_big_word(d); - d += 2; - mRef[ref - 1].y = get_big_word(d); - d += 2; + auto ref = reader.Get(); + mRef[ref - 1].x = reader.Get(); + mRef[ref - 1].y = reader.Get(); } - mSym = static_cast(*d); - ++d; - mFlags.set(kPointLabelFlipped, (*d) > 0); - ++d; - if (static_cast(std::distance(&serialized_data[0], d)) != serialized_data.size()) { + mSym = static_cast(reader.Get()); + mFlags.set(kPointLabelFlipped, (reader.Get()) > 0); + if (reader.size() != 0) { throw CC_FileException("bad POS chunk"); } } diff --git a/src/core/CalChartPoint.h b/src/core/CalChartPoint.h index 39b3dab9..316d7f62 100644 --- a/src/core/CalChartPoint.h +++ b/src/core/CalChartPoint.h @@ -41,13 +41,15 @@ namespace CalChart { +class Reader; + class Point { public: static constexpr auto kNumRefPoints = 3; Point(); Point(Coord const& pos); - Point(std::vector const& serialized_data); + Point(Reader); std::vector Serialize() const; auto GetFlip() const { return mFlags.test(kPointLabelFlipped); } diff --git a/src/core/CalChartSheet.cpp b/src/core/CalChartSheet.cpp index 8916217b..3dfb6bcb 100644 --- a/src/core/CalChartSheet.cpp +++ b/src/core/CalChartSheet.cpp @@ -146,63 +146,54 @@ CheckInconsistancy(SYMBOL_TYPE symbol, uint8_t cont_index, } // Constructor for shows 3.3 and ealier. -Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* correction) +// intentionally a reference to Reader. +Sheet::Sheet(Version_3_3_and_earlier, size_t numPoints, Reader& reader, ParseErrorHandlers const* correction) : mAnimationContinuity(MAX_NUM_SYMBOLS) , mPoints(numPoints) { // Read in sheet name // - std::vector data = ReadCheckIDandFillData(stream, INGL_NAME); + std::vector data = reader.ReadCheckIDandFillData(INGL_NAME); mName = (const char*)&data[0]; // read in the duration: // <4> - auto chunk = ReadCheckIDandSize(stream, INGL_DURA); + auto chunk = reader.ReadCheckIDandSize(INGL_DURA); mBeats = chunk; // Point positions // - data = ReadCheckIDandFillData(stream, INGL_POS); + data = reader.ReadCheckIDandFillData(INGL_POS); if (data.size() != size_t(mPoints.size() * 4)) { throw CC_FileException("bad POS chunk"); } { - uint8_t* d = &data[0]; + auto reader = CalChart::Reader({data.data(), data.size()}); for (unsigned i = 0; i < mPoints.size(); ++i) { - Coord c; - c.x = get_big_word(d); - d += 2; - c.y = get_big_word(d); - d += 2; + auto c = Coord(reader.Get(), reader.Get()); for (unsigned j = 0; j <= Point::kNumRefPoints; j++) { mPoints[i].SetPos(c, j); } } } - uint32_t name = ReadLong(stream); + uint32_t name = reader.Get(); // read all the reference points while (INGL_REFP == name) { - std::vector data = FillData(stream); - if (data.size() != mPoints.size() * 4 + 2) { + auto size = reader.Get(); + if (size != mPoints.size() * 4 + 2) { throw CC_FileException("Bad REFP chunk"); } - uint8_t* d = &data[0]; - unsigned ref = get_big_word(d); - d += 2; + auto ref = reader.Get(); for (unsigned i = 0; i < mPoints.size(); i++) { - Coord c; - c.x = get_big_word(d); - d += 2; - c.y = get_big_word(d); - d += 2; + auto c = Coord(reader.Get(), reader.Get()); mPoints[i].SetPos(c, ref); } - name = ReadLong(stream); + name = reader.Get(); } // Point symbols while (INGL_SYMB == name) { - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); if (data.size() != mPoints.size()) { throw CC_FileException("Bad SYMB chunk"); } @@ -210,7 +201,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c for (unsigned i = 0; i < mPoints.size(); i++) { SetSymbol(i, (SYMBOL_TYPE)(*(d++))); } - name = ReadLong(stream); + name = reader.Get(); } std::map continity_for_symbol; std::map symbol_for_continuity; @@ -218,7 +209,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c // Point continuity types while (INGL_TYPE == name) { has_type = true; - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); if (data.size() != mPoints.size()) { throw CC_FileException("Bad TYPE chunk"); } @@ -227,7 +218,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c CheckInconsistancy(GetSymbol(i), *(d++), continity_for_symbol, symbol_for_continuity, mName, i); } - name = ReadLong(stream); + name = reader.Get(); } // because older calchart files may omit the continuity index, need to check // if it isn't used @@ -240,7 +231,7 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c } // Point labels (left or right) while (INGL_LABL == name) { - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); if (data.size() != mPoints.size()) { throw CC_FileException("Bad SYMB chunk"); } @@ -250,11 +241,11 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c mPoints.at(i).Flip(); } } - name = ReadLong(stream); + name = reader.Get(); } // Continuity text while (INGL_CONT == name) { - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); if (data.size() < 3) // one byte num + two nils minimum { throw CC_FileException("Bad cont chunk"); @@ -293,130 +284,115 @@ Sheet::Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* c std::string textstr(text); mAnimationContinuity.at(symbol_index) = Continuity{ textstr, correction }; - name = ReadLong(stream); + name = reader.Get(); } } // -=-=-=-=-=- LEGACY CODE -=-=-=-=-=- -Sheet::Sheet(size_t numPoints, uint8_t const* ptr, size_t size, ParseErrorHandlers const* correction) +Sheet::Sheet(size_t numPoints, Reader reader, ParseErrorHandlers const* correction) : mAnimationContinuity(MAX_NUM_SYMBOLS) , mPoints(numPoints) { // construct the parser handlers - auto parse_INGL_NAME = [](Sheet* sheet, uint8_t const* ptr, size_t size) { - auto str = (char const*)ptr; - if (size != (strlen(str) + 1)) { + auto parse_INGL_NAME = [](Sheet* sheet, Reader reader) { + auto str = reader.Get(); + if (reader.size() != 0) { throw CC_FileException("Description the wrong size", INGL_NAME); } sheet->mName = str; }; - auto parse_INGL_DURA = [](Sheet* sheet, uint8_t const* ptr, size_t size) { - if (4 != size) { + auto parse_INGL_DURA = [](Sheet* sheet, Reader reader) { + if (reader.size() != 4) { throw CC_FileException("Incorrect size", INGL_DURA); } - sheet->mBeats = get_big_long(ptr); + sheet->mBeats = reader.Get(); }; - auto parse_INGL_PNTS = [](Sheet* sheet, uint8_t const* ptr, size_t size) { + auto parse_INGL_PNTS = [](Sheet* sheet, Reader reader) { for (auto i = 0u; i < sheet->mPoints.size(); ++i) { - auto this_size = *ptr; - if (this_size > size) { + auto this_size = reader.Get(); + if (this_size > reader.size()) { throw CC_FileException("Incorrect size", INGL_PNTS); } - sheet->mPoints[i] = Point({ ptr + 1, ptr + 1 + this_size }); - ptr += this_size + 1; - size -= this_size + 1; + sheet->mPoints[i] = Point(reader.first(this_size)); + reader = reader.subspan(this_size); } - if (size != 0) { + if (reader.size() != 0) { throw CC_FileException("Incorrect size", INGL_PNTS); } }; - auto parse_INGL_ECNT = [correction](Sheet* sheet, uint8_t const* ptr, size_t size) { - if (size < 2) // one byte num + 1 nil minimum + auto parse_INGL_ECNT = [correction](Sheet* sheet, Reader reader) { + if (reader.size() < 2) // one byte num + 1 nil minimum { throw CC_FileException("Bad cont chunk", INGL_ECNT); } - auto d = (char const*)ptr; - if (d[size - 1] != '\0') { - throw CC_FileException("Cont chunk not NULL terminated", INGL_ECNT); - } - auto text = d + 1; - size_t num = strlen(text); - if (size < num + 2) // check for room for text string - { - throw CC_FileException("Bad cont chunk", INGL_ECNT); - } - SYMBOL_TYPE symbol_index = static_cast(*d); + SYMBOL_TYPE symbol_index = static_cast(reader.Get()); if (symbol_index >= MAX_NUM_SYMBOLS) { throw CC_FileException("No viable symbol for name", INGL_ECNT); } - std::string textstr(text); - sheet->mAnimationContinuity.at(symbol_index) = Continuity{ textstr, correction }; + auto text = reader.Get(); + sheet->mAnimationContinuity.at(symbol_index) = Continuity{ text, correction }; }; - auto parse_INGL_CONT = [parse_INGL_ECNT](Sheet* sheet, uint8_t const* ptr, size_t size) { - const std::map> + auto parse_INGL_CONT = [parse_INGL_ECNT](Sheet* sheet, Reader reader) { + const std::map> parser = { { INGL_ECNT, parse_INGL_ECNT }, }; - auto table = Parser::ParseOutLabels(ptr, ptr + size); + auto table = reader.ParseOutLabels(); for (auto& i : table) { auto the_parser = parser.find(std::get<0>(i)); if (the_parser != parser.end()) { - the_parser->second(sheet, std::get<1>(i), std::get<2>(i)); + the_parser->second(sheet, std::get<1>(i)); } } }; - auto parse_INGL_EVCT = [](Sheet* sheet, uint8_t const* ptr, size_t size) { - auto begin = ptr; - auto end = ptr + size; - if (std::distance(begin, end) < 1) // one byte for symbol + auto parse_INGL_EVCT = [](Sheet* sheet, Reader reader) { + if (reader.size() < 1) // one byte for symbol { throw CC_FileException("Bad cont chunk", INGL_EVCT); } - SYMBOL_TYPE symbol_index = static_cast(*begin++); + SYMBOL_TYPE symbol_index = static_cast(reader.Get()); if (symbol_index >= MAX_NUM_SYMBOLS) { throw CC_FileException("No viable symbol for name", INGL_EVCT); } - sheet->mAnimationContinuity.at(symbol_index) = Continuity{ std::vector{ begin, end } }; + sheet->mAnimationContinuity.at(symbol_index) = Continuity{ reader }; }; - auto parse_INGL_VCNT = [parse_INGL_EVCT](Sheet* sheet, uint8_t const* ptr, size_t size) { - std::map> const + auto parse_INGL_VCNT = [parse_INGL_EVCT](Sheet* sheet, Reader reader) { + std::map> const parser = { { INGL_EVCT, parse_INGL_EVCT }, }; - auto table = Parser::ParseOutLabels(ptr, ptr + size); + auto table = reader.ParseOutLabels(); for (auto& i : table) { auto the_parser = parser.find(std::get<0>(i)); if (the_parser != parser.end()) { - the_parser->second(sheet, std::get<1>(i), std::get<2>(i)); + the_parser->second(sheet, std::get<1>(i)); } } }; - auto parse_INGL_PCNT = [](Sheet* sheet, uint8_t const* ptr, size_t size) { - auto print_name = (char const*)ptr; - auto print_cont = print_name + strlen(print_name) + 1; - if ((strlen(print_name) + 1 + strlen(print_cont) + 1) != size) { + auto parse_INGL_PCNT = [](Sheet* sheet, Reader reader) { + auto print_name = reader.Get(); + auto print_cont = reader.Get(); + if (reader.size() != 0) { throw CC_FileException("Bad Print cont chunk", INGL_PCNT); } sheet->mPrintableContinuity = PrintContinuity(print_name, print_cont); }; - auto parse_INGL_BACK = [](Sheet* sheet, uint8_t const* ptr, size_t size) { - auto end_ptr = ptr + size; - auto num = get_big_long(ptr); - ptr += 4; + auto parse_INGL_BACK = [](Sheet* sheet, Reader reader) { + auto num = reader.Get(); while (num--) { - auto [ image, new_ptr ] = CreateImageData(ptr); + auto [ image, new_reader ] = CreateImageData(reader); sheet->mBackgroundImages.push_back(image); - ptr = new_ptr; + reader = new_reader; } - if (ptr != end_ptr) { + if (reader.size() != 0) { throw CC_FileException("Bad Background chunk", INGL_BACK); } }; - std::map> const + std::map> const parser = { { INGL_NAME, parse_INGL_NAME }, @@ -428,11 +404,11 @@ Sheet::Sheet(size_t numPoints, uint8_t const* ptr, size_t size, ParseErrorHandle { INGL_BACK, parse_INGL_BACK }, }; - auto table = Parser::ParseOutLabels(ptr, ptr + size); + auto table = reader.ParseOutLabels(); for (auto& i : table) { auto the_parser = parser.find(std::get<0>(i)); if (the_parser != parser.end()) { - the_parser->second(this, std::get<1>(i), std::get<2>(i)); + the_parser->second(this, std::get<1>(i)); } } } @@ -766,12 +742,11 @@ void Sheet::sheet_round_trip_test() auto blank_sheet = Sheet(0); auto blank_sheet_data = blank_sheet.SerializeSheet(); // need to pull out the sheet data - auto table = Parser::ParseOutLabels(blank_sheet_data.data(), - blank_sheet_data.data() + blank_sheet_data.size()); + auto reader = Reader({blank_sheet_data.data(), blank_sheet_data.size()}); + auto table = reader.ParseOutLabels(); assert(table.size() == 1); assert(std::get<0>(table.front()) == INGL_SHET); - auto re_read_sheet = Sheet(0, std::get<1>(table.front()), - std::get<2>(table.front())); + auto re_read_sheet = Sheet(0, std::get<1>(table.front())); auto re_read_sheet_data = re_read_sheet.SerializeSheet(); bool is_equal = blank_sheet_data.size() == re_read_sheet_data.size() && std::equal(blank_sheet_data.begin(), blank_sheet_data.end(), re_read_sheet_data.begin()); (void)is_equal; @@ -781,12 +756,11 @@ void Sheet::sheet_round_trip_test() auto blank_sheet = Sheet(0, "new_sheet"); auto blank_sheet_data = blank_sheet.SerializeSheet(); // need to pull out the sheet data - auto table = Parser::ParseOutLabels(blank_sheet_data.data(), - blank_sheet_data.data() + blank_sheet_data.size()); + auto reader = Reader({blank_sheet_data.data(), blank_sheet_data.size()}); + auto table = reader.ParseOutLabels(); assert(table.size() == 1); assert(std::get<0>(table.front()) == INGL_SHET); - auto re_read_sheet = Sheet(0, std::get<1>(table.front()), - std::get<2>(table.front())); + auto re_read_sheet = Sheet(0, std::get<1>(table.front())); auto re_read_sheet_data = re_read_sheet.SerializeSheet(); bool is_equal = blank_sheet_data.size() == re_read_sheet_data.size() && std::equal(blank_sheet_data.begin(), blank_sheet_data.end(), re_read_sheet_data.begin()); (void)is_equal; @@ -806,12 +780,11 @@ void Sheet::sheet_round_trip_test() }; auto blank_sheet_data = blank_sheet.SerializeSheet(); // need to pull out the sheet data - auto table = Parser::ParseOutLabels(blank_sheet_data.data(), - blank_sheet_data.data() + blank_sheet_data.size()); + auto reader = Reader({blank_sheet_data.data(), blank_sheet_data.size()}); + auto table = reader.ParseOutLabels(); assert(table.size() == 1); assert(std::get<0>(table.front()) == INGL_SHET); - auto re_read_sheet = Sheet(1, std::get<1>(table.front()), - std::get<2>(table.front())); + auto re_read_sheet = Sheet(1, std::get<1>(table.front())); auto re_read_sheet_data = re_read_sheet.SerializeSheet(); bool is_equal = blank_sheet_data.size() == re_read_sheet_data.size() && std::equal(blank_sheet_data.begin(), blank_sheet_data.end(), re_read_sheet_data.begin()); // auto mismatch_at = std::mismatch(blank_sheet_data.begin(), diff --git a/src/core/CalChartSheet.h b/src/core/CalChartSheet.h index d8173dee..fdfcaf20 100644 --- a/src/core/CalChartSheet.h +++ b/src/core/CalChartSheet.h @@ -44,6 +44,7 @@ namespace CalChart { class Continuity; +class Reader; struct ParseErrorHandlers; // error occurred on parsing. First arg is what went wrong, second is the values that need to be fixed. @@ -51,8 +52,9 @@ class Sheet { public: Sheet(size_t numPoints); Sheet(size_t numPoints, std::string const& newname); - Sheet(size_t numPoints, std::istream& stream, ParseErrorHandlers const* correction = nullptr); - Sheet(size_t numPoints, uint8_t const* ptr, size_t size, ParseErrorHandlers const* correction = nullptr); + // intentionally a reference to Reader. + Sheet(Version_3_3_and_earlier, size_t numPoints, Reader&, ParseErrorHandlers const* correction = nullptr); + Sheet(size_t numPoints, Reader, ParseErrorHandlers const* correction = nullptr); ~Sheet(); private: diff --git a/src/core/CalChartShow.cpp b/src/core/CalChartShow.cpp index 3bdf826c..e6b47adf 100644 --- a/src/core/CalChartShow.cpp +++ b/src/core/CalChartShow.cpp @@ -59,22 +59,24 @@ std::unique_ptr Show::Create(ShowMode const& mode, std::vector Show::Create(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* correction) { - ReadAndCheckID(stream, INGL_INGL); - uint32_t version = ReadGurkSymbolAndGetVersion(stream, INGL_GURK); - if (version <= 0x303) { - return std::unique_ptr(new Show(mode, stream, correction)); - } - // read the whole stream into a block, making sure we don't skip white space stream.unsetf(std::ios::skipws); std::vector data(std::istream_iterator{ stream }, std::istream_iterator{}); // wxWidgets doesn't like it when we've reach the end of file. Remove flags stream.clear(); + auto reader = Reader({data.data(), data.size()}); + + reader.ReadAndCheckID(INGL_INGL); + auto version = reader.ReadGurkSymbolAndGetVersion(INGL_GURK); + + if (version <= 0x303) { + return std::unique_ptr(new Show(Version_3_3_and_earlier{}, mode, reader, correction)); + } // debug purposes, you can uncomment this line to have the show dumped // DoRecursiveParsing("", data.data(), data.data() + data.size()); - return std::unique_ptr(new Show(mode, data.data(), data.size(), correction)); + return std::unique_ptr(new Show(mode, reader, correction)); } // Create a new show @@ -86,27 +88,23 @@ Show::Show(ShowMode const& mode) // -=-=-=-=-=- LEGACY CODE -=-=-=-=-=- // Recommend that you don't touch this unless you know what you are doing. // Constructor for shows 3.3 and ealier. -Show::Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* correction) - : mMode(mode) +Show::Show(Version_3_3_and_earlier, ShowMode const& mode, Reader reader, ParseErrorHandlers const* correction) + : Show(mode) { // caller should have stripped off INGL and GURK headers - /* - ReadAndCheckID(stream, INGL_INGL); - uint32_t version = ReadGurkSymbolAndGetVersion(stream, INGL_GURK); - */ - ReadAndCheckID(stream, INGL_SHOW); + reader.ReadAndCheckID(INGL_SHOW); // Handle show info // read in the size: // <4><# points> - auto numpoints = ReadCheckIDandSize(stream, INGL_SIZE); + auto numpoints = reader.ReadCheckIDandSize(INGL_SIZE); mDotLabelAndInstrument.assign(numpoints, std::pair{ "", kDefault }); - uint32_t name = ReadLong(stream); + uint32_t name = reader.Get(); // Optional: read in the point labels // if (INGL_LABL == name) { - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); std::vector labels; auto str = (char const*)&data[0]; for (auto i = 0; i < GetNumPoints(); i++) { @@ -117,7 +115,7 @@ Show::Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* std::transform(labels.begin(), labels.end(), std::back_inserter(labelsAndInstruments), [](auto&& i) { return std::pair{ i, kDefault }; }); SetPointLabelAndInstrument(labelsAndInstruments); // peek for the next name - name = ReadLong(stream); + name = reader.Get(); } else { // fail? } @@ -125,126 +123,111 @@ Show::Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* // Optional: read in the description // if (INGL_DESC == name) { - std::vector data = FillData(stream); + std::vector data = reader.GetVector(); auto str = (char const*)&data[0]; SetDescr(std::string(str, strlen(str))); // peek for the next name - name = ReadLong(stream); + name = reader.Get(); } // Read in sheets // while (INGL_GURK == name) { - ReadAndCheckID(stream, INGL_SHET); + reader.ReadAndCheckID(INGL_SHET); - Sheet sheet(GetNumPoints(), stream, correction); + Sheet sheet(Version_3_3_and_earlier{}, GetNumPoints(), reader, correction); InsertSheet(sheet, GetNumSheets()); // ReadAndCheckID(stream, INGL_END); - ReadAndCheckID(stream, INGL_SHET); + reader.ReadAndCheckID(INGL_SHET); // peek for the next name - name = ReadLong(stream); + name = reader.Get(); } // ReadAndCheckID(stream, INGL_END); - ReadAndCheckID(stream, INGL_SHOW); + reader.ReadAndCheckID(INGL_SHOW); // now set the show to sheet 0 mSheetNum = 0; } // -=-=-=-=-=- LEGACY CODE -=-=-=-=-=- -Show::Show(ShowMode const& mode, uint8_t const* ptr, size_t size, ParseErrorHandlers const* correction) - : mMode(mode) +Show::Show(ShowMode const& mode, Reader reader, ParseErrorHandlers const* correction) + : Show(mode) { // caller should have stripped off INGL and GURK headers // construct the parser handlers // TODO: Why can't I capture this here? - auto parse_INGL_SIZE = [](Show* show, uint8_t const* ptr, size_t size) { - if (4 != size) { + auto parse_INGL_SIZE = [](Show& show, Reader reader) { + if (reader.size() != 4) { throw CC_FileException("Incorrect size", INGL_SIZE); } - auto numpoints = get_big_long(ptr); - show->mDotLabelAndInstrument.assign(numpoints, std::pair{ "", kDefault }); + auto numpoints = reader.Get(); + show.mDotLabelAndInstrument.assign(numpoints, std::pair{ "", kDefault }); }; - auto parse_INGL_LABL = [](Show* show, uint8_t const* ptr, size_t size) { + auto parse_INGL_LABL = [](Show& show, Reader reader) { std::vector> labels; - if (!size && show->GetNumPoints()) { + if (reader.size() == 0 && show.GetNumPoints()) { throw CC_FileException("Label the wrong size", INGL_LABL); } // restrict search to the size we're given - auto str = (char const*)ptr; - for (auto i = 0; i < show->GetNumPoints(); i++) { + for (auto i = 0; i < show.GetNumPoints(); i++) { + auto str = reader.Get(); labels.push_back({ str, kDefault }); - auto length = strlen(str) + 1; - if (length > size) { - throw CC_FileException("Label too large", INGL_LABL); - } - str += length; - size -= length; } - if (size != 0) { + if (reader.size() != 0) { throw CC_FileException("Label the wrong size", INGL_LABL); } - show->SetPointLabelAndInstrument(labels); + show.SetPointLabelAndInstrument(labels); }; - auto parse_INGL_INST = [](Show* show, uint8_t const* ptr, size_t size) { - auto currentLabels = show->mDotLabelAndInstrument; - if (!size && show->GetNumPoints()) { + auto parse_INGL_INST = [](Show& show, Reader reader) { + auto currentLabels = show.mDotLabelAndInstrument; + if (reader.size() == 0 && show.GetNumPoints()) { throw CC_FileException("Label the wrong size", INGL_LABL); } // restrict search to the size we're given - auto str = (char const*)ptr; - for (auto i = 0; i < show->GetNumPoints(); i++) { - auto thisInst = std::string{ str }; + for (auto i = 0; i < show.GetNumPoints(); i++) { + auto thisInst = reader.Get(); currentLabels.at(i).second = thisInst == "" ? kDefault : thisInst; - auto length = strlen(str) + 1; - if (length > size) { - throw CC_FileException("Label too large", INGL_LABL); - } - str += length; - size -= length; } - if (size != 0) { + if (reader.size() != 0) { throw CC_FileException("Label the wrong size", INGL_LABL); } - show->SetPointLabelAndInstrument(currentLabels); + show.SetPointLabelAndInstrument(currentLabels); }; - auto parse_INGL_DESC = [](Show* show, uint8_t const* ptr, size_t size) { - auto str = (char const*)ptr; - if (size != (strlen(str) + 1)) { + auto parse_INGL_DESC = [](Show& show, Reader reader) { + auto str = reader.Get(); + if (reader.size() != 0) { throw CC_FileException("Description the wrong size", INGL_DESC); } - show->SetDescr(std::string(str, strlen(str))); + show.SetDescr(str); }; - auto parse_INGL_SHET = [correction](Show* show, uint8_t const* ptr, size_t size) { - Sheet sheet(show->GetNumPoints(), ptr, size, correction); - auto sheet_num = show->GetCurrentSheetNum(); - show->InsertSheet(sheet, show->GetNumSheets()); - show->SetCurrentSheet(sheet_num); + auto parse_INGL_SHET = [correction](Show& show, Reader reader) { + Sheet sheet(show.GetNumPoints(), reader, correction); + auto sheet_num = show.GetCurrentSheetNum(); + show.InsertSheet(sheet, show.GetNumSheets()); + show.SetCurrentSheet(sheet_num); }; - auto parse_INGL_SELE = [](Show* show, uint8_t const* ptr, size_t size) { - if ((size % 4) != 0) { + auto parse_INGL_SELE = [](Show& show, Reader reader) { + if ((reader.size() % 4) != 0) { throw CC_FileException("Incorrect size", INGL_SIZE); } - while (size) { - show->mSelectionList.insert(get_big_long(ptr)); - ptr += 4; - size -= 4; + while (reader.size()) { + show.mSelectionList.insert(reader.Get()); } }; - auto parse_INGL_CURR = [](Show* show, uint8_t const* ptr, size_t size) { - if (4 != size) { + auto parse_INGL_CURR = [](Show& show, Reader reader) { + if (reader.size() != 4) { throw CC_FileException("Incorrect size", INGL_SIZE); } - show->mSheetNum = get_big_long(ptr); + show.mSheetNum = reader.Get(); }; - auto parse_INGL_MODE = [](Show* show, uint8_t const* ptr, size_t size) { - show->mMode = ShowMode::CreateShowMode({ ptr, ptr + size }); + auto parse_INGL_MODE = [](Show& show, Reader reader) { + show.mMode = ShowMode::CreateShowMode(reader); }; // [=] needed here to pull in the parse functions - auto parse_INGL_SHOW = [=](Show* show, uint8_t const* ptr, size_t size) { - std::map> const parser = { + auto parse_INGL_SHOW = [=](Show& show, Reader reader) { + std::map> const parser = { { INGL_SIZE, parse_INGL_SIZE }, { INGL_LABL, parse_INGL_LABL }, { INGL_INST, parse_INGL_INST }, @@ -254,20 +237,20 @@ Show::Show(ShowMode const& mode, uint8_t const* ptr, size_t size, ParseErrorHand { INGL_CURR, parse_INGL_CURR }, { INGL_MODE, parse_INGL_MODE }, }; - auto table = Parser::ParseOutLabels(ptr, ptr + size); + auto table = reader.ParseOutLabels(); for (auto& i : table) { auto the_parser = parser.find(std::get<0>(i)); if (the_parser != parser.end()) { - the_parser->second(show, std::get<1>(i), std::get<2>(i)); + the_parser->second(show, std::get<1>(i)); } } }; - auto table = Parser::ParseOutLabels(ptr, ptr + size); + auto table = reader.ParseOutLabels(); bool found_show = false; for (auto& i : table) { if (std::get<0>(i) == INGL_SHOW) { - parse_INGL_SHOW(this, std::get<1>(i), std::get<2>(i)); + parse_INGL_SHOW(*this, std::get<1>(i)); found_show = true; } } @@ -1109,7 +1092,7 @@ void Show::CC_show_round_trip_test_with_number_label_description() Append(data, Construct_block(INGL_MODE, ShowMode::GetDefaultShowMode().Serialize())); auto show_data = Construct_block(INGL_SHOW, data); - Show show1(ShowMode::GetDefaultShowMode(), (const uint8_t*)show_data.data(), show_data.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(const uint8_t*)show_data.data(), show_data.size()})); auto show1_data = show1.SerializeShow(); // eat header show1_data.erase(show1_data.begin(), show1_data.begin() + 8); @@ -1136,7 +1119,7 @@ void Show::CC_show_round_trip_test_with_different_show_modes() // eat header show1_data.erase(show1_data.begin(), show1_data.begin() + 8); - Show show2(ShowMode::GetDefaultShowMode(), (uint8_t const*)show1_data.data(), show1_data.size()); + Show show2(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show1_data.data(), show1_data.size()})); assert(show2.GetShowMode().HashW() == 36); } @@ -1144,8 +1127,8 @@ void Show::CC_show_blank_desc_test() { auto show_zero_points_zero_labels_zero_description = Construct_show_zero_points_zero_labels_zero_description(); Show show1(ShowMode::GetDefaultShowMode(), - (uint8_t const*)show_zero_points_zero_labels_zero_description.data(), - show_zero_points_zero_labels_zero_description.size()); + Reader({(uint8_t const*)show_zero_points_zero_labels_zero_description.data(), + show_zero_points_zero_labels_zero_description.size()})); auto show1_data = show1.SerializeShow(); // eat header show1_data.erase(show1_data.begin(), show1_data.begin() + 8); @@ -1157,8 +1140,8 @@ void Show::CC_show_blank_desc_test() // now remove the description and they should be equal auto show_zero_points_zero_labels = Construct_show_zero_points_zero_labels(); - Show show2(ShowMode::GetDefaultShowMode(), (uint8_t const*)show_zero_points_zero_labels.data(), - show_zero_points_zero_labels.size()); + Show show2(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show_zero_points_zero_labels.data(), + show_zero_points_zero_labels.size()})); auto show2_data = show2.SerializeShow(); show2_data.erase(show2_data.begin(), show2_data.begin() + 8); is_equal = show2_data.size() == show_zero_points_zero_labels.size() && std::equal(show2_data.begin(), show2_data.end(), show_zero_points_zero_labels.begin()); @@ -1195,7 +1178,7 @@ void Show::CC_show_wrong_size_throws_exception() auto show_data = Construct_block(INGL_SHOW, points_3); bool hit_exception = false; try { - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)show_data.data(), show_data.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show_data.data(), show_data.size()})); } catch (CC_FileException const&) { hit_exception = true; } @@ -1216,7 +1199,7 @@ void Show::CC_show_wrong_size_number_labels_throws() auto show_data = Construct_block(INGL_SHOW, t_show_data); bool hit_exception = false; try { - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)show_data.data(), show_data.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show_data.data(), show_data.size()})); } catch (CC_FileException const&) { hit_exception = true; } @@ -1233,7 +1216,7 @@ void Show::CC_show_wrong_size_number_labels_throws() auto show_data = Construct_block(INGL_SHOW, t_show_data); bool hit_exception = false; try { - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)show_data.data(), show_data.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show_data.data(), show_data.size()})); } catch (CC_FileException const&) { hit_exception = true; } @@ -1257,7 +1240,7 @@ void Show::CC_show_wrong_size_description() auto show_data = Construct_block(INGL_SHOW, t_show_data); bool hit_exception = false; try { - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)show_data.data(), show_data.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)show_data.data(), show_data.size()})); } catch (CC_FileException const&) { hit_exception = true; } @@ -1271,7 +1254,7 @@ void Show::CC_show_extra_cruft_ok() { // now remove the description and they should be equal auto extra_cruft = Construct_show_zero_points_zero_labels_1_sheet_and_random(); - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)extra_cruft.data(), extra_cruft.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)extra_cruft.data(), extra_cruft.size()})); auto show1_data = show1.SerializeShow(); auto blank_show = Show::Create(ShowMode::GetDefaultShowMode()); @@ -1287,7 +1270,7 @@ void Show::CC_show_with_nothing_throws() std::vector empty{}; bool hit_exception = false; try { - Show show1(ShowMode::GetDefaultShowMode(), (uint8_t const*)empty.data(), empty.size()); + Show show1(ShowMode::GetDefaultShowMode(), Reader({(uint8_t const*)empty.data(), empty.size()})); } catch (CC_FileException const&) { hit_exception = true; } diff --git a/src/core/CalChartShow.h b/src/core/CalChartShow.h index b50ec284..106917a8 100644 --- a/src/core/CalChartShow.h +++ b/src/core/CalChartShow.h @@ -55,6 +55,7 @@ namespace CalChart { class Show; class Sheet; +class Reader; struct ParseErrorHandlers; using Show_command = std::function; @@ -74,9 +75,9 @@ class Show { private: Show(ShowMode const& mode); // calchart 3.3 and earlier is parsed via the istream. - Show(ShowMode const& mode, std::istream& stream, ParseErrorHandlers const* correction = nullptr); + Show(Version_3_3_and_earlier, ShowMode const& mode, Reader reader, ParseErrorHandlers const* correction = nullptr); // calchart 3.4 and later are given a data blob to parse. - Show(ShowMode const& mode, const uint8_t* ptr, size_t size, ParseErrorHandlers const* correction = nullptr); + Show(ShowMode const& mode, Reader reader, ParseErrorHandlers const* correction = nullptr); public: ~Show(); diff --git a/src/core/CalChartShowMode.cpp b/src/core/CalChartShowMode.cpp index 0a0717fc..03696433 100644 --- a/src/core/CalChartShowMode.cpp +++ b/src/core/CalChartShowMode.cpp @@ -22,6 +22,7 @@ #include "CalChartShowMode.h" #include "CalChartFileFormat.h" +#include "ccvers.h" #include #include @@ -133,28 +134,23 @@ ShowMode ShowMode::CreateShowMode(CalChart::Coord size, CalChart::Coord offset, }; } -ShowMode ShowMode::CreateShowMode(std::vector const& data) +ShowMode ShowMode::CreateShowMode(CalChart::Reader reader) { - auto begin = data.data(); - auto end = data.data() + data.size(); - ShowModeInfo_t values; for (auto& i : values) { - if (std::distance(begin, end) < 4) { + if (reader.size() < 4) { throw std::runtime_error("Error, size of ShowMode is not correct"); } - i = Parser::get_big_long(begin); - begin += 4; + i = reader.Get(); } YardLinesInfo_t yardlines; for (auto& i : yardlines) { - if (std::distance(begin, end) < 1) { + if (reader.size() < 1) { throw std::runtime_error("Error, yardtext does not have enough for a null terminator"); } - i = (char const*)begin; - begin += i.size() + 1; // 1 is for the null terminator + i = reader.Get(); } - if (std::distance(begin, end) != 0) { + if (reader.size() != 0) { throw std::runtime_error("Error, size of ShowMode is not correct"); } return ShowMode::CreateShowMode(values, yardlines); @@ -197,7 +193,7 @@ void ShowMode_UnitTests() { auto uut1 = ShowMode::GetDefaultShowMode(); auto data = uut1.Serialize(); - auto uut2 = ShowMode::CreateShowMode(data); + auto uut2 = ShowMode::CreateShowMode(CalChart::Reader({data.data(), data.size()})); assert(uut1 == uut2); } diff --git a/src/core/CalChartShowMode.h b/src/core/CalChartShowMode.h index f0d720f1..8fc266bb 100644 --- a/src/core/CalChartShowMode.h +++ b/src/core/CalChartShowMode.h @@ -31,6 +31,8 @@ namespace CalChart { +class Reader; + static constexpr auto SPR_YARD_LEFT = 8; static constexpr auto SPR_YARD_RIGHT = 4; static constexpr auto SPR_YARD_ABOVE = 2; @@ -73,7 +75,7 @@ class ShowMode { CalChart::Coord border1, CalChart::Coord border2, unsigned short whash, unsigned short ehash, YardLinesInfo_t const& yardlines); - static ShowMode CreateShowMode(std::vector const&); + static ShowMode CreateShowMode(CalChart::Reader reader); std::vector Serialize() const; ShowModeInfo_t GetShowModeInfo() const; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c1bba553..35aefbab 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,6 +4,7 @@ add_executable(CalChartTests ${CMAKE_CURRENT_SOURCE_DIR}/CalChartContinuityTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CalChartCoordTests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/CalChartFileFormatTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CalChartPointTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CalChartSheetTests.cpp ${CMAKE_CURRENT_SOURCE_DIR}/CalChartShowTests.cpp diff --git a/tests/CalChartFileFormatTests.cpp b/tests/CalChartFileFormatTests.cpp new file mode 100644 index 00000000..5ef0a4e2 --- /dev/null +++ b/tests/CalChartFileFormatTests.cpp @@ -0,0 +1,17 @@ +#include "catch2/catch.hpp" +#include "CalChartFileFormat.h" + +TEST_CASE( "CalChartParserBasics" ) { + auto a = std::vector{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; + + auto reader = CalChart::Reader({a.data(), a.size()}); + CHECK(reader.Peek() == 0x0001); + CHECK(reader.Peek() == 0x00010203); + CHECK(reader.Peek() == 0x0001); + CHECK(reader.Peek() == 0x00010203); + + CHECK(reader.Get() == 0x0001); + CHECK(reader.Get() == 0x02030405); + CHECK(reader.Get() == 0x0607); + CHECK(reader.Get() == 0x08090a0b); +}