Main Page   Modules   Class Hierarchy   Data Structures   File List   Data Fields   Globals   Related Pages  

oscl_linked_list.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00003 
00004 //                     O S C L _ L I N K E D _ L I S T
00005 
00006 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
00007 
00018 #ifndef OSCL_LINKED_LIST_H_INCLUDED
00019 #define OSCL_LINKED_LIST_H_INCLUDED
00020 
00021 #ifndef OSCL_BASE_H_INCLUDED
00022 #include "oscl_base.h"
00023 #endif
00024 #ifndef OSCL_DEFALLOC_H_INCLUDED
00025 #include "oscl_defalloc.h"
00026 #endif
00027 #ifndef OSCL_OPAQUE_TYPE_H_INCLUDED
00028 #include "oscl_opaque_type.h"
00029 #endif
00030 #ifndef OSCL_ASSERT_H_INCLUDED
00031 #include "oscl_assert.h"
00032 #endif
00033 
00034 
00043 template <class LLClass, class Alloc> class Oscl_Linked_List;
00047 template <class LLClass> class LinkedListElement
00048 {
00049 
00050     public:
00051         LinkedListElement(LLClass in_data)
00052         {
00053             data = in_data;
00054             next = NULL;
00055         };
00056         //  ~LinkedListElement() {};
00057 
00058 //  friend class Oscl_Linked_List<LLClass>;
00059         LinkedListElement<LLClass>* next;
00060         LLClass data;
00061 
00062     private:
00063 };
00064 
00069 class Oscl_Linked_List_Base
00070 {
00071     protected:
00072         virtual ~Oscl_Linked_List_Base()
00073         {}
00074 
00075         OSCL_IMPORT_REF void construct(Oscl_Opaque_Type_Alloc_LL* op);
00076 
00077         OSCL_IMPORT_REF void destroy();
00078 
00085         OSCL_IMPORT_REF int32 get_first(OsclAny* ele);
00086 
00093         OSCL_IMPORT_REF int32 get_next(OsclAny* ele);
00094 
00100         OSCL_IMPORT_REF int32 check_list();
00101 
00108         OSCL_IMPORT_REF int32 add_element(const OsclAny* new_element);
00109 
00117         OSCL_IMPORT_REF int32 add_to_front(const OsclAny* new_element);
00118 
00126         OSCL_IMPORT_REF int32 insert_element(const OsclAny* new_element, int index);
00127 
00133         OSCL_IMPORT_REF int32 get_element(int32 index, OsclAny* element);
00134 
00140         OSCL_IMPORT_REF int32 remove_element(const OsclAny* data_to_remove);
00141 
00148         OSCL_IMPORT_REF int32 get_index(const OsclAny* data);
00149 
00155         OSCL_IMPORT_REF int32 remove_element(const int32 index_to_remove);
00156 
00162         OSCL_IMPORT_REF int32 move_to_end(const OsclAny* data_to_move);
00163 
00169         OSCL_IMPORT_REF int32 move_to_front(const OsclAny* data_to_move);
00170 
00171         OsclAny *head;
00172         OsclAny *tail;
00173         OsclAny *iterator;
00174         int32 num_elements;
00175         uint32 sizeof_T;
00176 
00177     private:
00178         Oscl_Opaque_Type_Alloc_LL* pOpaqueType;
00179 };
00180 
00184 template <class LLClass, class Alloc> class Oscl_Linked_List
00185         : public Oscl_Linked_List_Base
00186         , public Oscl_Opaque_Type_Alloc_LL
00187 {
00188 
00189     public:
00193         Oscl_Linked_List(): Oscl_Linked_List_Base(), Oscl_Opaque_Type_Alloc_LL()
00194         {
00195             sizeof_T = sizeof(LinkedListElement<LLClass>);
00196             Oscl_Linked_List_Base::construct(this);
00197         }
00198 
00202         ~Oscl_Linked_List()
00203         {
00204             Oscl_Linked_List_Base::destroy();
00205         }
00206 
00207         void clear()
00208         {
00209             Oscl_Linked_List_Base::destroy();
00210         }
00211 
00212         int32 dequeue_element(LLClass & element)
00213         {
00214             get_element(0, element);
00215             return remove_element((int32) 0);
00216         }
00217         // get_first() and get_next() together provide iterator function
00218 
00225         int32 get_first(LLClass & ele)
00226         {
00227             return Oscl_Linked_List_Base::get_first(&ele);
00228         }
00229 
00236         int32 get_next(LLClass & ele)
00237         {
00238             return Oscl_Linked_List_Base::get_next(&ele);
00239         }
00240 
00246         int32 check_list()
00247         {
00248             return Oscl_Linked_List_Base::check_list();
00249         }
00250 
00255         int32 get_num_elements()
00256         {
00257             return num_elements;
00258         }
00259 
00266         int32 add_element(LLClass& new_element)
00267         {
00268             return Oscl_Linked_List_Base::add_element(&new_element);
00269         }
00270 
00278         int32 add_to_front(const LLClass& new_element)
00279         {
00280             return Oscl_Linked_List_Base::add_to_front(&new_element);
00281         }
00289         int32 insert_element(const LLClass& new_element, int index)
00290         {
00291             return Oscl_Linked_List_Base::insert_element(&new_element, index);
00292         }
00293 
00299         int32 get_element(int32 index, LLClass& element)
00300         {
00301             return Oscl_Linked_List_Base::get_element(index, &element);
00302         }
00303 
00309         int32 remove_element(const LLClass& data_to_remove)
00310         {
00311             return Oscl_Linked_List_Base::remove_element(&data_to_remove);
00312         }
00313 
00320         int32 get_index(const LLClass& data)
00321         {
00322             return Oscl_Linked_List_Base::get_index(&data);
00323         }
00324 
00330         int32 remove_element(const int32 index_to_remove)
00331         {
00332             return Oscl_Linked_List_Base::remove_element(index_to_remove);
00333         }
00334 
00340         int32 move_to_end(const LLClass& data_to_move)
00341         {
00342             return Oscl_Linked_List_Base::move_to_end(&data_to_move);
00343         }
00344 
00350         int32 move_to_front(const LLClass& data_to_move)
00351         {
00352             return Oscl_Linked_List_Base::move_to_front(&data_to_move);
00353         }
00354 
00355 
00356     private:
00357 
00358         //from Oscl_Opaque_Type_Alloc_LL
00359         void construct(OsclAny* p, const OsclAny* init_val)
00360         {
00361             OSCL_ASSERT(init_val);
00362             OSCL_ASSERT(p);
00363             new(p) LinkedListElement<LLClass>(*(LLClass*)init_val);
00364         }
00365 
00366         //this typedef is needed to avoid compile errors ADS 1.2 compiler.
00367         typedef LinkedListElement<LLClass>* p_elem_type;
00368 
00369         //from Oscl_Opaque_Type_Alloc_LL
00370         void destroy(OsclAny* p)
00371         {
00372             OSCL_ASSERT(p);
00373             ((p_elem_type)p)->~LinkedListElement<LLClass>();
00374         }
00375 
00376         //from Oscl_Opaque_Type_Alloc_LL
00377         OsclAny* allocate(const uint32 size)
00378         {
00379             return alloc.ALLOCATE(size);
00380         }
00381 
00382         //from Oscl_Opaque_Type_Alloc_LL
00383         void deallocate(OsclAny* p)
00384         {
00385             alloc.deallocate(p);
00386         }
00387 
00388         //from Oscl_Opaque_Type_Alloc_LL
00389         OsclAny* get_next(const OsclAny* elem)const
00390         {
00391             return ((LinkedListElement<LLClass>*)elem)->next;
00392         }
00393 
00394         //from Oscl_Opaque_Type_Alloc_LL
00395         void set_next(OsclAny* elem, const OsclAny* nextelem)
00396         {
00397             OSCL_ASSERT(elem);
00398             ((LinkedListElement<LLClass>*)elem)->next = (LinkedListElement<LLClass>*)nextelem;
00399         }
00400 
00401         //from Oscl_Opaque_Type_Alloc_LL
00402         void get_data(OsclAny*elem, OsclAny*data_val)
00403         {
00404             OSCL_ASSERT(elem);
00405             OSCL_ASSERT(data_val);
00406             *((LLClass*)data_val) = ((LinkedListElement<LLClass>*)elem)->data ;
00407         }
00408 
00409         //from Oscl_Opaque_Type_Alloc_LL
00410         bool compare_data(const OsclAny*elem, const OsclAny*data_val)const
00411         {
00412             OSCL_ASSERT(elem);
00413             OSCL_ASSERT(data_val);
00414             return ((LinkedListElement<LLClass>*)elem)->data == *((LLClass*)data_val);
00415         }
00416 
00417         Alloc alloc;
00418 
00419 };
00420 
00426 template <class LLClass, class Alloc, class TheLock> class Oscl_MTLinked_List
00427 {
00428 
00429     public:
00433         Oscl_MTLinked_List() {};
00434 
00438         ~Oscl_MTLinked_List() {};
00439 
00440         int32 dequeue_element(LLClass & element)
00441         {
00442             int32 status;
00443             TheLock Mylock;
00444             Mylock.Lock();
00445             status = the_list.dequeue_element(element);
00446             Mylock.Unlock();
00447             return status;
00448         }
00449 
00457         int32 add_element(LLClass& new_element)
00458         {
00459             int32 status;
00460             TheLock Mylock;
00461             Mylock.Lock();
00462             status = the_list.add_element(new_element);
00463             Mylock.Unlock();
00464             return status;
00465         }
00466 
00474         int32 add_to_front(LLClass& new_element)
00475         {
00476             int32 status;
00477             TheLock Mylock;
00478             Mylock.Lock();
00479             status = the_list.add_to_front(new_element);
00480             Mylock.Unlock();
00481             return status;
00482         }
00483 
00490         uint32 get_element(int32 index, LLClass& element)
00491         {
00492 
00493             int32 status;
00494             TheLock Mylock;
00495             Mylock.Lock();
00496             status = the_list.get_element(index, element);
00497             Mylock.Unlock();
00498             return status;
00499         }
00500 
00506         int32 remove_element(const LLClass& data_to_remove)
00507         {
00508             int32 status;
00509             TheLock Mylock;
00510             Mylock.Lock();
00511             status = the_list.remove_element(data_to_remove);
00512             Mylock.Unlock();
00513             return status;
00514         }
00515 
00522         int32 get_index(const LLClass& data)
00523         {
00524             int32 status;
00525             TheLock Mylock;
00526             Mylock.Lock();
00527             status = the_list.get_index(data);
00528             Mylock.Unlock();
00529             return status;
00530         }
00531 
00537         int32 remove_element(const int32 index_to_remove)
00538         {
00539             int32 status;
00540             TheLock Mylock;
00541             Mylock.Lock();
00542             status = the_list.remove_element(index_to_remove);
00543             Mylock.Unlock();
00544             return status;
00545         }
00546 
00552         int32 move_to_end(const LLClass& data_to_move)
00553         {
00554             int32 status;
00555             TheLock Mylock;
00556             Mylock.Lock();
00557             status = the_list.move_to_end(data_to_move);
00558             Mylock.Unlock();
00559             return status;
00560         }
00561 
00567         int32 move_to_front(const LLClass& data_to_move)
00568         {
00569             int32 status;
00570             TheLock Mylock;
00571             Mylock.Lock();
00572             status = the_list.move_to_front(data_to_move);
00573             Mylock.Unlock();
00574             return status;
00575         }
00576 
00577     protected:
00578         Oscl_Linked_List<LLClass, Alloc> the_list;
00579 //    PVMutex mutex;
00580 
00581 };
00582 
00583 
00587 #endif  // __LINKED_LIST_H
00588 

OSCL API
Posting Version: CORE_8.000.1.1_RC4