Code: Select all
valgrind --leak-check=full --show-reachable=no --track-origins=yes ./play
Code: Select all
void map_test_01()
{
irr::core::map<s32, stringc*> items;
// ADD ITEMS
stringc *so = new stringc("Apples");
items.insert(33, so);
so = new stringc("Kiwi");
items.insert(37, so);
//items.set(31, new stringc("Bananas")); // replace / insert
//items[55] = new stringc("Ants");
/*
// DUMP
for(map<irr::s32,stringc*>::Iterator it=items.getIterator(); !it.atEnd(); it++)
{
std::cout << it->getKey() << " => " << (*it->getValue()).c_str() << std::endl;
}
std::cout << "" << std::endl;
// DUMP
//irr::core::map<s32, stringc*> items;
irr::core::map<s32, stringc*>::Iterator it;
for(it = items.getIterator(); !it.atEnd(); it++)
{
std::cout << it->getKey() << " => " << (*it->getValue()).c_str() << std::endl;
}
std::cout << "" << std::endl;
// FIND USING ITERATOR
//irr::core::map<s32, stringc*>::Iterator it = items.find(31);
it = items.find(55);
if (!it.atEnd())
{
//return (*it).getValue();
std::cout << "Found: " << it->getKey() << " => " << (*it->getValue()).c_str() << std::endl;
}
std::cout << "" << std::endl;
// FIND USING NODE
core::map<s32, stringc*>::Node* n = items.find(31);
if (n)
{
//indices.push_back(n->getValue());
std::cout << "Found: " << n->getKey() << " => " << (*n->getValue()).c_str() << std::endl;
}
*/
std::cout << "" << std::endl;
core::map<s32, stringc*>::ParentFirstIterator Iterator=items.getParentFirstIterator();
for(;!Iterator.atEnd();Iterator++)
{
core::map<s32, stringc*>::Node* n = Iterator.getNode(); // items.find(31);
//delete Iterator.getNode()->getValue();
//stringc *n = Iterator.getNode()->getValue();
delete n->getValue();
n->getValue() = NULL;
/*
stringc *ss = n->getValue();
delete ss;
ss = NULL;
*/
items.remove(n);
Iterator = items.getParentFirstIterator();
}
//items.clear();
std::cout << "" << std::endl;
}