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: st_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 SOLTOOLS_ST_LIST_HXX
32 #define SOLTOOLS_ST_LIST_HXX
39 class ST_List
/// Soltools-List.
42 typedef XX
* iterator
;
43 typedef const XX
* const_iterator
;
48 const ST_List
<XX
> & i_rList
);
49 virtual ~ST_List() { }
52 ST_List
<XX
> & operator=(
53 const ST_List
<XX
> & i_rList
);
55 const XX
& operator[](
64 { alloc(i_nSize
,true); }
68 { Insert(i_aPos
-begin(), elem_
); }
74 { Insert(size(),elem_
); }
77 { Remove(i_aPos
-begin()); }
80 void pop_back() { Remove(size()-1); }
81 void erase_all() { while (size()) Remove(size()-1); }
84 const_iterator
begin() const { return &inhalt
[0]; }
85 const_iterator
end() const { return &inhalt
[len
]; }
87 const XX
& front() const { return elem(0); }
88 const XX
& back() const { return elem(len
-1); }
90 unsigned size() const { return len
; }
91 unsigned space() const { return allocated
; }
96 iterator
begin() { return &inhalt
[0]; }
97 iterator
end() { return &inhalt
[len
]; }
99 XX
& front() { return elem(0); }
100 XX
& back() { return elem(len
-1); }
111 { return inhalt
[n
]; }
114 { return inhalt
[n
]; }
124 class DynamicList
: public ST_List
< XY
* >
129 const DynamicList
<XY
> &
131 virtual ~DynamicList(); /// Deletes all member pointers
133 DynamicList
<XY
> & operator=(
134 const DynamicList
<XY
> &
147 ST_List
<XX
>::ST_List()
156 ST_List
<XX
>::ST_List( const ST_List
<XX
> & i_rList
)
161 alloc(i_rList
.size());
163 for ( const_iterator it
= i_rList
.begin();
173 ST_List
<XX
>::operator=( const ST_List
<XX
> & i_rList
)
175 for ( const_iterator it
= i_rList
.begin();
186 ST_List
<XX
>::Insert(unsigned pos
, const XX
& elem_
)
192 for ( unsigned p
= len
; p
> pos
; --p
)
194 inhalt
[p
] = inhalt
[p
-1];
203 ST_List
<XX
>::Remove(unsigned pos
)
208 for ( unsigned p
= pos
; p
< len
; ++p
)
210 inhalt
[p
] = inhalt
[p
+1];
218 ST_List
<XX
>::checkSize(unsigned newLength
)
220 // neuen Platzbedarf pruefen:
221 unsigned newSpace
= space();
222 if (newLength
>= newSpace
)
226 const unsigned nBorder
= 2000000000;
227 while(newLength
>= newSpace
)
229 if (newSpace
< nBorder
)
233 std::cerr
<< "List becomes too big" << std::endl
;
240 if (newSpace
!= space())
241 alloc(newSpace
,true);
246 ST_List
<XX
>::alloc( unsigned newSpace
,
249 XX
* pNew
= new XX
[newSpace
];
255 for (unsigned i
= 0; i
< len
; ++i
)
264 allocated
= newSpace
;
269 DynamicList
<XY
>::DynamicList()
274 DynamicList
<XY
>::DynamicList( const DynamicList
<XY
> & i_rList
)
275 : ST_List
< XY
* >(i_rList
)
277 for ( typename DynamicList
<XY
>::iterator it
= this->begin();
278 it
!= DynamicList
<XY
>::end();
281 // Copying the contents the pointers point at:
282 (*it
) = new XY( *(*it
) );
287 DynamicList
<XY
>::~DynamicList()
294 DynamicList
<XY
>::operator=( const DynamicList
<XY
> & i_rList
)
296 for ( typename DynamicList
<XY
>::const_iterator it
= i_rList
.begin();
300 push_back( new XY(*(*it
)) );
308 DynamicList
<XY
>::Insert(unsigned pos
, XY
* const & elem_
)
310 if ( pos
> this->len
)
313 checkSize(DynamicList
<XY
>::len
+2);
314 memmove( DynamicList
<XY
>::inhalt
+pos
+1, DynamicList
<XY
>::inhalt
+pos
, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );
315 this->inhalt
[pos
] = elem_
;
321 DynamicList
<XY
>::Remove( unsigned pos
)
323 if (!this->is_valid_index(pos
) )
326 delete DynamicList
<XY
>::inhalt
[pos
];
327 memmove(DynamicList
<XY
>::inhalt
+pos
, DynamicList
<XY
>::inhalt
+pos
+1, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );