1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #ifndef SOLTOOLS_ST_LIST_HXX
30 #define SOLTOOLS_ST_LIST_HXX
37 class ST_List
/// Soltools-List.
40 typedef XX
* iterator
;
41 typedef const XX
* const_iterator
;
46 const ST_List
<XX
> & i_rList
);
47 virtual ~ST_List() { delete[] inhalt
; }
50 ST_List
<XX
> & operator=(
51 const ST_List
<XX
> & i_rList
);
53 const XX
& operator[](
62 { alloc(i_nSize
,true); }
66 { Insert((unsigned)(i_aPos
-begin()), elem_
); }
72 { Insert(size(),elem_
); }
75 { Remove((int)(i_aPos
-begin())); }
78 void pop_back() { Remove(size()-1); }
79 void erase_all() { while (size()) Remove(size()-1); }
82 const_iterator
begin() const { return &inhalt
[0]; }
83 const_iterator
end() const { return &inhalt
[len
]; }
85 const XX
& front() const { return elem(0); }
86 const XX
& back() const { return elem(len
-1); }
88 unsigned size() const { return len
; }
89 unsigned space() const { return allocated
; }
94 iterator
begin() { return &inhalt
[0]; }
95 iterator
end() { return &inhalt
[len
]; }
97 XX
& front() { return elem(0); }
98 XX
& back() { return elem(len
-1); }
109 { return inhalt
[n
]; }
112 { return inhalt
[n
]; }
122 class DynamicList
: public ST_List
< XY
* >
127 const DynamicList
<XY
> &
129 virtual ~DynamicList(); /// Deletes all member pointers
131 DynamicList
<XY
> & operator=(
132 const DynamicList
<XY
> &
145 ST_List
<XX
>::ST_List()
154 ST_List
<XX
>::ST_List( const ST_List
<XX
> & i_rList
)
159 alloc(i_rList
.size());
161 for ( const_iterator it
= i_rList
.begin();
171 ST_List
<XX
>::operator=( const ST_List
<XX
> & i_rList
)
173 for ( const_iterator it
= i_rList
.begin();
184 ST_List
<XX
>::Insert(unsigned pos
, const XX
& elem_
)
190 for ( unsigned p
= len
; p
> pos
; --p
)
192 inhalt
[p
] = inhalt
[p
-1];
201 ST_List
<XX
>::Remove(unsigned pos
)
206 for ( unsigned p
= pos
; p
< len
; ++p
)
208 inhalt
[p
] = inhalt
[p
+1];
216 ST_List
<XX
>::checkSize(unsigned newLength
)
218 // neuen Platzbedarf pruefen:
219 unsigned newSpace
= space();
220 if (newLength
>= newSpace
)
224 const unsigned nBorder
= 2000000000;
225 while(newLength
>= newSpace
)
227 if (newSpace
< nBorder
)
231 std::cerr
<< "List becomes too big" << std::endl
;
238 if (newSpace
!= space())
239 alloc(newSpace
,true);
244 ST_List
<XX
>::alloc( unsigned newSpace
,
247 XX
* pNew
= new XX
[newSpace
];
253 for (unsigned i
= 0; i
< len
; ++i
)
262 allocated
= newSpace
;
267 DynamicList
<XY
>::DynamicList()
272 DynamicList
<XY
>::DynamicList( const DynamicList
<XY
> & i_rList
)
273 : ST_List
< XY
* >(i_rList
)
275 for ( typename DynamicList
<XY
>::iterator it
= this->begin();
276 it
!= DynamicList
<XY
>::end();
279 // Copying the contents the pointers point at:
280 (*it
) = new XY( *(*it
) );
285 DynamicList
<XY
>::~DynamicList()
292 DynamicList
<XY
>::operator=( const DynamicList
<XY
> & i_rList
)
294 for ( typename DynamicList
<XY
>::const_iterator it
= i_rList
.begin();
298 this->push_back( new XY(*(*it
)) );
306 DynamicList
<XY
>::Insert(unsigned pos
, XY
* const & elem_
)
308 if ( pos
> this->len
)
311 this->checkSize(DynamicList
<XY
>::len
+2);
312 memmove( DynamicList
<XY
>::inhalt
+pos
+1, DynamicList
<XY
>::inhalt
+pos
, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );
313 this->inhalt
[pos
] = elem_
;
319 DynamicList
<XY
>::Remove( unsigned pos
)
321 if (!this->is_valid_index(pos
) )
324 delete DynamicList
<XY
>::inhalt
[pos
];
325 memmove(DynamicList
<XY
>::inhalt
+pos
, DynamicList
<XY
>::inhalt
+pos
+1, (DynamicList
<XY
>::len
-pos
) * sizeof(XY
*) );
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */