| 1 |
#ifndef _SIMPLELINKED_LIST |
| 2 |
#define _SIMPLELINKED_LIST |
| 3 |
|
| 4 |
#include "protoDebug.h" |
| 5 |
|
| 6 |
/* |
| 7 |
* SimpleList.h |
| 8 |
* |
| 9 |
* Created by Ian Taylor on 17/07/2008. |
| 10 |
* |
| 11 |
* Simple List is a linked list that consists of ListItem objects. ListItemObjects can be |
| 12 |
* subclassed by any data object in order to add your own data to Simple list. Therefore, |
| 13 |
* ListItem is an interface that a class can inherit from to become a an item |
| 14 |
* in a SimpleList. |
| 15 |
* |
| 16 |
* SimpleList could implement lots of other linked list-type things, like inserting |
| 17 |
* but the implementation assumes that uses of simple list will be much like a |
| 18 |
* FIFO and elements are always inserted as a head, although it can be searched and |
| 19 |
* elements can be deleted from anywhere in the list. Incidentally, you can use |
| 20 |
* SimpleList list a FIFO by using getHead() to get the head item and then removing |
| 21 |
* that from the list if desired. |
| 22 |
*/ |
| 23 |
|
| 24 |
class ListItem { |
| 25 |
public: |
| 26 |
ListItem(); |
| 27 |
|
| 28 |
ListItem* getPrev() {return prev;} |
| 29 |
void setPrev(ListItem* broker) {prev = broker;} |
| 30 |
ListItem* getNext() {return next;} |
| 31 |
void setNext(ListItem* broker) {next = broker;} |
| 32 |
|
| 33 |
void setIdentifier(unsigned int ident) { identifier=ident; } |
| 34 |
void setAddress(unsigned int addr) { address=addr; } |
| 35 |
void setPort(unsigned int portno) { portnumber=portno; } |
| 36 |
|
| 37 |
unsigned int getIdentifier() { return identifier; } |
| 38 |
unsigned int getAddress() { return address; } |
| 39 |
unsigned int getPort() { return portnumber; } |
| 40 |
|
| 41 |
private: |
| 42 |
ListItem* prev; |
| 43 |
ListItem* next; |
| 44 |
unsigned int identifier; |
| 45 |
unsigned int portnumber; |
| 46 |
unsigned int address; |
| 47 |
}; |
| 48 |
|
| 49 |
class SimpleList { |
| 50 |
public: |
| 51 |
SimpleList(); |
| 52 |
~SimpleList(); |
| 53 |
|
| 54 |
ListItem *getHead() { return head; } |
| 55 |
ListItem *getTail() { return tail; } |
| 56 |
|
| 57 |
void prepend(ListItem *item); |
| 58 |
void remove(ListItem *item); |
| 59 |
|
| 60 |
void print(); |
| 61 |
|
| 62 |
/** Find list item by searching for list items with address and port number as specified **/ |
| 63 |
ListItem* findProxyByPortAndAddress(unsigned int address, unsigned int port); |
| 64 |
|
| 65 |
/** |
| 66 |
* Finds the Socket proxy by searching the IDs which |
| 67 |
* can be set and retrieved using the GetSocketPrioxyID and |
| 68 |
* GetSocketPrioxyID respectively. |
| 69 |
*/ |
| 70 |
ListItem* findProxyByIdentifier(unsigned int proxyID); |
| 71 |
|
| 72 |
protected: |
| 73 |
ListItem* head; |
| 74 |
ListItem* tail; |
| 75 |
}; // end class ProtoSimAgent::SocketProxy::List |
| 76 |
|
| 77 |
#endif |