On 02/09/2014 at 04:38, xxxxxxxx wrote:
For what my non-programmers knowledge is worth, I use std library objects quite a bit in my plugins, if for the reason just because they're standard. I've particularly used the std::vector a bit, and haven't had any problems with them.
Not sure what your programming skill level is so parden my igrnorance if you already know, but an example of using a std::vector container could be something like:
// need the vector header file somewhere in your code
#include <vector>
// create a vector container
std::vector< LONG > MyLongContainer;
// the container does not come 'sized' automatically,
// you will need to do this somewhere in your code
MyLongContainer.resize(5);
// fill container indexed values (note that index values start at 0)
MyLongContainer[0] = 27; // random number
MyLongContainer[1] = 65; // random number
MyLongContainer[2] = 196; // random number
MyLongContainer[3] = 6; // random number
MyLongContainer[4] = 13; // random number
// print container values
for(int i = 0; i <= MyLongContainer.size()-1;)
{
GePrint("MyLongContainer[" + LongToString(i)+ "] = " + LongToString(MyLongContainer[i]));
i++;
}
That will probably work straight as it is in a function if you want to try it. Here's also an example that takes the std::vector a little further:
\\ lets create a container array made of a std:pair object to our
\\ vector container. The pair object is made up of two variable
\\ types that you can assign (hence pair) - so it's a container of pairs
std::vector< std::pair< LONG,String > > MyLongContainer;
MyLongContainer.resize(5);
MyLongContainer[0].first = 27; // pair number
MyLongContainer[0].second = "Pair 1"; // pair name
MyLongContainer[1].first = 65; // pair number
MyLongContainer[1].second = "Pair 2; // pair name
MyLongContainer[2].first = 196; // pair number
MyLongContainer[2].second = "Pair 3"; // pair name
MyLongContainer[3].first = 6; // pair number
MyLongContainer[3].second = "Pair 4; // pair name
MyLongContainer[4].first = 13; // pair number
MyLongContainer[4].second = "Pair 5"; // pair name
for(int i = 0; i <= MyLongContainer.size()-1;)
{
GePrint("MyLongContainer[" + LongToString(i)+ "] = " + LongToString(MyLongContainer[i].first) + ": " + MyLongContainer[i].second);
i++;
}
Barring any mistakes in the code, the above should also work as is. Hope that is of some help. Cheers,
WP.