Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:08

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * File:   G4TableTemplate.hh
0028  * Author: B. Wendt (wendbryc@isu.edu)
0029  *
0030  * Created on August 2, 2011, 10:21 AM
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 /** G4TableTemplate is essentially a wrapper around a std::vector designed
0042  *  to work specifically with pointers.
0043  */
0044 template<class T>
0045 class G4TableTemplate
0046 {
0047   public:
0048     /** Default constructor */
0049     G4TableTemplate() = default;
0050     /** Adds a container to the table */
0051     void G4AddContainer(T* NewContainer);
0052     /** Gets a pointer to the table */
0053     G4TableTemplate* G4GetTable();
0054     /** Retrieve a container from the table */
0055     T* G4GetContainer(unsigned int WhichContainer);
0056     /** Create a new blank container */
0057     T* G4GetNewContainer();
0058     /** Create a new container that is constructed with a G4int */
0059     T* G4GetNewContainer(G4int DefaultValue);
0060     /** Get the number of elements in the table */
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 /* G4TABLETEMPLATE_HH */