46 logical :: valid = .false.
48 class(*),
pointer :: item
67 integer,
public :: status = 0
70 integer :: usedslots = 0
73 integer :: allocatedslots = 0
79 type(
listitem),
dimension(:),
allocatable :: listdata
149 class(
list),
intent(in) :: me
163 class(
list),
intent(inout) :: me
165 class(*),
intent(in) :: newitem
171 if (me%UsedSlots == me%AllocatedSlots)
then
173 call me%create_newslots(me%NewSlotsToAllocate)
174 if (me%status /= 0)
return
178 call me%ListData(me%UsedSlots+1)%add_listitem(newitem)
179 me%UsedSlots = me%UsedSlots + 1
189 class(
list),
intent(inout) :: me
190 class(*),
allocatable :: item
193 allocate(item, source=me%Listdata(me%UsedSlots)%item, stat=me%status)
196 call me%ListData(me%UsedSlots)%del_listitem()
197 me%UsedSlots = me%UsedSlots - 1
205 class(
list),
intent(inout),
target :: me
207 integer,
intent(in) :: index
209 class(*),
pointer :: item
213 if (index < 1 .OR. index > me%Size())
return
215 if (me%Listdata(index)%isvalid_listitem()) item=>me%Listdata(index)%item
224 class(
list),
intent(inout) :: me
225 class(*),
allocatable :: item
226 class(*),
pointer :: ptr
228 allocate(item, source=ptr)
236 class(
list),
intent(inout) :: me
237 class(*),
allocatable :: item
238 class(*),
pointer :: ptr
239 ptr => me%Item(me%Size())
240 allocate(item, source=ptr)
247 class(
list),
intent(inout) :: me
248 integer,
intent(in) :: pos
249 class(*),
intent(in) :: NewItem
254 if (pos < 1 .OR. pos > (me%Size()+1))
then
260 if (me%Size() == me%AllocatedSlots)
then
262 call me%create_newslots(me%NewSlotsToAllocate)
263 if (me%status /= 0)
return
267 do ctr = me%Size(), pos, -1
268 call me%ListData(ctr+1)%add_listitem(me%ListData(ctr)%item)
272 call me%ListData(pos)%add_listitem(newitem)
273 me%UsedSlots = me%UsedSlots + 1
282 class(
list),
intent(inout) :: me
283 integer,
intent(in) :: pos
288 if (pos < 1 .OR. pos > me%Size())
then
294 call me%ListData(pos)%del_listitem()
297 do ctr = pos, me%Size()-1
298 call me%ListData(ctr)%add_listitem(me%ListData(ctr+1)%item)
300 me%UsedSlots = me%UsedSlots - 1
310 class(
list),
intent(inout) :: me
312 integer,
intent(in) :: NumSlots
314 type(
listitem),
dimension(:),
allocatable :: tmp
318 allocate(tmp(me%AllocatedSlots+numslots), stat=me%status)
320 if (me%status == 0)
then
322 if (me%UsedSlots /= 0)
then
324 tmp(1:me%AllocatedSlots) = me%ListData
327 call move_alloc(from=tmp, to=me%ListData)
328 me%AllocatedSlots = me%AllocatedSlots + numslots
338 class(
list),
intent(out) :: lhs
339 class(
list),
intent(in) :: rhs
346 allocate(lhs%ListData(rhs%AllocatedSlots))
349 do ctr = 1, rhs%AllocatedSlots
350 call lhs%ListData(ctr)%add_listitem(rhs%ListData(ctr)%item)
354 lhs%status = rhs%status
355 lhs%NewSlotsToAllocate = rhs%NewSlotsToAllocate
356 lhs%UsedSlots = rhs%UsedSlots
357 lhs%AllocatedSlots = rhs%AllocatedSlots
368 class(
list),
intent(inout) :: me
372 do ctr = 1, me%Size()
373 call me%ListData(ctr)%del_listitem()
383 class(
list),
intent(inout) :: me
386 type(
listitem),
dimension(:),
allocatable :: tmp
388 if (me%Size() < me%AllocatedSlots)
then
390 do ctr = me%Size()+1, me%AllocatedSlots
391 call me%ListData(ctr)%del_listitem()
393 me%AllocatedSlots = me%Size()
396 if (me%AllocatedSlots < 1)
then
397 if (
allocated(me%ListData))
deallocate(me%ListData, stat=me%status)
400 allocate(tmp(1:me%AllocatedSlots), stat=me%status)
401 if (me%status == 0)
then
402 tmp = me%ListData(1:me%AllocatedSlots)
403 call move_alloc(from=tmp, to=me%ListData)
414 type(
list),
intent(inout) :: me
419 do ctr = 1, me%Size()
420 call me%ListData(ctr)%del_listitem()
430 class(
listitem),
intent(inout) :: me
432 class(*),
intent(in) :: item
436 allocate(me%item, source=item, stat=status)
437 if (status == 0)
then
441 if (
associated(me%item))
deallocate(me%item)
450 class(
listitem),
intent(inout) :: me
452 if (
associated(me%item))
deallocate(me%item)