Skip to content

Commit

Permalink
doc: document object iterators (#1090)
Browse files Browse the repository at this point in the history
Signed-off-by: Darshan Sen <darshan.sen@postman.com>
  • Loading branch information
RaisinTen committed Oct 25, 2021
1 parent 04b26a9 commit 0dfa89f
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions doc/object.md
Expand Up @@ -288,6 +288,34 @@ Napi::Value Napi::Object::operator[] (uint32_t index) const;

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

### begin()

```cpp
Napi::Object::iterator Napi::Object::begin() const;
```

Returns a constant iterator to the beginning of the object.

```cpp
Napi::Object::iterator Napi::Object::begin();
```

Returns a non constant iterator to the beginning of the object.

### end()

```cpp
Napi::Object::iterator Napi::Object::end() const;
```

Returns a constant iterator to the end of the object.

```cpp
Napi::Object::iterator Napi::Object::end();
```

Returns a non constant iterator to the end of the object.

## Iterator

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

In constant iterators, the iterated values are immutable.

#### operator++()

```cpp
inline Napi::Object::const_iterator& Napi::Object::const_iterator::operator++();
```

Moves the iterator one step forward.

#### operator==

```cpp
inline bool Napi::Object::const_iterator::operator==(const Napi::Object::const_iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at the same index.

#### operator!=

```cpp
inline bool Napi::Object::const_iterator::operator!=(const Napi::Object::const_iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at different indices.

#### operator*()

```cpp
inline const std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::const_iterator::operator*() const;
```

Returns the currently iterated key and value.

#### Example
```cpp
Value Sum(const CallbackInfo& info) {
Object object = info[0].As<Object>();
Expand All @@ -317,6 +380,41 @@ Value Sum(const CallbackInfo& info) {
In non constant iterators, the iterated values are mutable.
#### operator++()
```cpp
inline Napi::Object::iterator& Napi::Object::iterator::operator++();
```

Moves the iterator one step forward.

#### operator==

```cpp
inline bool Napi::Object::iterator::operator==(const Napi::Object::iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at the same index.

#### operator!=

```cpp
inline bool Napi::Object::iterator::operator!=(const Napi::Object::iterator& other) const;
```
- `[in] other`: Another iterator to compare the current iterator to.

Returns whether both iterators are at different indices.

#### operator*()

```cpp
inline std::pair<Napi::Value, Napi::Object::PropertyLValue<Napi::Value>> Napi::Object::iterator::operator*();
```

Returns the currently iterated key and value.

#### Example
```cpp
void Increment(const CallbackInfo& info) {
Env env = info.Env();
Expand Down

0 comments on commit 0dfa89f

Please sign in to comment.