xref: /trunk/main/autodoc/source/ary/inc/store/s_base.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef ARY_STORE_S_BASE_HXX
29 #define ARY_STORE_S_BASE_HXX
30 
31 // USED SERVICES
32 #include <deque>
33 #include <cosv/tpl/tpltools.hxx>
34 
35 
36 
37 
38 namespace ary
39 {
40 namespace stg
41 {
42 
43 
44 /** The basic storage container of the repository.
45 
46     @collab Storage
47     Implements Storage. Not used elsewhere.
48 
49     @tpl ENTITY
50     The type of *it, where it is of type c_iter, has to be ENTITY * const.
51 */
52 template <class ENTITY>
53 class Base
54 {
55   public:
56     // LIFECYCLE
57     typedef std::deque< ENTITY* >               impl_type;
58     typedef typename impl_type::const_iterator  c_iter;
59 
60 
61     /** @param i_nrOfReservedItems
62         The number of actual items to reserve, including the item
63         at index [0] that is always empty and unused.
64     */
65                         Base(
66                             uintt               i_nrOfReservedItems );
67                         ~Base();
68 
69     // OPERATORS
70     ENTITY *            operator[](
71                             uintt               i_index ) const;
72     // OPERATIONS
73     uintt               Add_Entity(             /// @return the index of the new element.
74                             DYN ENTITY &        pass_newEntity );
75     DYN ENTITY *        Set_Entity(             /// @return the previous value.
76                             uintt               i_index,
77                             DYN ENTITY &        pass_newEntity );
78     // INQUIRY
79     uintt               Size() const;           /// Incl. reserved size.
80     uintt               ReservedSize() const;   /// Incl. zero for element at [0].
81 
82     c_iter              Begin() const;          /// @return location of index 1, because 0 is always empty.
83     c_iter              BeginUnreserved() const;
84     c_iter              End() const;
85 
86   private:
87     // DATA
88     impl_type               aData;
89     uintt                   nReservedSize;
90 };
91 
92 
93 
94 // IMPLEMENTATION
95 
96 template <class ENTITY>
97 Base<ENTITY>::Base(uintt i_nrOfReservedItems)
98     :   aData(i_nrOfReservedItems, 0),
99         nReservedSize(i_nrOfReservedItems)
100 {
101 }
102 
103 template <class ENTITY>
104 Base<ENTITY>::~Base()
105 {
106     csv::erase_container_of_heap_ptrs(aData);
107 }
108 
109 
110 template <class ENTITY>
111 ENTITY *
112 Base<ENTITY>::operator[](uintt i_index) const
113 {
114     if (i_index < aData.size())
115         return aData[i_index];
116     return 0;
117 }
118 
119 template <class ENTITY>
120 uintt
121 Base<ENTITY>::Add_Entity(DYN ENTITY & pass_newEntity)
122 {
123     aData.push_back(&pass_newEntity);
124     return aData.size() - 1;
125 }
126 
127 template <class ENTITY>
128 DYN ENTITY *
129 Base<ENTITY>::Set_Entity( uintt         i_index,
130                           DYN ENTITY &  pass_newEntity )
131 {
132     csv_assert(i_index != 0 AND i_index < aData.size());
133 
134     Dyn<ENTITY>
135         ret(aData[i_index]);
136     aData[i_index] = &pass_newEntity;
137     return ret.Release();
138 }
139 
140 template <class ENTITY>
141 uintt
142 Base<ENTITY>::Size() const
143 {
144     return aData.size();
145 }
146 
147 template <class ENTITY>
148 uintt
149 Base<ENTITY>::ReservedSize() const
150 {
151     return nReservedSize;
152 }
153 
154 template <class ENTITY>
155 typename Base<ENTITY>::c_iter
156 Base<ENTITY>::Begin() const
157 {
158     return aData.begin() + 1;
159 }
160 
161 template <class ENTITY>
162 typename Base<ENTITY>::c_iter
163 Base<ENTITY>::BeginUnreserved() const
164 {
165     return aData.begin() + nReservedSize;
166 }
167 
168 template <class ENTITY>
169 typename Base<ENTITY>::c_iter
170 Base<ENTITY>::End() const
171 {
172     return aData.end();
173 }
174 
175 
176 
177 
178 }   // namespace stg
179 }   // namespace ary
180 #endif
181