From 4adc7c78fcd0f89622065d60241223c25b66ebe5 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Mon, 31 Mar 2014 10:30:33 -0700 Subject: [PATCH] Remove array indexing from UnknownElement --- libaegisub/common/cajun/elements.cpp | 4 --- .../include/libaegisub/cajun/elements.h | 25 ++++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/libaegisub/common/cajun/elements.cpp b/libaegisub/common/cajun/elements.cpp index 7e39e8260..20c38aebd 100644 --- a/libaegisub/common/cajun/elements.cpp +++ b/libaegisub/common/cajun/elements.cpp @@ -124,10 +124,6 @@ const UnknownElement& UnknownElement::operator[] (const std::string& key) const return it->second; } -UnknownElement& UnknownElement::operator[](size_t index) { return CastTo()[index]; } -UnknownElement const& UnknownElement::operator[](size_t index) const { return CastTo()[index]; } - - template ElementTypeT const& UnknownElement::CastTo() const { diff --git a/libaegisub/include/libaegisub/cajun/elements.h b/libaegisub/include/libaegisub/cajun/elements.h index c3ffe7046..63688a07f 100644 --- a/libaegisub/include/libaegisub/cajun/elements.h +++ b/libaegisub/include/libaegisub/cajun/elements.h @@ -35,14 +35,12 @@ typedef std::string String; typedef std::deque Array; typedef std::map Object; -class Null; - +struct Null; ///////////////////////////////////////////////////////////////////////// // Exception - base class for all JSON-related runtime errors -class Exception : public std::runtime_error -{ +class Exception : public std::runtime_error { public: Exception(const std::string& sMessage) : std::runtime_error(sMessage) { } }; @@ -60,8 +58,7 @@ public: // element accesses can be chained together, allowing the following // (when document structure is well-known): // String str = objInvoices[1]["Customer"]["Company"]; -class UnknownElement -{ +class UnknownElement { public: UnknownElement(); UnknownElement(const UnknownElement& unknown); @@ -96,16 +93,12 @@ public: operator Null&(); // provides quick access to children when real element type is object - template - UnknownElement& operator[] (const char (&key)[N]) { return operator[](std::string(key)); } - template - const UnknownElement& operator[] (const char (&key)[N]) const { return operator[](std::string(key)); } UnknownElement& operator[] (const std::string& key); const UnknownElement& operator[] (const std::string& key) const; - - // provides quick access to children when real element type is array - UnknownElement& operator[] (size_t index); - const UnknownElement& operator[] (size_t index) const; + template + UnknownElement& operator[] (const char(&key)[N]) { return operator[](std::string(key)); } + template + const UnknownElement& operator[] (const char(&key)[N]) const { return operator[](std::string(key)); } // implements visitor pattern void Accept(ConstVisitor& visitor) const; @@ -133,9 +126,7 @@ private: ///////////////////////////////////////////////////////////////////////////////// // Null - doesn't do much of anything but satisfy the JSON spec. It is the default // element type of UnknownElement -class Null -{ -public: +struct Null { bool operator == (const Null&) const { return true; } };