Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 /* 27 * File: G4ArrayOps.hh 28 * Author: B. Wendt (wendbryc@isu.edu) 29 * 30 * Created on July 28, 2012, 16:08 31 */ 32 33 // All the arrays that use the functions in th 34 // [] (bracket) operator for element-wise acce 35 36 #ifndef G4ARRAYOPS_HH 37 #define G4ARRAYOPS_HH 38 39 #include "globals.hh" 40 41 #include <vector> 42 43 /** G4ArrayOps is a namespace that provides te 44 * performing basic arithmatic operations on 45 * is accessed with the [] operator. 46 */ 47 namespace G4ArrayOps 48 { 49 /** Set's all the values in an array to a cons 50 template<class T> 51 void Set(G4int Elements, T* To, T Value) 52 { 53 for (G4int position = 0; position < Elements 54 To[position] = Value; 55 } 56 } 57 58 /** Copy values from one array to another */ 59 template<class T> 60 void Copy(G4int Elements, T* To, T* From) 61 { 62 for (G4int position = 0; position < Elements 63 To[position] = From[position]; 64 } 65 } 66 67 /** Add two arrays together. If the second arr 68 * 'To' array is used as if the function were 69 */ 70 template<class T> 71 void Add(G4int Elements, T* To, T* A1, T* A2 = 72 { 73 if (A2 == nullptr) { 74 A2 = To; 75 } 76 77 for (G4int position = 0; position < Elements 78 To[position] = A2[position] + A1[position] 79 } 80 } 81 82 /** Add a constant to an array. If the second 83 * 'To' array is used as if the function were 84 */ 85 template<class T> 86 void Add(G4int Elements, T* To, T A1, T* A2 = 87 { 88 if (A2 == NULL) { 89 A2 = To; 90 } 91 92 for (G4int position = 0; position < Elements 93 To[position] = A1 + A2[position]; 94 } 95 } 96 97 /** Subtract an array from another. If the sec 98 * 'To' array is used as if the function were 99 */ 100 template<class T> 101 void Subtract(G4int Elements, T* To, T* Minuen 102 { 103 if (Subtrahend == NULL) { 104 Subtrahend = Minuend; 105 Minuend = To; 106 } 107 108 for (G4int position = 0; position < Elements 109 To[position] = Minuend[position] - Subtrah 110 } 111 } 112 113 /** Multiply two arrays together. If the secon 114 * 'To' array is used as if the function were 115 */ 116 template<class T> 117 void Multiply(G4int Elements, T* To, T* M1, T* 118 { 119 if (M2 == nullptr) { 120 M2 = To; 121 } 122 123 for (G4int position = 0; position < Elements 124 To[position] = M2[position] * M1[position] 125 } 126 } 127 128 /** Multiply an array by a constant. If the se 129 * 'To' array is used as if the function were 130 */ 131 template<class T> 132 void Multiply(G4int Elements, T* To, T M1, T* 133 { 134 if (M2 == NULL) { 135 M2 = To; 136 } 137 138 for (G4int position = 0; position < Elements 139 To[position] = M2[position] * M1; 140 } 141 } 142 143 /** Divide an array by another. If the second 144 * 'To' array is used as if the function were 145 */ 146 template<class T> 147 void Divide(G4int Elements, T* To, T* Numerato 148 { 149 if (Denominator == NULL) { 150 Denominator = Numerator; 151 Numerator = To; 152 } 153 154 for (G4int position = 0; position < Elements 155 To[position] = Numerator[position] / Denom 156 } 157 } 158 159 /** Divide a constant by an array. If the seco 160 * 'To' array is used as if the function were 161 */ 162 template<class T> 163 void Divide(G4int Elements, T* To, T Numerator 164 { 165 if (Denominator == nullptr) { 166 Denominator = To; 167 } 168 169 for (G4int position = 0; position < Elements 170 To[position] = Numerator / Denominator[pos 171 } 172 } 173 174 template<class T> 175 void DeleteVectorOfPointers(std::vector<T>& Ve 176 { 177 for (unsigned int i = 0; i < Vector.size(); 178 delete Vector[i]; 179 } 180 181 delete &Vector; 182 } 183 } // namespace G4ArrayOps 184 185 #endif /** G4ARRAYOPS_HH */ 186