3DCoat Core API
The 3DCoat API documentation.
Loading...
Searching...
No Matches
Arrays.cpp

 * Very basic arrays operations

// Very basic arrays operations
#include <CoreAPI.h>
//If you need the release build at full speed please change the Debug below to Release
//@config: Debug
//this function just displays the array using the coat::dialog
void show(coat::list<int>& list) {
coat::str res;
for (auto& a : list){
res << a << " ";
}
coat::dialog().text(res).ok().show();
}
// The main() will be called as soon as user will run the script
EXPORT
int main(){
coat::list<int> array; // declare array of int-s
array.Add(1); // add the single integer value 1
array1.Add(2, 10); // add 10 elements, each element is 2
array1.Insert(3, 5); // insert the value 5 at position 3
array1.RemoveAt(5, 2); // remove 2 elements at the position 5
show(array1);
int x[3] = { 7,8,9 };
array1.AddRange(x, 3); // add 3 elements from the regular array
array.AddRange(array1); // add the whole array
array.Reverse(); // reverse the order of elements
show(array);
int pos_of_2 = array1.find(2); // returns the position of the value 2, returns -1 if not found
for (int x : array) { // the for-cycle. In this case you may not erase array elements within the loop
//... do something ...
}
for (int i = 0; i < array.Count(); i++) { // indexed for-loop, in this case you can remove elements within the cycle
if (array[i] == 5) { // we remove element if it is exual to 5
array.Remove(i--);
}
}
show(array);
array.Clear(); // set zero count of elements
array = array1; // you can assign one array to another one
array.forEach(
[&](int x) {
// do something with each element
});
array1.Fill(7); // fill with the same value
show(array1);
return 0;
}
the rich dialog. You may customize it, show your custom parameters and custom buttons.
Definition CoreAPI.h:3821
dialog & ok()
add Ok button
int show()
Show the dialog. This is usually the last command in the chain.
dialog & text(const char *id)
pass the header text of the dialog
comms::cList< X > list
the array template, see cList
Definition CoreAPI.h:70
comms::cStr str
the string that is compatible with the 3DCoat engine, see the cStr
Definition CoreAPI.h:67