STL container 대신 tizen collection들을 사용해야 할 경우가 있어 정리함.
: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.apireference/namespaceTizen_1_1Base_1_1Collection.html
: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.appprogramming/html/guide/base/collection_namespace.htm
일반적인 std::array, std::list를 대체할 Tizen의 자료구조이며 아래 나오는 제약사항을 숙지하고 구현해야 함. stl을 사용하다 tizen api들을 사용할 경우 다소 생소한 부분들이 있음.
ArrayList and LinkedList
: https://developer.tizen.org/dev-guide/2.2.1/org.tizen.native.appprogramming/html/guide/base/arraylist_linkedlist.htm
제약사항
- They override the IList methods to implement their own adding, removing, inserting, and writing mechanisms.
- Indexes in them are zero-based.
- They can be traversed using a Tizen::Base::Collection::IEnumerator interface.
- They allow duplication of values, but do not accept null references.
- They do not copy the values, but just keep the pointers to the values.
- The RemoveAll() method is called internally by a destructor. Depending on the element deleter, the RemoveAll() method destroys all elements. You do not have to call the RemoveAll() method to deallocate all elements at the end.
위 제약사항에서 유의해야 하는 것은
IEnumerator interface를 사용해서 탐색하며
value가 아닌 pointer를 저장해야 하며
destructor에서 저장된 primitive value들을 알아서 deallocate함.
자세한 사용 방법은 위 링크에 포함된 예제를 보면 OK..
#include <FBase.h> using namespace Tizen::Base; using namespace Tizen::Base::Collection; void MyClass::ArrayListTSample(void) { ArrayListT< int > list; list.Construct(); int int1 = 1; int int2 = 2; int int3 = 3; int int4 = 4; list.Add(int1); // 1 list.Add(int2); // 1,2 list.Add(int3); // 1,2,3 int temp; for (int i = 0; i < list.GetCount(); i++) { list.GetAt(i, temp); } list.InsertAt(int4, 1); // 1,4,2,3 ComparerT< int >* pIntComparer = new ComparerT<int>(); list.Sort(*pIntComparer); // 1,2,3,4 delete pIntComparer; list.Remove(int3); // 1,2,4 list.RemoveAt(0); // 2,4 // Uses an enumerator to access elements in the list IEnumeratorT< int >* pEnum = list.GetEnumeratorN(); while (pEnum->MoveNext() == E_SUCCESS) { pEnum->GetCurrent(temp); } delete pEnum; }
위는 일반적인 primitive 자료형을 위한 자료구조라고 보면 될 듯하며 user-defined object를 처리하기 위해서는 다음 template base data structure를 사용 해야한다.
Tizen::Base::Collection::ArrayListT<Type>
: https://developer.tizen.org/dev-guide/2.2.0/org.tizen.native.apireference/classTizen_1_1Base_1_1Collection_1_1ArrayListT.html
Tizen::Base::Collection::LinkedListT<Type>
: https://developer.tizen.org/dev-guide/2.2.0/org.tizen.native.apireference/classTizen_1_1Base_1_1Collection_1_1LinkedListT.html
The Tizen::Base::Collection::ArrayListT<Type> and Tizen::Base::Collection::LinkedListT<Type> classes represent a template-based collection of objects that can be individually accessed by index, and behave similarly as the object-based class versions. These classes allow duplicate elements. Several methods in these classes need operators of the type assignment (=), equivalent (==), and not equivalent (!=). Furthermore, to use the Sort() method, relational operators (<, >) or a comparer must be provided.
* HashMapT 의 key를 String으로 할 경우 컴파일 에러가 발생한다. 예제대로 int를 key값으로 사용하라.
댓글 없음:
댓글 쓰기