Skip to content

Commit b1bb460

Browse files
committed
iterator
1 parent 4bed964 commit b1bb460

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

include/json.hh

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @file json.hh
33
* @author Simone Ancona
44
* @brief A JSON parser for C++
5-
* @version 1.0
6-
* @date 2023-07-14
5+
* @version 1.1
6+
* @date 2023-07-15
77
*
88
* @copyright Copyright (c) 2023
99
*
@@ -193,6 +193,38 @@ namespace Jpp
193193
* @return std::string
194194
*/
195195
std::string to_string();
196+
197+
/**
198+
* @brief Begin iterator
199+
*
200+
* @return std::map<std::string, Json>::iterator
201+
* @since v1.1
202+
*/
203+
std::map<std::string, Json>::iterator begin();
204+
205+
/**
206+
* @brief End iterator
207+
*
208+
* @return std::map<std::string, Json>::iterator
209+
* @since v1.1
210+
*/
211+
std::map<std::string, Json>::iterator end();
212+
213+
/**
214+
* @brief Reverse begin iterator
215+
*
216+
* @return std::map<std::string, Json>::iterator
217+
* @since v1.1
218+
*/
219+
std::map<std::string, Json>::reverse_iterator rbegin();
220+
221+
/**
222+
* @brief Reverse end iterator
223+
*
224+
* @return std::map<std::string, Json>::iterator
225+
* @since v1.1
226+
*/
227+
std::map<std::string, Json>::reverse_iterator rend();
196228
};
197229

198230
void trim_string(std::string &);

src/json.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @file json.cc
33
* @author Simone Ancona
44
* @brief
5-
* @version 1.0
6-
* @date 2023-07-14
5+
* @version 1.1
6+
* @date 2023-07-15
77
*
88
* @copyright Copyright (c) 2023
99
*
@@ -152,6 +152,26 @@ Jpp::Json &Jpp::Json::operator=(int num)
152152
return *this;
153153
}
154154

155+
std::map<std::string, Jpp::Json>::iterator Jpp::Json::begin()
156+
{
157+
return children.begin();
158+
}
159+
160+
std::map<std::string, Jpp::Json>::iterator Jpp::Json::end()
161+
{
162+
return children.end();
163+
}
164+
165+
std::map<std::string, Jpp::Json>::reverse_iterator Jpp::Json::rbegin()
166+
{
167+
return children.rbegin();
168+
}
169+
170+
std::map<std::string, Jpp::Json>::reverse_iterator Jpp::Json::rend()
171+
{
172+
return children.rend();
173+
}
174+
155175
void Jpp::Json::parse(std::string json_string)
156176
{
157177
trim_string(json_string);

0 commit comments

Comments
 (0)