Skip to content

Commit

Permalink
add convenience method: at() and lookup()
Browse files Browse the repository at this point in the history
  • Loading branch information
ttti07 committed Mar 28, 2016
1 parent b51e368 commit 88f5419
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions include/ucl++.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class Ucl final {
return default_val;
}

const Ucl operator[] (size_t i) const
const Ucl at (size_t i) const
{
if (type () == UCL_ARRAY) {
return Ucl (ucl_array_find_index (obj.get(), i));
Expand All @@ -317,7 +317,7 @@ class Ucl final {
return Ucl (nullptr);
}

const Ucl operator[](const std::string &key) const
const Ucl lookup (const std::string &key) const
{
if (type () == UCL_OBJECT) {
return Ucl (ucl_object_lookup_len (obj.get(),
Expand All @@ -326,6 +326,16 @@ class Ucl final {

return Ucl (nullptr);
}

inline const Ucl operator[] (size_t i) const
{
return at(i);
}

inline const Ucl operator[](const std::string &key) const
{
return lookup(key);
}
// Serialize.
void dump (std::string &out, ucl_emitter_t type = UCL_EMIT_JSON) const
{
Expand Down

0 comments on commit 88f5419

Please sign in to comment.