Update ooo320-m1
[ooovba.git] / autodoc / inc / ary / sequentialids.hxx
blob4b3ce706df8efd289d8f90b13cf4115b4e314ec1
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: sequentialids.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_SEQUENTIALIDS_HXX
32 #define ARY_SEQUENTIALIDS_HXX
35 // USED SERVICES
36 // BASE CLASSES
37 // OTHER
38 #include <algorithm>
42 namespace ary
46 /** Implementation of a set of children to an entity in the Autodoc
47 repository. The children are in the sequence of addition.
49 template<class ID>
50 class SequentialIds
52 public:
53 typedef std::vector<ID> data_t;
54 typedef typename data_t::const_iterator const_iterator;
56 // LIFECYCLE
57 explicit SequentialIds(
58 std::size_t i_reserve = 0 );
59 ~SequentialIds();
61 // OPERATIONS
62 void Add(
63 const ID & i_child );
64 // INQUIRY
65 const_iterator Begin() const;
66 const_iterator End() const;
67 std::size_t Size() const;
69 template <class IDENTIFY>
70 ID Find(
71 IDENTIFY i_find ) const;
72 template <class IDENTIFY>
73 // Workaround for Solaris8 compiler: return type has to match alphabetically
74 typename std::vector<ID>::const_iterator
75 Search(
76 IDENTIFY i_find ) const;
77 private:
78 // DATA
79 data_t aData;
88 // IMPLEMENTATION
90 template <class ID>
91 SequentialIds<ID>::SequentialIds(std::size_t i_reserve)
92 : aData()
94 if (i_reserve > 0)
95 aData.reserve(i_reserve);
98 template <class ID>
99 SequentialIds<ID>::~SequentialIds()
103 template <class ID>
104 inline void
105 SequentialIds<ID>::Add(const ID & i_child)
107 aData.push_back(i_child);
110 template <class ID>
111 inline typename SequentialIds<ID>::const_iterator
112 SequentialIds<ID>::Begin() const
114 return aData.begin();
117 template <class ID>
118 inline typename SequentialIds<ID>::const_iterator
119 SequentialIds<ID>::End() const
121 return aData.end();
124 template <class ID>
125 inline std::size_t
126 SequentialIds<ID>::Size() const
128 return aData.size();
131 template <class ID>
132 template <class IDENTIFY>
134 SequentialIds<ID>::Find(IDENTIFY i_find) const
136 const_iterator
137 ret = std::find_if(aData.begin(), aData.end(), i_find);
138 csv_assert(ret != aData.end());
139 return *ret;
142 template <class ID>
143 template <class IDENTIFY>
144 // Workaround for Solaris8 compiler: return type has to match alphabetically
145 // typename SequentialIds<ID>::const_iterator
146 typename std::vector<ID>::const_iterator
147 SequentialIds<ID>::Search(IDENTIFY i_find) const
149 return std::find_if(aData.begin(), aData.end(), i_find);
155 } // namespace ary
156 #endif