xref: /aoo42x/main/autodoc/inc/ary/sequentialids.hxx (revision 1c78a5d6)
1*1c78a5d6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1c78a5d6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1c78a5d6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1c78a5d6SAndrew Rist  * distributed with this work for additional information
6*1c78a5d6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1c78a5d6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1c78a5d6SAndrew Rist  * "License"); you may not use this file except in compliance
9*1c78a5d6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1c78a5d6SAndrew Rist  *
11*1c78a5d6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1c78a5d6SAndrew Rist  *
13*1c78a5d6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1c78a5d6SAndrew Rist  * software distributed under the License is distributed on an
15*1c78a5d6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1c78a5d6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1c78a5d6SAndrew Rist  * specific language governing permissions and limitations
18*1c78a5d6SAndrew Rist  * under the License.
19*1c78a5d6SAndrew Rist  *
20*1c78a5d6SAndrew Rist  *************************************************************/
21*1c78a5d6SAndrew Rist 
22*1c78a5d6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef ARY_SEQUENTIALIDS_HXX
25cdf0e10cSrcweir #define ARY_SEQUENTIALIDS_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // USED SERVICES
29cdf0e10cSrcweir     // BASE CLASSES
30cdf0e10cSrcweir     // OTHER
31cdf0e10cSrcweir #include <algorithm>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
35cdf0e10cSrcweir namespace ary
36cdf0e10cSrcweir {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir /** Implementation of a set of children to an entity in the Autodoc
40cdf0e10cSrcweir     repository. The children are in the sequence of addition.
41cdf0e10cSrcweir */
42cdf0e10cSrcweir template<class ID>
43cdf0e10cSrcweir class SequentialIds
44cdf0e10cSrcweir {
45cdf0e10cSrcweir   public:
46cdf0e10cSrcweir     typedef std::vector<ID>                     data_t;
47cdf0e10cSrcweir     typedef typename data_t::const_iterator     const_iterator;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     // LIFECYCLE
50cdf0e10cSrcweir     explicit            SequentialIds(
51cdf0e10cSrcweir                             std::size_t         i_reserve = 0 );
52cdf0e10cSrcweir                         ~SequentialIds();
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     // OPERATIONS
55cdf0e10cSrcweir     void                Add(
56cdf0e10cSrcweir                             const ID &       i_child );
57cdf0e10cSrcweir     // INQUIRY
58cdf0e10cSrcweir     const_iterator      Begin() const;
59cdf0e10cSrcweir     const_iterator      End() const;
60cdf0e10cSrcweir     std::size_t         Size() const;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     template <class IDENTIFY>
63cdf0e10cSrcweir     ID                  Find(
64cdf0e10cSrcweir                             IDENTIFY            i_find ) const;
65cdf0e10cSrcweir     template <class IDENTIFY>
66cdf0e10cSrcweir     // Workaround for Solaris8 compiler: return type has to match alphabetically
67cdf0e10cSrcweir     typename std::vector<ID>::const_iterator
68cdf0e10cSrcweir                         Search(
69cdf0e10cSrcweir                             IDENTIFY            i_find ) const;
70cdf0e10cSrcweir   private:
71cdf0e10cSrcweir     // DATA
72cdf0e10cSrcweir     data_t              aData;
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 
81cdf0e10cSrcweir // IMPLEMENTATION
82cdf0e10cSrcweir 
83cdf0e10cSrcweir template <class ID>
SequentialIds(std::size_t i_reserve)84cdf0e10cSrcweir SequentialIds<ID>::SequentialIds(std::size_t i_reserve)
85cdf0e10cSrcweir     :   aData()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     if (i_reserve > 0)
88cdf0e10cSrcweir         aData.reserve(i_reserve);
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir template <class ID>
~SequentialIds()92cdf0e10cSrcweir SequentialIds<ID>::~SequentialIds()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir template <class ID>
97cdf0e10cSrcweir inline void
Add(const ID & i_child)98cdf0e10cSrcweir SequentialIds<ID>::Add(const ID & i_child)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir     aData.push_back(i_child);
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir template <class ID>
104cdf0e10cSrcweir inline typename SequentialIds<ID>::const_iterator
Begin() const105cdf0e10cSrcweir SequentialIds<ID>::Begin() const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     return aData.begin();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir template <class ID>
111cdf0e10cSrcweir inline typename SequentialIds<ID>::const_iterator
End() const112cdf0e10cSrcweir SequentialIds<ID>::End() const
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     return aData.end();
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir template <class ID>
118cdf0e10cSrcweir inline std::size_t
Size() const119cdf0e10cSrcweir SequentialIds<ID>::Size() const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     return aData.size();
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir template <class ID>
125cdf0e10cSrcweir template <class IDENTIFY>
126cdf0e10cSrcweir ID
Find(IDENTIFY i_find) const127cdf0e10cSrcweir SequentialIds<ID>::Find(IDENTIFY i_find) const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     const_iterator
130cdf0e10cSrcweir         ret = std::find_if(aData.begin(), aData.end(), i_find);
131cdf0e10cSrcweir     csv_assert(ret != aData.end());
132cdf0e10cSrcweir     return *ret;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir template <class ID>
136cdf0e10cSrcweir template <class IDENTIFY>
137cdf0e10cSrcweir // Workaround for Solaris8 compiler: return type has to match alphabetically
138cdf0e10cSrcweir // typename SequentialIds<ID>::const_iterator
139cdf0e10cSrcweir typename std::vector<ID>::const_iterator
Search(IDENTIFY i_find) const140cdf0e10cSrcweir SequentialIds<ID>::Search(IDENTIFY i_find) const
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     return std::find_if(aData.begin(), aData.end(), i_find);
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 
148cdf0e10cSrcweir }   // namespace ary
149cdf0e10cSrcweir #endif
150