00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _FL_PTR_LIST_H_
00023 #define _FL_PTR_LIST_H_
00024
00025 #include "Enumerations.h"
00026
00027 typedef void* Fl_Ptr_List_Item;
00028 typedef int (*Fl_Foreach_Function)(void *item, void *arg);
00029 typedef int (*Fl_Sort_Function)(const void *item1, const void *item2);
00030 typedef int (*Fl_Search_Function)(const void *key, const void *other);
00031
00037 class FL_API Fl_Ptr_List {
00038 public:
00039 Fl_Ptr_List();
00040 virtual ~Fl_Ptr_List();
00041
00042 virtual void clear();
00043
00044 void resize(unsigned newsize);
00045
00046 void auto_delete(bool val) { auto_delete_ = val; }
00047 bool auto_delete() { return auto_delete_; }
00048
00049
00050 void blocksize(int s) { blocksize_ = s; }
00051 int blocksize() { return blocksize_; }
00052
00053 bool empty() const { return size_==0; }
00054 unsigned count() const { return size_; }
00055 unsigned size() const { return size_; }
00056
00057 void append(void *item);
00058 void prepend(void *item);
00059
00060 void insert(unsigned pos, Fl_Ptr_List_Item item);
00061 void replace(unsigned pos, Fl_Ptr_List_Item item);
00062
00063 void remove(unsigned pos);
00064 bool remove(Fl_Ptr_List_Item ptr);
00065
00076 void sort(Fl_Sort_Function cmpfunc);
00077
00087 Fl_Ptr_List_Item search(Fl_Ptr_List_Item key, Fl_Search_Function cmpfunc);
00088
00100 Fl_Ptr_List_Item binary_search(Fl_Ptr_List_Item key, Fl_Search_Function cmpfunc);
00101
00106 int index_of(const Fl_Ptr_List_Item p) const;
00107
00108 Fl_Ptr_List_Item item(unsigned index) const;
00109 Fl_Ptr_List_Item& operator [] (unsigned ind) const { return items[ind]; }
00110
00111 Fl_Ptr_List_Item *data() const { return items; }
00112
00113
00114 Fl_Ptr_List& operator = (const Fl_Ptr_List &list);
00115 Fl_Ptr_List(const Fl_Ptr_List &list);
00116
00117
00118
00119 int for_each(Fl_Foreach_Function todo,void * arg);
00120 int for_each(Fl_Foreach_Function todo,void * arg) const;
00121
00122
00123 protected:
00124
00125 virtual void free_item(Fl_Ptr_List_Item item);
00126
00127 Fl_Ptr_List_Item *items;
00128 bool auto_delete_;
00129
00130 private:
00131 unsigned blocksize_;
00132 unsigned capacity_;
00133 unsigned size_;
00134 };
00135
00136 #endif