File indexing completed on 2025-01-18 09:59:08
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef G4TABLETEMPLATE_HH
0034 #define G4TABLETEMPLATE_HH
0035
0036 #include "G4FFGDefaultValues.hh"
0037 #include "globals.hh"
0038
0039 #include <vector>
0040
0041
0042
0043
0044 template<class T>
0045 class G4TableTemplate
0046 {
0047 public:
0048
0049 G4TableTemplate() = default;
0050
0051 void G4AddContainer(T* NewContainer);
0052
0053 G4TableTemplate* G4GetTable();
0054
0055 T* G4GetContainer(unsigned int WhichContainer);
0056
0057 T* G4GetNewContainer();
0058
0059 T* G4GetNewContainer(G4int DefaultValue);
0060
0061 G4long G4GetNumberOfElements();
0062
0063 private:
0064 std::vector<T*> ContainerTable_;
0065
0066 public:
0067 ~G4TableTemplate();
0068 };
0069
0070 template<class T>
0071 void G4TableTemplate<T>::G4AddContainer(T* NewContainer)
0072 {
0073 ContainerTable_.push_back(NewContainer);
0074 }
0075
0076 template<class T>
0077 G4TableTemplate<T>* G4TableTemplate<T>::G4GetTable()
0078 {
0079 return this;
0080 }
0081
0082 template<class T>
0083 T* G4TableTemplate<T>::G4GetContainer(unsigned int WhichContainer)
0084 {
0085 if (WhichContainer < ContainerTable_.size()) {
0086 return ContainerTable_[WhichContainer];
0087 }
0088
0089 return nullptr;
0090 }
0091
0092 template<class T>
0093 T* G4TableTemplate<T>::G4GetNewContainer()
0094 {
0095 ContainerTable_.push_back(new T);
0096
0097 return ContainerTable_.back();
0098 }
0099
0100 template<class T>
0101 T* G4TableTemplate<T>::G4GetNewContainer(G4int DefaultValue)
0102 {
0103 ContainerTable_.push_back(new T(DefaultValue));
0104
0105 return ContainerTable_.back();
0106 }
0107
0108 template<class T>
0109 G4long G4TableTemplate<T>::G4GetNumberOfElements()
0110 {
0111 return ContainerTable_.size();
0112 }
0113
0114 template<class T>
0115 G4TableTemplate<T>::~G4TableTemplate()
0116 {
0117 for (unsigned int i = 0; i < ContainerTable_.size(); i++) {
0118 delete ContainerTable_[i];
0119 }
0120 }
0121
0122 #endif