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: s_base.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 ARY_STORE_S_BASE_HXX
32 #define ARY_STORE_S_BASE_HXX
36 #include <cosv/tpl/tpltools.hxx>
47 /** The basic storage container of the repository.
50 Implements Storage. Not used elsewhere.
53 The type of *it, where it is of type c_iter, has to be ENTITY * const.
55 template <class ENTITY
>
60 typedef std::deque
< ENTITY
* > impl_type
;
61 typedef typename
impl_type::const_iterator c_iter
;
64 /** @param i_nrOfReservedItems
65 The number of actual items to reserve, including the item
66 at index [0] that is always empty and unused.
69 uintt i_nrOfReservedItems
);
74 uintt i_index
) const;
76 uintt
Add_Entity( /// @return the index of the new element.
77 DYN ENTITY
& pass_newEntity
);
78 DYN ENTITY
* Set_Entity( /// @return the previous value.
80 DYN ENTITY
& pass_newEntity
);
82 uintt
Size() const; /// Incl. reserved size.
83 uintt
ReservedSize() const; /// Incl. zero for element at [0].
85 c_iter
Begin() const; /// @return location of index 1, because 0 is always empty.
86 c_iter
BeginUnreserved() const;
99 template <class ENTITY
>
100 Base
<ENTITY
>::Base(uintt i_nrOfReservedItems
)
101 : aData(i_nrOfReservedItems
, 0),
102 nReservedSize(i_nrOfReservedItems
)
106 template <class ENTITY
>
107 Base
<ENTITY
>::~Base()
109 csv::erase_container_of_heap_ptrs(aData
);
113 template <class ENTITY
>
115 Base
<ENTITY
>::operator[](uintt i_index
) const
117 if (i_index
< aData
.size())
118 return aData
[i_index
];
122 template <class ENTITY
>
124 Base
<ENTITY
>::Add_Entity(DYN ENTITY
& pass_newEntity
)
126 aData
.push_back(&pass_newEntity
);
127 return aData
.size() - 1;
130 template <class ENTITY
>
132 Base
<ENTITY
>::Set_Entity( uintt i_index
,
133 DYN ENTITY
& pass_newEntity
)
135 csv_assert(i_index
!= 0 AND i_index
< aData
.size());
139 aData
[i_index
] = &pass_newEntity
;
140 return ret
.Release();
143 template <class ENTITY
>
145 Base
<ENTITY
>::Size() const
150 template <class ENTITY
>
152 Base
<ENTITY
>::ReservedSize() const
154 return nReservedSize
;
157 template <class ENTITY
>
158 typename Base
<ENTITY
>::c_iter
159 Base
<ENTITY
>::Begin() const
161 return aData
.begin() + 1;
164 template <class ENTITY
>
165 typename Base
<ENTITY
>::c_iter
166 Base
<ENTITY
>::BeginUnreserved() const
168 return aData
.begin() + nReservedSize
;
171 template <class ENTITY
>
172 typename Base
<ENTITY
>::c_iter
173 Base
<ENTITY
>::End() const