summaryrefslogtreecommitdiffstats
path: root/lanbrowsing/lisa/stringlist.cpp
blob: 3bf82f9c17eb1d6479dd073f5ba2a7966764525a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "simplelist.h"

template <class T>
SimpleList<T>::SimpleList()
   :m_list(0)
   ,m_current(0)
   ,m_last(0)
   ,m_size(0)
{};

template <class T>
SimpleList<T>::~SimpleList()
{
   clear();
};

template <class T>
void SimpleList<T>::append(const T& text)
{
   if (m_list==0)
   {
      m_list=new TemplNode<T>(text);
      m_last=m_list;
   }
   else
   {
      m_last->m_next=new TemplNode<T>(text);
      m_last=m_last->m_next;
   };
   m_size++;
};

template <class T>
void SimpleList<T>::removeFirst()
{
   if (m_list==0) return;
   TemplNode<T> *first=m_list;
   m_list=m_list->m_next;
   m_size--;
   if (m_list==0)
      m_last=0;
   m_current=0;
   delete first;
};

template <class T>
void SimpleList<T>::clear()
{
   while (m_list!=0)
      removeFirst();
   m_current=0;
   m_last=0;
   m_list=0;
   m_size=0;
};

template <class T>
void SimpleList<T>::remove(T* item)
{
   if (item==0) return;
   TemplNode<T>* pre(0);
   for (T* tmp=first(); tmp!=0; tmp=next())
   {
      if (tmp==item)
      {
         if (m_current==m_list)
         {
            removeFirst();
            return;
         }
         else
         {
            TemplNode<T> *succ=m_current->m_next;
            if (m_current==m_last)
               m_last=pre;
            delete m_current;
            pre->m_next=succ;
            m_size--;
            m_current=0;
            
         };
      };
      pre=m_current;
   };
   
};

template <class T>
T* SimpleList<T>::first()
{
   m_current=m_list;
   if (m_list==0)
      return 0;
   return &m_current->m_item;
};

template <class T>
T* SimpleList<T>::next()
{
   if (m_current==0) return 0;
   m_current=m_current->m_next;
   if (m_current==0) return 0;
   return &m_current->m_item;
};

template <class T>
int SimpleList<T>::size()
{
   return m_size;
}