CopernicaMarketingSoftware/PHP-CPP — pull request #25 by valmat (2014-03-11 10:37:03+00:00)
Title: Native iterate through arrays and objects of type Value

Iterate over arrays and objects of type Value

I propose to consider the iteration of arrays and objects without the use of additional containers.

A few examples:

```c
void loopValue(Php::Parameters ¶ms)
{
std::cout << "\nArray/Object contains " << params[0].size() << " items" << std::endl;

// Preferred variant
// Value::iterator& Value::end() is called only once
for(auto &i: params[0]) {
std::cout << "\n["<< i.ind() << "]:["<< i.key() << "]=" << i.value() << "\t | \t" << i.typestr();
}

// Possible variant
// Value::iterator& Value::end() is called with each iteration
for (auto it=params[0].begin(); it!=params[0].end(); it++) {
std::cout << "\n["<< it->ind() << "]:["<< it->key() << "]=" << it->value() << "\t | \t" << it->typestr();
}

// Recursive iterations
Php::Value v;
for(auto &i: params[0]) {
v = i.value();
std::cout << std::endl << "["<< i.ind() << "]:["<< i.key() << "]=" << v << "\t | \t" << i.typestr();
for(auto &j: v) {
std::cout << std::endl << "\t["<< j.ind() << "]:["<< j.key() << "]="<< j.value();
}
}
std::cout << std::endl;
}
```

Iteration method
```c
for(auto &i: params[0]) {...}
```
is more convenient and less expensive, but if someone can conveniently otherwise, he can iterate and in this way:
```c
for (auto it=params[0].begin(); it!=params[0].end(); it++) { {...}
```
or this:
```c
for (Value::iterator it=params[0].begin(); it!=params[0].end(); ++it) { {...}
```

A few words about using.
Value::iterator supports the following methods:
```c
Value::iterator it;

/**
* Retrieve a string key of element of the array
* the same as *it.key();
*
* @return std::string
*/
it->key();

/**
* Retrieve a integer key (index) of element of the array
* the same as *it.ind();
*
* @return unsigned long
*/
it->ind();

/**
* key type is string?
* true ‒ string, false ‒ integer
* the same as *it.isstr();
*
* @return bool
*/
it->isstr();

/**
* debug function
* the same as *it.typestr();
* if key type is string, return "str", else return "num"
*
* @return const char *
*/
it->typestry();
```

Now this new feature allows just iterate through in one direction.
If necessary, it possible deepen and enhance functionality.
At this point, this iterator is not a iterator is compatible with STL C++11 and does not support the corresponding algorithms.

Why iteration in a way better than iterating through `Value::mapValue()`:

1	Firstly preserved the original order of elements in the array.
2	This method is faster, as the passage is provided once, while using `Value::mapValue()`, we first fill `std::map result`, and then intereresati filled container.
In addition, there is an economy to initialize the container `std::map` and operations over them.
3	It is very convenient.