30.06.2011, 10:32
Just did these defines for enumerating through vector easily. Vector must only contain entries of same data type.
Example usage:
Prints
0: Hello, World!
1: Hello to you too.
How-to use:
Index of current entry is stored in variable named "_X_it" where X is vector id specified in vectorid (if you specified a variable there, X will be variable name, not the content). So its not suggested to use this. Better to use your own index variable like in example.
These defines can be put into cstl.inc file for easy usage.
Код:
#define vector_enum_cell<%0,%1> for (new _%0_it = 0, %1 = 0 ; (_%0_it < vector_size(%0) && (%1 = vector_get(%0,_%0_it))) ; _%0_it++) #define vector_enum_float<%0,%1> for (new _%0_it = 0, Float:%1 = 0 ; (_%0_it < vector_size(%0) && (%1 = vector_get_float(%0,_%0_it))) ; _%0_it++) #define vector_enum_arr<%0,%1,%2> for (new _%0_it = 0, %1[%2] ; (_%0_it < vector_size(%0) && (vector_get_arr(%0,_%0_it,%1,%2))) ; _%0_it++)
Код:
new vector_id = 0, index = 0; vector_push_back_arr(vector_id, "Hello, World!"); vector_push_back_arr(vector_id, "Hello to you too."); vector_enum_arr<vector_id, curStr, 128> { printf("index %i: %s", index, curStr); index++; } vector_clear(vector_id);
0: Hello, World!
1: Hello to you too.
How-to use:
Код:
vector_enum_cell<vectorid, currentcell> Specify vector to enumerate in vectorid. Specify variable name to store current cell. vector_enum_float<vectorid, currentfloat> Specify vector to enumerate in vectorid. Specify variable name to store current float. vector_enum_arr<vectorid, currentarr, length> Specify vector to enumerate in vectorid. Specify variable name to store current array. Specify length for currentarr (if vector contains array larger than it, its truncated)
These defines can be put into cstl.inc file for easy usage.