2 * Amiga Generic Set - set of libraries and includes to ease sw development for all Amiga platforms
3 * Copyright (C) 2001-2011 Tomasz Wiszkowski Tomasz.Wiszkowski at gmail.com.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "LibrarySpool.h"
23 #include <libclass/exec.h>
24 #include <LibC/LibC.h>
26 using namespace GenNS
;
28 EList::EList(MinList
* pList
)
37 bExternalList
= false;
38 PrvList
= new MinList
;
39 PrvList
->mlh_Head
= (MinNode
*)&PrvList
->mlh_Tail
;
40 PrvList
->mlh_TailPred
= (MinNode
*)&PrvList
->mlh_Head
;
41 PrvList
->mlh_Tail
= 0;
47 if (false == bExternalList
)
57 void EList::Add(void* ApObject
)
59 ENode
*pNode
= new ENode
;
61 memset(pNode
, 0, sizeof(ENode
));
62 pNode
->ln_Data
= ApObject
;
64 Exec
->AddTail((List
*)PrvList
, (Node
*)pNode
);
65 if (false == bExternalList
)
69 void EList::AddFeatured(void* ApObject
, const char* ApName
, signed char AlPri
)
71 ENode
*pNode
= new ENode
;
73 memset(pNode
, 0, sizeof(ENode
));
74 pNode
->ln_Data
= ApObject
;
75 pNode
->ln_Pri
= AlPri
;
76 pNode
->ln_Name
= const_cast<char*>(ApName
);
78 Exec
->Enqueue((List
*)PrvList
, (Node
*)pNode
);
79 if (false == bExternalList
)
83 void EList::InsertAt(void* ApObject
, unsigned long APos
)
85 ENode
*pNode
= new ENode
;
86 pNode
->ln_Data
= ApObject
;
87 if (APos
>=GetCount())
89 Exec
->AddTail((List
*)PrvList
, (Node
*)pNode
);
93 Exec
->AddHead((List
*)PrvList
, (Node
*)pNode
);
97 Node
* pBefore
= (Node
*)PrvList
->mlh_Head
;
100 pBefore
= pBefore
->ln_Succ
;
102 Exec
->Insert((List
*)PrvList
, (Node
*)pNode
, pBefore
);
104 if (false == bExternalList
)
108 void EList::Rem(void* ApObject
)
110 ENode
*pNode
= (ENode
*)PrvList
->mlh_Head
;
111 while (pNode
->ln_Succ
)
113 ENode
*pNext
= (ENode
*)pNode
->ln_Succ
;
114 if (pNode
->ln_Data
== ApObject
)
116 Exec
->Remove((Node
*)pNode
);
117 if (false == bExternalList
)
125 void EList::Rem(unsigned long AItem
)
127 if (false == bExternalList
)
128 if (AItem
> Count
) return;
130 ENode
*pNode
= (ENode
*)PrvList
->mlh_Head
;
131 while (pNode
->ln_Succ
)
133 ENode
*pNext
= (ENode
*)pNode
->ln_Succ
;
136 Exec
->Remove((Node
*)pNode
);
137 if (false == bExternalList
)
147 void* EList::operator [] (unsigned long AItem
)
149 if (false == bExternalList
)
150 if (AItem
> Count
) return 0;
151 ENode
*pNode
= (ENode
*)PrvList
->mlh_Head
;
152 while (pNode
->ln_Succ
)
154 ENode
*pNext
= (ENode
*)pNode
->ln_Succ
;
157 return pNode
->ln_Data
;
165 unsigned long EList::GetCount()
167 if (false == bExternalList
)
170 ENode
*pNode
= (ENode
*)PrvList
->mlh_Head
;
173 while (pNode
->ln_Succ
)
175 pNode
= (ENode
*)pNode
->ln_Succ
;
181 void *EList::Get(unsigned long AItem
)
183 return (*this)[AItem
];
186 Node
* EList::GetNode(unsigned long AItem
)
188 if (false == bExternalList
)
189 if (AItem
> Count
) return 0;
190 ENode
*pNode
= (ENode
*)PrvList
->mlh_Head
;
191 while (pNode
->ln_Succ
)
193 ENode
*pNext
= (ENode
*)pNode
->ln_Succ
;
204 MinList
*EList::GetList()
211 bool bCopy
= bExternalList
;
212 bExternalList
= true;
214 bExternalList
= bCopy
;