1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef SOLTOOLS_ST_LIST_HXX
29 #define SOLTOOLS_ST_LIST_HXX
36 class ST_List
/// Soltools-List.
39 typedef XX
* iterator
;
40 typedef const XX
* const_iterator
;
45 const ST_List
<XX
> & i_rList
);
46 virtual ~ST_List() { }
49 ST_List
<XX
> & operator=(
50 const ST_List
<XX
> & i_rList
);
52 const XX
& operator[](
61 { alloc(i_nSize
,true); }
65 { Insert(i_aPos
-begin(), elem_
); }
71 { Insert(size(),elem_
); }
74 { Remove(i_aPos
-begin()); }
77 void pop_back() { Remove(size()-1); }
78 void erase_all() { while (size()) Remove(size()-1); }
81 const_iterator
begin() const { return &inhalt
[0]; }
82 const_iterator
end() const { return &inhalt
[len
]; }
84 const XX
& front() const { return elem(0); }
85 const XX
& back() const { return elem(len
-1); }
87 unsigned size() const { return len
; }
88 unsigned space() const { return allocated
; }
93 iterator
begin() { return &inhalt
[0]; }
94 iterator
end() { return &inhalt
[len
]; }
96 XX
& front() { return elem(0); }
97 XX
& back() { return elem(len
-1); }
108 { return inhalt
[n
]; }
111 { return inhalt
[n
]; }
121 class DynamicList
: public ST_List
< XY
* >
126 const DynamicList
<XY
> &
128 virtual ~DynamicList(); /// Deletes all member pointers
130 DynamicList
<XY
> & operator=(
131 const DynamicList
<XY
> &
144 ST_List
<XX
>::ST_List()
153 ST_List
<XX
>::ST_List( const ST_List
<XX
> & i_rList
)
158 alloc(i_rList
.size());
160 for ( const_iterator it
= i_rList
.begin();
170 ST_List
<XX
>::operator=( const ST_List
<XX
> & i_rList
)
172 for ( const_iterator it
= i_rList
.begin();
183 ST_List
<XX
>::Insert(unsigned pos
, const XX
& elem_
)
189 for ( unsigned p
= len
; p
> pos
; --p
)
191 inhalt
[p
] = inhalt
[p
-1];
200 ST_List
<XX
>::Remove(unsigned pos
)
205 for ( unsigned p
= pos
; p
< len
; ++p
)
207 inhalt
[p
] = inhalt
[p
+1];
215 ST_List
<XX
>::checkSize(unsigned newLength
)
217 // neuen Platzbedarf pruefen:
218 unsigned newSpace
= space();
219 if (newLength
>= newSpace
)
223 const unsigned nBorder
= 2000000000;
224 while(newLength
>= newSpace
)
226 if (newSpace
< nBorder
)
230 std::cerr
<< "List becomes too big" << std::endl
;
237 if (newSpace
!= space())
238 alloc(newSpace
,true);
243 ST_List
<XX
>::alloc( unsigned newSpace
,
246 XX
* pNew
= new XX
[newSpace
];
252 for (unsigned i
= 0; i
< len
; ++i
)
261 allocated
= newSpace
;
266 DynamicList
<XY
>::DynamicList()
271 DynamicList
<XY
>::DynamicList( const DynamicList
<XY
> & i_rList
)
272 : ST_List
< XY
* >(i_rList
)
274 for ( typename DynamicList
<XY
>::iterator it
= this->begin();
275 it
!= DynamicList
<XY
>::end();
278 // Copying the contents the pointers point at:
279 (*it
) = new XY( *(*it
) );
284 DynamicList
<XY
>::~DynamicList()
291 DynamicList
<XY
>::operator=( const DynamicList
<XY
> & i_rList
)
293 for ( typename DynamicList
<XY
>::const_iterator it
= i_rList
.begin();
297 push_back( new XY(*(*it
)) );
305 DynamicList
<XY
>::Insert(unsigned pos
, XY
* const & elem_
)
307 if ( pos
> this->len
)
310 checkSize(DynamicList
<XY
>::len
+2);
311 memmove( DynamicList
<XY
>::inhalt
+pos
+1, DynamicList
<XY
>::inhalt
+pos
, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );
312 this->inhalt
[pos
] = elem_
;
318 DynamicList
<XY
>::Remove( unsigned pos
)
320 if (!this->is_valid_index(pos
) )
323 delete DynamicList
<XY
>::inhalt
[pos
];
324 memmove(DynamicList
<XY
>::inhalt
+pos
, DynamicList
<XY
>::inhalt
+pos
+1, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );