merge the formfield patch from ooo-build
[ooovba.git] / autodoc / source / ary / inc / store / s_base.hxx
blob9ab863a3104413d01cf5959ea21cc0771a7be58c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: s_base.hxx,v $
10 * $Revision: 1.3 $
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
34 // USED SERVICES
35 #include <deque>
36 #include <cosv/tpl/tpltools.hxx>
41 namespace ary
43 namespace stg
47 /** The basic storage container of the repository.
49 @collab Storage
50 Implements Storage. Not used elsewhere.
52 @tpl ENTITY
53 The type of *it, where it is of type c_iter, has to be ENTITY * const.
55 template <class ENTITY>
56 class Base
58 public:
59 // LIFECYCLE
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.
68 Base(
69 uintt i_nrOfReservedItems );
70 ~Base();
72 // OPERATORS
73 ENTITY * operator[](
74 uintt i_index ) const;
75 // OPERATIONS
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.
79 uintt i_index,
80 DYN ENTITY & pass_newEntity );
81 // INQUIRY
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;
87 c_iter End() const;
89 private:
90 // DATA
91 impl_type aData;
92 uintt nReservedSize;
97 // IMPLEMENTATION
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>
114 ENTITY *
115 Base<ENTITY>::operator[](uintt i_index) const
117 if (i_index < aData.size())
118 return aData[i_index];
119 return 0;
122 template <class ENTITY>
123 uintt
124 Base<ENTITY>::Add_Entity(DYN ENTITY & pass_newEntity)
126 aData.push_back(&pass_newEntity);
127 return aData.size() - 1;
130 template <class ENTITY>
131 DYN 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());
137 Dyn<ENTITY>
138 ret(aData[i_index]);
139 aData[i_index] = &pass_newEntity;
140 return ret.Release();
143 template <class ENTITY>
144 uintt
145 Base<ENTITY>::Size() const
147 return aData.size();
150 template <class ENTITY>
151 uintt
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
175 return aData.end();
181 } // namespace stg
182 } // namespace ary
183 #endif