Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Ptr_List.h

00001 /*
00002  * $Id: Fl_Ptr_List.h,v 1.11 2003/04/12 15:02:19 laza2000 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
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     //Default is 0, means auto-calculated
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     // Copy
00114     Fl_Ptr_List& operator = (const Fl_Ptr_List &list);
00115     Fl_Ptr_List(const Fl_Ptr_List &list);
00116 
00117     // Call 'todo' for every item til 'todo' returns 'true',
00118     // then return item index or (-1) if 'todo' never return 'true'.
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     // Free item in list e.g.: delete (SomeClass*)(item);
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

Generated on Thu Jul 31 15:33:44 2003 for eFLTK by doxygen1.2.15