Geant4-11
G4FastVector.hh
Go to the documentation of this file.
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// G4FastVector
27//
28// Class description:
29//
30// Template class defining a vector of pointers,
31// not performing boundary checking.
32
33// Author: G.Cosmo, 2 December 1995
34// First implementation, based on object model
35// --------------------------------------------------------------------
36#ifndef G4FastVector_hh
37#define G4FastVector_hh 1
38
39#include "globals.hh"
40
41template <class Type, G4int N>
43{
44 public:
46
48 {
49 if(ptr != &theArray[0])
50 delete[] ptr;
51 }
52
53 inline Type* operator[](G4int anIndex) const
54 // Access operator to the array.
55 {
56 return ptr[anIndex];
57 }
58
59 inline void Initialize(G4int items)
60 // Normally the pointer ptr points to the stack-array
61 // theArray; only when the number of items is greater
62 // than N, memory is allocated dynamically.
63 {
64 if(ptr != &theArray[0])
65 delete[] ptr;
66 if(items > N)
67 ptr = new Type*[items];
68 else
69 ptr = &theArray[0];
70 }
71
72 inline void SetElement(G4int anIndex, Type* anElement)
73 // To insert an element at the given position inside
74 // the vector.
75 {
76 ptr[anIndex] = anElement;
77 }
78
79 private:
82};
83
84#endif
int G4int
Definition: G4Types.hh:85
Type * theArray[N]
Definition: G4FastVector.hh:80
void SetElement(G4int anIndex, Type *anElement)
Definition: G4FastVector.hh:72
void Initialize(G4int items)
Definition: G4FastVector.hh:59
Type * operator[](G4int anIndex) const
Definition: G4FastVector.hh:53