From 61b1741376991353279d1077cc9504003fab9fce Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Thu, 22 Dec 2011 21:12:55 +0000 Subject: [PATCH] Remove all the json::Reader::Read overloads, as we never actually use them Originally committed to SVN as r6021. --- aegisub/libaegisub/common/cajun/reader.cpp | 14 +------ .../include/libaegisub/cajun/reader.h | 13 ------- aegisub/tests/libaegisub_cajun.cpp | 39 ++++++++----------- 3 files changed, 19 insertions(+), 47 deletions(-) diff --git a/aegisub/libaegisub/common/cajun/reader.cpp b/aegisub/libaegisub/common/cajun/reader.cpp index ddf3556b2..221d377aa 100644 --- a/aegisub/libaegisub/common/cajun/reader.cpp +++ b/aegisub/libaegisub/common/cajun/reader.cpp @@ -85,17 +85,7 @@ public: bool EOS() const { return m_itCurrent == m_Tokens.end(); } }; -void Reader::Read(Object& object, std::istream& istr) { Read_i(object, istr); } -void Reader::Read(Array& array, std::istream& istr) { Read_i(array, istr); } -void Reader::Read(String& string, std::istream& istr) { Read_i(string, istr); } -void Reader::Read(Integer& number, std::istream& istr) { Read_i(number, istr); } -void Reader::Read(Double& number, std::istream& istr) { Read_i(number, istr); } -void Reader::Read(Boolean& boolean, std::istream& istr) { Read_i(boolean, istr); } -void Reader::Read(Null& null, std::istream& istr) { Read_i(null, istr); } -void Reader::Read(UnknownElement& unknown, std::istream& istr) { Read_i(unknown, istr); } - -template -void Reader::Read_i(ElementTypeT& element, std::istream& istr) { +void Reader::Read(UnknownElement& unknown, std::istream& istr) { Reader reader; Tokens tokens; @@ -103,7 +93,7 @@ void Reader::Read_i(ElementTypeT& element, std::istream& istr) { reader.Scan(tokens, inputStream); TokenStream tokenStream(tokens); - element = reader.Parse(tokenStream); + unknown = reader.Parse(tokenStream); if (!tokenStream.EOS()) { Token const& token = tokenStream.Peek(); diff --git a/aegisub/libaegisub/include/libaegisub/cajun/reader.h b/aegisub/libaegisub/include/libaegisub/cajun/reader.h index a8f9dfcc0..caa1284d1 100644 --- a/aegisub/libaegisub/include/libaegisub/cajun/reader.h +++ b/aegisub/libaegisub/include/libaegisub/cajun/reader.h @@ -55,16 +55,6 @@ public: Reader::Location m_locTokenEnd; }; - // if you know what the document looks like, call one of these... - static void Read(Object& object, std::istream& istr); - static void Read(Array& array, std::istream& istr); - static void Read(String& string, std::istream& istr); - static void Read(Integer& number, std::istream& istr); - static void Read(Double& number, std::istream& istr); - static void Read(Boolean& boolean, std::istream& istr); - static void Read(Null& null, std::istream& istr); - - // ...otherwise, if you don't know, call this & visit it static void Read(UnknownElement& elementRoot, std::istream& istr); private: @@ -94,9 +84,6 @@ private: class TokenStream; typedef std::vector Tokens; - template - static void Read_i(ElementTypeT& element, std::istream& istr); - // scanning istream into token sequence void Scan(Tokens& tokens, InputStream& inputStream); diff --git a/aegisub/tests/libaegisub_cajun.cpp b/aegisub/tests/libaegisub_cajun.cpp index 2153e866f..a1bb0da0a 100644 --- a/aegisub/tests/libaegisub_cajun.cpp +++ b/aegisub/tests/libaegisub_cajun.cpp @@ -280,7 +280,7 @@ TEST_F(lagi_cajun, ObjectEquality) { } TEST_F(lagi_cajun, Read) { - json::Object obj; + json::UnknownElement obj; std::istringstream doc("{\"String\" : \"This is a test\", \"Boolean\" : false, \"Null\" : null }"); EXPECT_NO_THROW(json::Reader::Read(obj, doc)); EXPECT_NO_THROW(obj["String"]); @@ -321,52 +321,47 @@ TEST_F(lagi_cajun, Write) { } TEST_F(lagi_cajun, ReaderParserErrors) { - json::Array arr; + json::UnknownElement ue; + std::istringstream missing_comma("[1 2]"); - EXPECT_THROW(json::Reader::Read(arr, missing_comma), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, missing_comma), json::Exception); - json::Double num; std::istringstream garbage_after_number("123eee"); - EXPECT_THROW(json::Reader::Read(num, garbage_after_number), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, garbage_after_number), json::Exception); - json::String str; std::istringstream unexpected_eof("["); - EXPECT_THROW(json::Reader::Read(str, unexpected_eof), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, unexpected_eof), json::Exception); std::istringstream bad_initial_token("]"); - EXPECT_THROW(json::Reader::Read(str, bad_initial_token), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, bad_initial_token), json::Exception); std::istringstream garbage_after_end("[]a"); - EXPECT_THROW(json::Reader::Read(str, garbage_after_end), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, garbage_after_end), json::Exception); - json::Null null; std::istringstream empty_str(""); - EXPECT_THROW(json::Reader::Read(null, empty_str), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, empty_str), json::Exception); - json::Object obj; std::istringstream dupe_keys("{\"a\": [], \"a\": 0}"); - EXPECT_THROW(json::Reader::Read(obj, dupe_keys), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, dupe_keys), json::Exception); std::istringstream unique_keys("{\"a\": [], \"b\": 0}"); - EXPECT_NO_THROW(json::Reader::Read(obj, unique_keys)); + EXPECT_NO_THROW(json::Reader::Read(ue, unique_keys)); } TEST_F(lagi_cajun, ReaderScanErrors) { - json::Object obj; + json::UnknownElement ue; + std::istringstream doc("[true, false, thiswontwork]"); + EXPECT_THROW(json::Reader::Read(ue, doc), json::Exception); - EXPECT_THROW(json::Reader::Read(obj, doc), json::Exception); - - json::Double num; std::istringstream garbage_after_number("123abc"); - EXPECT_THROW(json::Reader::Read(num, garbage_after_number), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, garbage_after_number), json::Exception); - json::String str; std::istringstream bad_escape("\"\\j\""); - EXPECT_THROW(json::Reader::Read(str, bad_escape), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, bad_escape), json::Exception); std::istringstream unexpected_eof("\"abc"); - EXPECT_THROW(json::Reader::Read(str, unexpected_eof), json::Exception); + EXPECT_THROW(json::Reader::Read(ue, unexpected_eof), json::Exception); } std::string roundtrip_test(const char *in) {