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_SEQUENTIALIDS_HXX 29 #define ARY_SEQUENTIALIDS_HXX 30 31 32 // USED SERVICES 33 // BASE CLASSES 34 // OTHER 35 #include <algorithm> 36 37 38 39 namespace ary 40 { 41 42 43 /** Implementation of a set of children to an entity in the Autodoc 44 repository. The children are in the sequence of addition. 45 */ 46 template<class ID> 47 class SequentialIds 48 { 49 public: 50 typedef std::vector<ID> data_t; 51 typedef typename data_t::const_iterator const_iterator; 52 53 // LIFECYCLE 54 explicit SequentialIds( 55 std::size_t i_reserve = 0 ); 56 ~SequentialIds(); 57 58 // OPERATIONS 59 void Add( 60 const ID & i_child ); 61 // INQUIRY 62 const_iterator Begin() const; 63 const_iterator End() const; 64 std::size_t Size() const; 65 66 template <class IDENTIFY> 67 ID Find( 68 IDENTIFY i_find ) const; 69 template <class IDENTIFY> 70 // Workaround for Solaris8 compiler: return type has to match alphabetically 71 typename std::vector<ID>::const_iterator 72 Search( 73 IDENTIFY i_find ) const; 74 private: 75 // DATA 76 data_t aData; 77 }; 78 79 80 81 82 83 84 85 // IMPLEMENTATION 86 87 template <class ID> 88 SequentialIds<ID>::SequentialIds(std::size_t i_reserve) 89 : aData() 90 { 91 if (i_reserve > 0) 92 aData.reserve(i_reserve); 93 } 94 95 template <class ID> 96 SequentialIds<ID>::~SequentialIds() 97 { 98 } 99 100 template <class ID> 101 inline void 102 SequentialIds<ID>::Add(const ID & i_child) 103 { 104 aData.push_back(i_child); 105 } 106 107 template <class ID> 108 inline typename SequentialIds<ID>::const_iterator 109 SequentialIds<ID>::Begin() const 110 { 111 return aData.begin(); 112 } 113 114 template <class ID> 115 inline typename SequentialIds<ID>::const_iterator 116 SequentialIds<ID>::End() const 117 { 118 return aData.end(); 119 } 120 121 template <class ID> 122 inline std::size_t 123 SequentialIds<ID>::Size() const 124 { 125 return aData.size(); 126 } 127 128 template <class ID> 129 template <class IDENTIFY> 130 ID 131 SequentialIds<ID>::Find(IDENTIFY i_find) const 132 { 133 const_iterator 134 ret = std::find_if(aData.begin(), aData.end(), i_find); 135 csv_assert(ret != aData.end()); 136 return *ret; 137 } 138 139 template <class ID> 140 template <class IDENTIFY> 141 // Workaround for Solaris8 compiler: return type has to match alphabetically 142 // typename SequentialIds<ID>::const_iterator 143 typename std::vector<ID>::const_iterator 144 SequentialIds<ID>::Search(IDENTIFY i_find) const 145 { 146 return std::find_if(aData.begin(), aData.end(), i_find); 147 } 148 149 150 151 152 } // namespace ary 153 #endif 154