for (int i=1; i < num/3 + 1; ++i) {
Line* lp = new Line{"Line" + std::to_string(i),
Coord{i,i}, Coord{100*i,100*i}};
coll.push_back(lp);
Circle* cp = new Circle{"Circle" + std::to_string(i),
Coord{10*i,10*i}, i};
coll.push_back(cp);
Polygon* pp = new Polygon{"Polygon" + std::to_string(i),
{Coord{i,i}, Coord{i, -i},
Coord{-i, -i}, Coord{-i, i}}};
coll.push_back(pp);
}
return coll;
}
void cleanColl(GOColl& coll)
{ // call delete for corresponding new:
for (auto& geoobjptr : coll) {
delete geoobjptr; // avoid any memory leak
geoobjptr = nullptr; // avoid using element before removed
} // remove all elements in the vector:
coll.clear();
}
long iterate(const GOColl& coll)
{
long numEmpty = 0;
for (auto go : coll) {
if (go->getName().empty()) {
++numEmpty;
}
}
return numEmpty;
}
long iterateDown(const GOColl& coll)
{
long sumPoints = 0;
for (auto go : coll) {
if (auto p = dynamic_cast<const Polygon*>(go); p != nullptr) {
sumPoints += p->numPoints();
}
}
return sumPoints;
}
void shuffleAndMod(GOColl& coll)
{
std::default_random_engine dre;
std::shuffle(coll.begin(), coll.end(), // range
dre); // random number generator