1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: list.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __LISTEN_123456__
32 #define __LISTEN_123456__
42 typedef XX
* iterator
;
43 typedef const XX
* const_iterator
;
47 virtual ~List() { delete [] inhalt
; }
50 const XX
& operator[](
59 { alloc(i_nSize
,true); }
65 { insert(size(),elem_
); }
69 void pop_back() { remove(size()-1); }
70 void erase_all() { while (size()) remove(size()-1); }
73 const XX
& front() const { return elem(0); }
74 const XX
& back() const { return elem(len
-1); }
76 unsigned size() const { return len
; }
77 unsigned space() const { return allocated
; }
82 XX
& front() { return elem(0); }
83 XX
& back() { return elem(len
-1); }
104 // forbidden functions
105 List(const List
<XX
> & L
);
106 List
<XX
> & operator=(
112 class DynamicList
: public List
<XY
*>
115 virtual ~DynamicList();
139 List
<XX
>::insert(unsigned pos
, const XX
& elem_
)
145 for ( unsigned p
= len
; p
> pos
; --p
)
147 inhalt
[p
] = inhalt
[p
-1];
156 List
<XX
>::remove(unsigned pos
)
161 for ( unsigned p
= pos
; p
< len
; ++p
)
163 inhalt
[p
] = inhalt
[p
+1];
171 List
<XX
>::checkSize(unsigned newLength
)
173 // neuen Platzbedarf pruefen:
174 unsigned newSpace
= space();
175 if (newLength
> newSpace
)
179 const unsigned nBorder
= 65536 / 2;
180 while(newLength
> newSpace
)
182 if (newSpace
< nBorder
)
186 std::cerr
<< "List becomes too big" << std::endl
;
193 if (newSpace
!= space())
194 alloc(newSpace
,true);
199 List
<XX
>::alloc( unsigned newSpace
,
202 XX
* pNew
= new XX
[newSpace
];
208 for (unsigned i
= 0; i
< len
; ++i
)
217 allocated
= newSpace
;
222 DynamicList
<XY
>::~DynamicList()
229 DynamicList
<XY
>::insert(unsigned pos
, XY
* const & elem_
)
231 if ( pos
> this->len
)
234 checkSize(this->len
+2);
235 memmove(this->inhalt
[pos
+1], this->inhalt
[pos
], (this->len
-pos
) * sizeof(XY
*) );
236 this->inhalt
[pos
] = elem_
;
242 DynamicList
<XY
>::remove( unsigned pos
)
244 if (!this->is_valid_index(pos
) )
247 delete this->inhalt
[pos
];
248 memmove(this->inhalt
[pos
], this->inhalt
[pos
+1], (this->len
-pos
) * sizeof(XY
*) );