Commit dda8a5c4 by Niels

adjusted code to documentation; some cleanup

parent 139ef0e7
...@@ -1110,7 +1110,7 @@ class basic_json ...@@ -1110,7 +1110,7 @@ class basic_json
//////////////////// ////////////////////
/// access specified element with bounds checking /// access specified element with bounds checking
inline reference at(size_type pos) inline reference at(size_type idx)
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1118,11 +1118,11 @@ class basic_json ...@@ -1118,11 +1118,11 @@ class basic_json
throw std::runtime_error("cannot use at with " + type_name()); throw std::runtime_error("cannot use at with " + type_name());
} }
return m_value.array->at(pos); return m_value.array->at(idx);
} }
/// access specified element with bounds checking /// access specified element with bounds checking
inline const_reference at(size_type pos) const inline const_reference at(size_type idx) const
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1130,11 +1130,35 @@ class basic_json ...@@ -1130,11 +1130,35 @@ class basic_json
throw std::runtime_error("cannot use at with " + type_name()); throw std::runtime_error("cannot use at with " + type_name());
} }
return m_value.array->at(pos); return m_value.array->at(idx);
}
/// access specified element with bounds checking
inline reference at(const typename object_t::key_type& key)
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
}
/// access specified element with bounds checking
inline const_reference at(const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
} }
/// access specified element /// access specified element
inline reference operator[](size_type pos) inline reference operator[](size_type idx)
{ {
// implicitly convert null to object // implicitly convert null to object
if (m_type == value_t::null) if (m_type == value_t::null)
...@@ -1151,16 +1175,16 @@ class basic_json ...@@ -1151,16 +1175,16 @@ class basic_json
throw std::runtime_error("cannot use [] with " + type_name()); throw std::runtime_error("cannot use [] with " + type_name());
} }
for (size_t i = m_value.array->size(); i <= pos; ++i) for (size_t i = m_value.array->size(); i <= idx; ++i)
{ {
m_value.array->push_back(basic_json()); m_value.array->push_back(basic_json());
} }
return m_value.array->operator[](pos); return m_value.array->operator[](idx);
} }
/// access specified element /// access specified element
inline const_reference operator[](size_type pos) const inline const_reference operator[](size_type idx) const
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1168,31 +1192,7 @@ class basic_json ...@@ -1168,31 +1192,7 @@ class basic_json
throw std::runtime_error("cannot use [] with " + type_name()); throw std::runtime_error("cannot use [] with " + type_name());
} }
return m_value.array->operator[](pos); return m_value.array->operator[](idx);
}
/// access specified element with bounds checking
inline reference at(const typename object_t::key_type& key)
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
}
/// access specified element with bounds checking
inline const_reference at(const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
} }
/// access specified element /// access specified element
......
...@@ -1110,7 +1110,7 @@ class basic_json ...@@ -1110,7 +1110,7 @@ class basic_json
//////////////////// ////////////////////
/// access specified element with bounds checking /// access specified element with bounds checking
inline reference at(size_type pos) inline reference at(size_type idx)
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1118,11 +1118,11 @@ class basic_json ...@@ -1118,11 +1118,11 @@ class basic_json
throw std::runtime_error("cannot use at with " + type_name()); throw std::runtime_error("cannot use at with " + type_name());
} }
return m_value.array->at(pos); return m_value.array->at(idx);
} }
/// access specified element with bounds checking /// access specified element with bounds checking
inline const_reference at(size_type pos) const inline const_reference at(size_type idx) const
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1130,11 +1130,35 @@ class basic_json ...@@ -1130,11 +1130,35 @@ class basic_json
throw std::runtime_error("cannot use at with " + type_name()); throw std::runtime_error("cannot use at with " + type_name());
} }
return m_value.array->at(pos); return m_value.array->at(idx);
}
/// access specified element with bounds checking
inline reference at(const typename object_t::key_type& key)
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
}
/// access specified element with bounds checking
inline const_reference at(const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
} }
/// access specified element /// access specified element
inline reference operator[](size_type pos) inline reference operator[](size_type idx)
{ {
// implicitly convert null to object // implicitly convert null to object
if (m_type == value_t::null) if (m_type == value_t::null)
...@@ -1151,16 +1175,16 @@ class basic_json ...@@ -1151,16 +1175,16 @@ class basic_json
throw std::runtime_error("cannot use [] with " + type_name()); throw std::runtime_error("cannot use [] with " + type_name());
} }
for (size_t i = m_value.array->size(); i <= pos; ++i) for (size_t i = m_value.array->size(); i <= idx; ++i)
{ {
m_value.array->push_back(basic_json()); m_value.array->push_back(basic_json());
} }
return m_value.array->operator[](pos); return m_value.array->operator[](idx);
} }
/// access specified element /// access specified element
inline const_reference operator[](size_type pos) const inline const_reference operator[](size_type idx) const
{ {
// at only works for arrays // at only works for arrays
if (m_type != value_t::array) if (m_type != value_t::array)
...@@ -1168,31 +1192,7 @@ class basic_json ...@@ -1168,31 +1192,7 @@ class basic_json
throw std::runtime_error("cannot use [] with " + type_name()); throw std::runtime_error("cannot use [] with " + type_name());
} }
return m_value.array->operator[](pos); return m_value.array->operator[](idx);
}
/// access specified element with bounds checking
inline reference at(const typename object_t::key_type& key)
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
}
/// access specified element with bounds checking
inline const_reference at(const typename object_t::key_type& key) const
{
// at only works for objects
if (m_type != value_t::object)
{
throw std::runtime_error("cannot use at with " + type_name());
}
return m_value.object->at(key);
} }
/// access specified element /// access specified element
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment