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