Rudiments
/home/dmuse/src/rudiments/include/rudiments/linkedlist.h
00001 // Copyright (c) 2003 David Muse
00002 // See the COPYING file for more information.
00003 
00004 #ifndef RUDIMENTS_LINKEDLIST_H
00005 #define RUDIMENTS_LINKEDLIST_H
00006 
00007 #include <rudiments/private/linkedlistincludes.h>
00008 
00009 #ifdef RUDIMENTS_NAMESPACE
00010 namespace rudiments {
00011 #endif
00012 
00014 template <class datatype>
00015 class linkedlistnode {
00016         public:
00018                 linkedlistnode();
00019 
00023                 virtual ~linkedlistnode();
00024 
00026                 void            setData(datatype data);
00027 
00029                 datatype        getData() const;
00030 
00034                 int32_t compare(datatype data) const;
00035 
00037                 void    setPrevious(linkedlistnode<datatype> *previous);
00038 
00040                 void    setNext(linkedlistnode<datatype> *next);
00041 
00043                 linkedlistnode<datatype>        *getPrevious();
00044 
00046                 linkedlistnode<datatype>        *getNext();
00047 
00049                 void    print() const;
00050 
00051         #include <rudiments/private/linkedlistnode.h>
00052 };
00053 
00060 template < class datatype, class linkedlistnodetype=linkedlistnode<datatype> >
00061 class linkedlist {
00062         public:
00064                 linkedlist();
00065 
00069                 virtual ~linkedlist();
00070 
00073                 void    append(datatype data);
00074 
00077                 void    append(linkedlistnodetype *node);
00078 
00083                 bool    insert(uint64_t index, datatype data);
00084 
00089                 bool    insert(uint64_t index, linkedlistnodetype *node);
00090 
00094                 bool    removeByIndex(uint64_t index);
00095 
00099                 bool    removeByData(datatype data);
00100 
00104                 bool    removeAllByData(datatype data);
00105 
00109                 bool    removeNode(linkedlistnodetype *node);
00110 
00115                 bool    setDataByIndex(uint64_t index, datatype data);
00116 
00121                 bool    getDataByIndex(uint64_t index, datatype *data);
00122 
00124                 uint64_t        getLength() const;
00125 
00127                 linkedlistnodetype      *getFirstNode();
00128 
00130                 linkedlistnodetype      *getLastNode();
00131 
00133                 linkedlistnodetype      *getNodeByIndex(uint64_t index);
00134 
00137                 linkedlistnodetype      *getNodeByData(datatype data);
00138 
00141                 linkedlistnodetype      *getNodeByData(
00142                                                 linkedlistnodetype *startnode,
00143                                                 datatype data);
00144 
00148                 void    clear();
00149 
00151                 void    print() const;
00152 
00153         #include <rudiments/private/linkedlist.h>
00154 };
00155 
00156 typedef linkedlistnode< char * >                stringlistnode;
00157 typedef linkedlist< char *, stringlistnode >    stringlist;
00158 
00159 #ifdef RUDIMENTS_NAMESPACE
00160 }
00161 #endif
00162 
00163 #include <rudiments/private/linkedlistnodeinlines.h>
00164 #include <rudiments/private/linkedlistinlines.h>
00165 
00166 #endif