mirror of https://github.com/odrling/Aegisub
Remove array indexing from UnknownElement
This commit is contained in:
parent
fb79c47cb5
commit
4adc7c78fc
|
@ -124,10 +124,6 @@ const UnknownElement& UnknownElement::operator[] (const std::string& key) const
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnknownElement& UnknownElement::operator[](size_t index) { return CastTo<Array>()[index]; }
|
|
||||||
UnknownElement const& UnknownElement::operator[](size_t index) const { return CastTo<Array>()[index]; }
|
|
||||||
|
|
||||||
|
|
||||||
template <typename ElementTypeT>
|
template <typename ElementTypeT>
|
||||||
ElementTypeT const& UnknownElement::CastTo() const
|
ElementTypeT const& UnknownElement::CastTo() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,14 +35,12 @@ typedef std::string String;
|
||||||
typedef std::deque<UnknownElement> Array;
|
typedef std::deque<UnknownElement> Array;
|
||||||
typedef std::map<std::string, UnknownElement> Object;
|
typedef std::map<std::string, UnknownElement> Object;
|
||||||
|
|
||||||
class Null;
|
struct Null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////
|
||||||
// Exception - base class for all JSON-related runtime errors
|
// Exception - base class for all JSON-related runtime errors
|
||||||
class Exception : public std::runtime_error
|
class Exception : public std::runtime_error {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Exception(const std::string& sMessage) : std::runtime_error(sMessage) { }
|
Exception(const std::string& sMessage) : std::runtime_error(sMessage) { }
|
||||||
};
|
};
|
||||||
|
@ -60,8 +58,7 @@ public:
|
||||||
// element accesses can be chained together, allowing the following
|
// element accesses can be chained together, allowing the following
|
||||||
// (when document structure is well-known):
|
// (when document structure is well-known):
|
||||||
// String str = objInvoices[1]["Customer"]["Company"];
|
// String str = objInvoices[1]["Customer"]["Company"];
|
||||||
class UnknownElement
|
class UnknownElement {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
UnknownElement();
|
UnknownElement();
|
||||||
UnknownElement(const UnknownElement& unknown);
|
UnknownElement(const UnknownElement& unknown);
|
||||||
|
@ -96,16 +93,12 @@ public:
|
||||||
operator Null&();
|
operator Null&();
|
||||||
|
|
||||||
// provides quick access to children when real element type is object
|
// provides quick access to children when real element type is object
|
||||||
template<int N>
|
|
||||||
UnknownElement& operator[] (const char (&key)[N]) { return operator[](std::string(key)); }
|
|
||||||
template<int N>
|
|
||||||
const UnknownElement& operator[] (const char (&key)[N]) const { return operator[](std::string(key)); }
|
|
||||||
UnknownElement& operator[] (const std::string& key);
|
UnknownElement& operator[] (const std::string& key);
|
||||||
const UnknownElement& operator[] (const std::string& key) const;
|
const UnknownElement& operator[] (const std::string& key) const;
|
||||||
|
template<int N>
|
||||||
// provides quick access to children when real element type is array
|
UnknownElement& operator[] (const char(&key)[N]) { return operator[](std::string(key)); }
|
||||||
UnknownElement& operator[] (size_t index);
|
template<int N>
|
||||||
const UnknownElement& operator[] (size_t index) const;
|
const UnknownElement& operator[] (const char(&key)[N]) const { return operator[](std::string(key)); }
|
||||||
|
|
||||||
// implements visitor pattern
|
// implements visitor pattern
|
||||||
void Accept(ConstVisitor& visitor) const;
|
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
|
// Null - doesn't do much of anything but satisfy the JSON spec. It is the default
|
||||||
// element type of UnknownElement
|
// element type of UnknownElement
|
||||||
class Null
|
struct Null {
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator == (const Null&) const { return true; }
|
bool operator == (const Null&) const { return true; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue