00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifdef HAVE_CONFIG_H
00018 #include <dtn-config.h>
00019 #endif
00020 #include "ProphetLinkList.h"
00021
00022 namespace dtn
00023 {
00024
00025 LinkRef
00026 ProphetLinkList::NULL_LINK("ProphetLinkList");
00027
00028 ProphetLinkList::ProphetLinkList()
00029 {}
00030
00031 ProphetLinkList::~ProphetLinkList()
00032 {
00033 clear();
00034 }
00035
00036 void
00037 ProphetLinkList::add(const LinkRef& l)
00038 {
00039 iterator i;
00040 if (! find(l->remote_eid().c_str(),i))
00041 {
00042 ProphetLink* lr = new ProphetLink(l);
00043 list_.insert(i,lr);
00044 }
00045 }
00046
00047 void
00048 ProphetLinkList::del(const LinkRef& l)
00049 {
00050 iterator i;
00051 if (find(l->remote_eid().c_str(),i))
00052 {
00053 delete *i;
00054 list_.erase(i);
00055 }
00056 }
00057
00058 const prophet::Link*
00059 ProphetLinkList::find(const char* remote_eid) const
00060 {
00061 iterator i;
00062 ProphetLinkList* me = const_cast<ProphetLinkList*>(this);
00063 if (me != NULL && me->find(remote_eid,i))
00064 return (*i);
00065 return NULL;
00066 }
00067
00068 const LinkRef&
00069 ProphetLinkList::find_ref(const prophet::Link* link) const
00070 {
00071 if (link == NULL) return NULL_LINK;
00072 return find_ref(link->remote_eid());
00073 }
00074
00075 const LinkRef&
00076 ProphetLinkList::find_ref(const char* remote_eid) const
00077 {
00078 iterator i;
00079 ProphetLinkList* me = const_cast<ProphetLinkList*>(this);
00080 if (me != NULL && me->find(remote_eid,i))
00081 return (*i)->ref();
00082 return NULL_LINK;
00083 }
00084
00085 void
00086 ProphetLinkList::clear()
00087 {
00088 while (!list_.empty())
00089 {
00090 delete list_.front();
00091 list_.pop_front();
00092 }
00093 }
00094
00095 bool
00096 ProphetLinkList::find(const char* remote_eid, iterator& i)
00097 {
00098 i = list_.begin();
00099 while (i != list_.end() &&
00100 (strncmp((*i)->remote_eid(),remote_eid,strlen((*i)->remote_eid())) < 0) )
00101 i++;
00102 if (i == list_.end()) return false;
00103 return strncmp((*i)->remote_eid(),remote_eid,strlen((*i)->remote_eid())) == 0;
00104 }
00105
00106 };