I worked on a few projects for Bada OS 2.0 half a year or more ago, and I’d wanted to share some of my solutions since then. Finally, the blog is up and running, so I do that until it’s too late.
One of the weirdest classes in Bada is LinkedListT<>. It’s very easy to get a number of memory leaks unless you know a few subtleties. Whereas LinkedList has Remove, RemoveAll, and other remove methods with bool deallocate = false parameter, LinkedListT’s remove methods don’t have it. Therefore, you can’t easily clear such a list.
Then, destructing a LinkedListT doesn’t automatically deallocate any object in the container. You have to remove all of them manually (remember, there is no RemoveAll method that deallocates all the objects).
And last, to get an item from the container, you have to declare a variable on the stack, and use GetAt() to “fill” the object. Doing this a lot makes this typing rather boring.
To solve all of the mentioned issues, I created a child class with additional behavior. Here it is:
/* * FixedLinkedListT.h */#ifndef FIXEDLINKEDLISTT_H_#define FIXEDLINKEDLISTT_H_#include<FBase.h>// A class that extends Osp::Base::Collection::LinkedListT and implements// the missing methods from Osp::Base::Collection::LinkedList:// void RemoveAll(bool deallocate);// Type GetItemAt(int index);// Use when Type is a pointer onlytemplate<classType>classFixedLinkedListT:publicOsp::Base::Collection::LinkedListT<Type>{public:boolremoveAllOnDeallocating;FixedLinkedListT():removeAllOnDeallocating(true){}virtual~FixedLinkedListT(){if(removeAllOnDeallocating){this->RemoveAll(true);}}voidRemoveAll(booldeallocate){for(inti=this->GetCount()-1;i>=0;--i){Typeobject;this->GetAt(i,object);deleteobject;this->RemoveAt(i);}}TypeGetItemAt(intindex){Typeobject;this->GetAt(index,object);returnobject;}};#endif /* FIXEDLINKEDLISTT_H_ */