Skip to content

Commit 0dfa89f

Browse files
authored
doc: document object iterators (#1090)
Signed-off-by: Darshan Sen <[email protected]>
1 parent 04b26a9 commit 0dfa89f

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

doc/object.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,34 @@ Napi::Value Napi::Object::operator[] (uint32_t index) const;
288288

289289
Returns an indexed property or array element as a [`Napi::Value`](value.md).
290290

291+
### begin()
292+
293+
```cpp
294+
Napi::Object::iterator Napi::Object::begin() const;
295+
```
296+
297+
Returns a constant iterator to the beginning of the object.
298+
299+
```cpp
300+
Napi::Object::iterator Napi::Object::begin();
301+
```
302+
303+
Returns a non constant iterator to the beginning of the object.
304+
305+
### end()
306+
307+
```cpp
308+
Napi::Object::iterator Napi::Object::end() const;
309+
```
310+
311+
Returns a constant iterator to the end of the object.
312+
313+
```cpp
314+
Napi::Object::iterator Napi::Object::end();
315+
```
316+
317+
Returns a non constant iterator to the end of the object.
318+
291319
## Iterator
292320

293321
Iterators expose an `std::pair<...>`, where the `first` property is a
@@ -300,6 +328,41 @@ exceptions are enabled (by defining `NAPI_CPP_EXCEPTIONS` during the build).
300328

301329
In constant iterators, the iterated values are immutable.
302330

331+
#### operator++()
332+
333+
```cpp
334+
inline Napi::Object::const_iterator& Napi::Object::const_iterator::operator++();
335+
```
336+
337+
Moves the iterator one step forward.
338+
339+
#### operator==
340+
341+
```cpp
342+
inline bool Napi::Object::const_iterator::operator==(const Napi::Object::const_iterator& other) const;
343+
```
344+
- `[in] other`: Another iterator to compare the current iterator to.
345+
346+
Returns whether both iterators are at the same index.
347+
348+
#### operator!=
349+
350+
```cpp
351+
inline bool Napi::Object::const_iterator::operator!=(const Napi::Object::const_iterator& other) const;
352+
```
353+
- `[in] other`: Another iterator to compare the current iterator to.
354+
355+
Returns whether both iterators are at different indices.
356+
357+
#### operator*()
358+
359+
```cpp
360+
inline const std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::const_iterator::operator*() const;
361+
```
362+
363+
Returns the currently iterated key and value.
364+
365+
#### Example
303366
```cpp
304367
Value Sum(const CallbackInfo& info) {
305368
Object object = info[0].As<Object>();
@@ -317,6 +380,41 @@ Value Sum(const CallbackInfo& info) {
317380
318381
In non constant iterators, the iterated values are mutable.
319382
383+
#### operator++()
384+
385+
```cpp
386+
inline Napi::Object::iterator& Napi::Object::iterator::operator++();
387+
```
388+
389+
Moves the iterator one step forward.
390+
391+
#### operator==
392+
393+
```cpp
394+
inline bool Napi::Object::iterator::operator==(const Napi::Object::iterator& other) const;
395+
```
396+
- `[in] other`: Another iterator to compare the current iterator to.
397+
398+
Returns whether both iterators are at the same index.
399+
400+
#### operator!=
401+
402+
```cpp
403+
inline bool Napi::Object::iterator::operator!=(const Napi::Object::iterator& other) const;
404+
```
405+
- `[in] other`: Another iterator to compare the current iterator to.
406+
407+
Returns whether both iterators are at different indices.
408+
409+
#### operator*()
410+
411+
```cpp
412+
inline std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::iterator::operator*();
413+
```
414+
415+
Returns the currently iterated key and value.
416+
417+
#### Example
320418
```cpp
321419
void Increment(const CallbackInfo& info) {
322420
Env env = info.Env();

0 commit comments

Comments
 (0)