[807] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
| 26 | // |
---|
| 27 | // File name: RadmonTLabelledCollection.icc |
---|
| 28 | // Creation date: Sep 2005 |
---|
| 29 | // Main author: Riccardo Capra <capra@ge.infn.it> |
---|
| 30 | // |
---|
| 31 | // Id: $Id: RadmonTLabelledCollection.icc,v 1.6 2006/06/29 16:14:31 gunter Exp $ |
---|
| 32 | // Tag: $Name: $ |
---|
| 33 | // |
---|
| 34 | |
---|
| 35 | #ifndef RADMONTLABELLEDCOLLECTION_HH |
---|
| 36 | #error "RadmonTLabelledCollection.icc cannot be included directly. Please use RadmonTLabelledCollection.hh" |
---|
| 37 | #else /* RADMONTLABELLEDCOLLECTION_HH */ |
---|
| 38 | template <typename LabelledObject> |
---|
| 39 | RadmonTLabelledCollection<LabelledObject> :: RadmonTLabelledCollection() |
---|
| 40 | { |
---|
| 41 | } |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | template <typename LabelledObject> |
---|
| 46 | RadmonTLabelledCollection<LabelledObject> :: RadmonTLabelledCollection(const RadmonTLabelledCollection<LabelledObject> & copy) |
---|
| 47 | { |
---|
| 48 | collection=copy.collection; |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | template <typename LabelledObject> |
---|
| 54 | RadmonTLabelledCollection<LabelledObject> :: ~RadmonTLabelledCollection() |
---|
| 55 | { |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | |
---|
| 62 | template <typename LabelledObject> |
---|
| 63 | RadmonTLabelledCollection<LabelledObject> & RadmonTLabelledCollection<LabelledObject> :: operator=(const RadmonTLabelledCollection<LabelledObject> & copy) |
---|
| 64 | { |
---|
| 65 | collection=copy.collection; |
---|
| 66 | |
---|
| 67 | return (*this); |
---|
| 68 | } |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | |
---|
| 74 | template <typename LabelledObject> |
---|
| 75 | G4int RadmonTLabelledCollection<LabelledObject> :: GetNItems() const |
---|
| 76 | { |
---|
| 77 | return collection.size(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | template <typename LabelledObject> |
---|
| 83 | G4bool RadmonTLabelledCollection<LabelledObject> :: Empty() const |
---|
| 84 | { |
---|
| 85 | return collection.empty(); |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | template <typename LabelledObject> |
---|
| 93 | G4bool RadmonTLabelledCollection<LabelledObject> :: ExistsItemByLabel(const G4String & label) const |
---|
| 94 | { |
---|
| 95 | size_t i(collection.size()); |
---|
| 96 | |
---|
| 97 | while (i>0) |
---|
| 98 | { |
---|
| 99 | i--; |
---|
| 100 | if (collection[i].GetLabel()==label) |
---|
| 101 | return true; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | return false; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | template <typename LabelledObject> |
---|
| 110 | G4int RadmonTLabelledCollection<LabelledObject> :: MultiplicityItemByLabel(const G4String & label) const |
---|
| 111 | { |
---|
| 112 | G4int count(0); |
---|
| 113 | size_t i(collection.size()); |
---|
| 114 | |
---|
| 115 | while (i>0) |
---|
| 116 | { |
---|
| 117 | i--; |
---|
| 118 | if (collection[i].GetLabel()==label) |
---|
| 119 | count++; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | return count; |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | |
---|
| 126 | |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | template <typename LabelledObject> |
---|
| 130 | const LabelledObject & RadmonTLabelledCollection<LabelledObject> :: GetItem(G4int index) const |
---|
| 131 | { |
---|
| 132 | return collection[index]; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | template <typename LabelledObject> |
---|
| 138 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: GetItem(G4int index) |
---|
| 139 | { |
---|
| 140 | return collection[index]; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | |
---|
| 145 | template <typename LabelledObject> |
---|
| 146 | const LabelledObject & RadmonTLabelledCollection<LabelledObject> :: FindItemByLabel(const G4String & label, G4int count) const |
---|
| 147 | { |
---|
| 148 | return const_cast<RadmonTLabelledCollection *>(this)->FindItemByLabel(label, count); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | template <typename LabelledObject> |
---|
| 154 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: FindItemByLabel(const G4String & label, G4int count) |
---|
| 155 | { |
---|
| 156 | typename Collection::iterator i(collection.begin()); |
---|
| 157 | typename Collection::iterator const end(collection.end()); |
---|
| 158 | |
---|
| 159 | while (i<end) |
---|
| 160 | { |
---|
| 161 | if (i->GetLabel()==label) |
---|
| 162 | { |
---|
| 163 | if (count==0) |
---|
| 164 | return (*i); |
---|
| 165 | |
---|
| 166 | count--; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | i++; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | G4String text("RadmonTLabelledCollection::FindItemByLabel: Label \""); |
---|
| 173 | text+=label; |
---|
| 174 | text+="\" not found."; |
---|
| 175 | |
---|
| 176 | G4Exception(text); |
---|
| 177 | |
---|
| 178 | return collection.front(); |
---|
| 179 | } |
---|
| 180 | |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | |
---|
| 184 | |
---|
| 185 | template <typename LabelledObject> |
---|
| 186 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: InsertItemAfter(G4int index) |
---|
| 187 | { |
---|
| 188 | return InsertBefore(index+1); |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | template <typename LabelledObject> |
---|
| 194 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: InsertItemBefore(G4int index) |
---|
| 195 | { |
---|
| 196 | typename Collection::iterator i(collection.begin()); |
---|
| 197 | i+=index; |
---|
| 198 | |
---|
| 199 | collection.insert(i, LabelledObject()); |
---|
| 200 | |
---|
| 201 | return collection[index]; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | template <typename LabelledObject> |
---|
| 207 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: AppendItem(void) |
---|
| 208 | { |
---|
| 209 | collection.push_back(LabelledObject()); |
---|
| 210 | return collection.back(); |
---|
| 211 | } |
---|
| 212 | |
---|
| 213 | |
---|
| 214 | |
---|
| 215 | template <typename LabelledObject> |
---|
| 216 | LabelledObject & RadmonTLabelledCollection<LabelledObject> :: PrependItem(void) |
---|
| 217 | { |
---|
| 218 | collection.insert(collection.begin(), LabelledObject()); |
---|
| 219 | return collection.front(); |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | |
---|
| 226 | template <typename LabelledObject> |
---|
| 227 | void RadmonTLabelledCollection<LabelledObject> :: RemoveItemByLabel(const G4String & label, G4int count) |
---|
| 228 | { |
---|
| 229 | typename Collection::iterator i(collection.begin()); |
---|
| 230 | typename Collection::iterator const end(collection.end()); |
---|
| 231 | |
---|
| 232 | while (i<end) |
---|
| 233 | { |
---|
| 234 | if (i->GetLabel()==label) |
---|
| 235 | { |
---|
| 236 | if (count==0) |
---|
| 237 | { |
---|
| 238 | collection.erase(i); |
---|
| 239 | return; |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | count--; |
---|
| 243 | } |
---|
| 244 | |
---|
| 245 | i++; |
---|
| 246 | } |
---|
| 247 | } |
---|
| 248 | |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | template <typename LabelledObject> |
---|
| 252 | void RadmonTLabelledCollection<LabelledObject> :: RemoveItemsByLabel(const G4String & label) |
---|
| 253 | { |
---|
| 254 | typename Collection::iterator i(collection.begin()); |
---|
| 255 | typename Collection::iterator const end(collection.end()); |
---|
| 256 | |
---|
| 257 | while (i<end) |
---|
| 258 | { |
---|
| 259 | if (i->GetLabel()==label) |
---|
| 260 | i=collection.erase(i); |
---|
| 261 | else |
---|
| 262 | i++; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | |
---|
| 267 | |
---|
| 268 | template <typename LabelledObject> |
---|
| 269 | void RadmonTLabelledCollection<LabelledObject> :: RemoveItem(G4int index) |
---|
| 270 | { |
---|
| 271 | typename Collection::iterator i(collection.begin()); |
---|
| 272 | i+=index; |
---|
| 273 | |
---|
| 274 | collection.erase(i); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | |
---|
| 278 | |
---|
| 279 | template <typename LabelledObject> |
---|
| 280 | void RadmonTLabelledCollection<LabelledObject> :: RemoveItemsByRange(G4int first, G4int last) |
---|
| 281 | { |
---|
| 282 | typename Collection::iterator i(collection.begin()); |
---|
| 283 | typename Collection::iterator j(i); |
---|
| 284 | |
---|
| 285 | i+=first; |
---|
| 286 | j+=last; |
---|
| 287 | |
---|
| 288 | collection.erase(i, j); |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | template <typename LabelledObject> |
---|
| 294 | void RadmonTLabelledCollection<LabelledObject> :: RemoveAllItems() |
---|
| 295 | { |
---|
| 296 | collection.clear(); |
---|
| 297 | } |
---|
| 298 | #endif /* RADMONTLABELLEDCOLLECTION_HH */ |
---|