diff --git a/einaxx/include/einaxx/List.h b/einaxx/include/einaxx/List.h index cafd50d..45f88ae 100644 --- a/einaxx/include/einaxx/List.h +++ b/einaxx/include/einaxx/List.h @@ -103,9 +103,25 @@ EAPI void eina_iterator_foreach (Eina_Iterator *iterator, Iterator createIterator (); //Eina_Accessor *eina_list_accessor_new(const Eina_List *list); + + /*! + * @brief C object wrapper factory method. + * + * For internal usage only! This return a new allocated Object that holds + * the wrapped Eeina_List variable. With a delete on this object the wrapped + * C type won't be freed. + * + * @param o The C to to be wrapped. + * @return The wrapped C++ type. + */ + static List *wrap (Eina_List *el); private: + List (Eina_List *el); + Eina_List *mList; + + bool mFree; }; /** Implementation **/ @@ -143,14 +159,28 @@ bool List::Iterator::next (T *data) template List::List () : - mList (NULL) + mList (NULL), + mFree (true) +{ +} + +template +List::List (Eina_List *list) : + mList (list), + mFree (false) { } template List::~List () { - /*Eina_List *list = eina_list_free (mList); + Eina_List *list = NULL; + + if (mFree) + { + list = eina_list_free (mList); + } + if (!list) { // good case: do nothing @@ -158,7 +188,7 @@ List::~List () else { // TODO: error handling - }*/ + } } template @@ -280,6 +310,12 @@ typename List::Iterator List::createIterator () return i; } +template +List *List::wrap (Eina_List *list) +{ + return new List (list); +} + } // end namespace Einaxx #endif // EINAXX_LIST_H