Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add the std iterator typedefs to iterator and const_iterator #19

Merged
merged 1 commit into from
Jan 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions src/json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1400,11 +1400,11 @@ json::iterator::iterator(json* j) : object_(j)
{
if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
vi_ = new array_t::iterator(object_->value_.array->begin());
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
oi_ = new object_t::iterator(object_->value_.object->begin());
}
Expand All @@ -1415,11 +1415,11 @@ json::iterator::iterator(const json::iterator& o) : object_(o.object_)
{
if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
vi_ = new array_t::iterator(*(o.vi_));
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
oi_ = new object_t::iterator(*(o.oi_));
}
Expand Down Expand Up @@ -1449,11 +1449,11 @@ bool json::iterator::operator==(const json::iterator& o) const

if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
return (vi_ == o.vi_);
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
return (oi_ == o.oi_);
}
Expand All @@ -1477,15 +1477,15 @@ json::iterator& json::iterator::operator++()

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
if (++(*vi_) == object_->value_.array->end())
{
object_ = nullptr;
}
break;
}
case (value_type::object):
case (json::value_type::object):
{
if (++(*oi_) == object_->value_.object->end())
{
Expand All @@ -1511,11 +1511,11 @@ json& json::iterator::operator*() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return **vi_;
}
case (value_type::object):
case (json::value_type::object):
{
return (*oi_)->second;
}
Expand All @@ -1536,11 +1536,11 @@ json* json::iterator::operator->() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return &(**vi_);
}
case (value_type::object):
case (json::value_type::object):
{
return &((*oi_)->second);
}
Expand All @@ -1553,7 +1553,7 @@ json* json::iterator::operator->() const

std::string json::iterator::key() const
{
if (object_ != nullptr and object_->type_ == value_type::object)
if (object_ != nullptr and object_->type_ == json::value_type::object)
{
return (*oi_)->first;
}
Expand All @@ -1573,11 +1573,11 @@ json& json::iterator::value() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return **vi_;
}
case (value_type::object):
case (json::value_type::object):
{
return (*oi_)->second;
}
Expand All @@ -1593,11 +1593,11 @@ json::const_iterator::const_iterator(const json* j) : object_(j)
{
if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
vi_ = new array_t::const_iterator(object_->value_.array->begin());
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
oi_ = new object_t::const_iterator(object_->value_.object->begin());
}
Expand All @@ -1608,11 +1608,11 @@ json::const_iterator::const_iterator(const json::const_iterator& o) : object_(o.
{
if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
vi_ = new array_t::const_iterator(*(o.vi_));
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
oi_ = new object_t::const_iterator(*(o.oi_));
}
Expand All @@ -1623,11 +1623,11 @@ json::const_iterator::const_iterator(const json::iterator& o) : object_(o.object
{
if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
vi_ = new array_t::const_iterator(*(o.vi_));
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
oi_ = new object_t::const_iterator(*(o.oi_));
}
Expand Down Expand Up @@ -1657,11 +1657,11 @@ bool json::const_iterator::operator==(const json::const_iterator& o) const

if (object_ != nullptr)
{
if (object_->type_ == value_type::array)
if (object_->type_ == json::value_type::array)
{
return (vi_ == o.vi_);
}
if (object_->type_ == value_type::object)
if (object_->type_ == json::value_type::object)
{
return (oi_ == o.oi_);
}
Expand All @@ -1685,15 +1685,15 @@ json::const_iterator& json::const_iterator::operator++()

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
if (++(*vi_) == object_->value_.array->end())
{
object_ = nullptr;
}
break;
}
case (value_type::object):
case (json::value_type::object):
{
if (++(*oi_) == object_->value_.object->end())
{
Expand All @@ -1719,11 +1719,11 @@ const json& json::const_iterator::operator*() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return **vi_;
}
case (value_type::object):
case (json::value_type::object):
{
return (*oi_)->second;
}
Expand All @@ -1744,11 +1744,11 @@ const json* json::const_iterator::operator->() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return &(**vi_);
}
case (value_type::object):
case (json::value_type::object):
{
return &((*oi_)->second);
}
Expand All @@ -1761,7 +1761,7 @@ const json* json::const_iterator::operator->() const

std::string json::const_iterator::key() const
{
if (object_ != nullptr and object_->type_ == value_type::object)
if (object_ != nullptr and object_->type_ == json::value_type::object)
{
return (*oi_)->first;
}
Expand All @@ -1781,11 +1781,11 @@ const json& json::const_iterator::value() const

switch (object_->type_)
{
case (value_type::array):
case (json::value_type::array):
{
return **vi_;
}
case (value_type::object):
case (json::value_type::object):
{
return (*oi_)->second;
}
Expand Down
6 changes: 3 additions & 3 deletions src/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class json

public:
/// an iterator
class iterator
class iterator : public std::iterator<std::forward_iterator_tag, json>
{
friend class json;
friend class json::const_iterator;
Expand Down Expand Up @@ -356,15 +356,15 @@ class json
};

/// a const iterator
class const_iterator
class const_iterator : public std::iterator<std::forward_iterator_tag, const json>
{
friend class json;

public:
const_iterator() = default;
const_iterator(const json*);
const_iterator(const const_iterator&);
const_iterator(const iterator&);
const_iterator(const json::iterator&);
~const_iterator();

const_iterator& operator=(const_iterator);
Expand Down