G4OrderedTable.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // ------------------------------------------------------------
00031 //      GEANT 4 class header file 
00032 // ------------------------------------------------------------
00033 // Sep. 1996  : M.Maire 
00034 // Jan. 2001  : H.Kurashige
00035 //              - G4ValVector is replaced with G4DataVector 
00036 //              - Migrated to std::vector<G4DataVector*>.
00037 // Sep. 2001  : H.Kurashige
00038 //              - Add
00039 //                 G4bool Store(const G4String&, G4bool)
00040 //                 G4bool Retrieve(const G4String&, G4bool);
00041 //                 ostream& operator<<(ostream&, G4OrderedTable&)
00042 //
00043 // Class Description:
00044 //
00045 //      Utility class, defining an ordered collection of vectors
00046 //      of <G4double>.
00047 
00048 // ------------------------------------------------------------
00049 
00050 #ifndef G4OrderedTable_h
00051 #define G4OrderedTable_h 1
00052 
00053 #include "globals.hh"
00054 #include <vector>
00055 class G4DataVector;
00056 
00057 class G4OrderedTable : public std::vector<G4DataVector*> 
00058 {
00059 
00060  public: // with description
00061 
00062   G4OrderedTable();
00063     // Deafult constructor.
00064 
00065   explicit G4OrderedTable(size_t cap);
00066     // Constructor given a 'capacity' defining the initial
00067     // number of elements (NULL pointers are filled up)
00068 
00069   virtual ~G4OrderedTable();
00070     // Empty Destructor
00071 
00072   inline void clearAndDestroy();
00073     // Removes all elements and deletes all non-NULL pointers
00074 
00075   G4bool Store(const G4String& filename, G4bool ascii=false);
00076     // Stores OrderedTable in a file (returns false in case of failure).
00077   
00078   G4bool Retrieve(const G4String& filename, G4bool ascii=false);
00079     // Retrieves OrderedTable from a file (returns false in case of failure).
00080 
00081   friend std::ostream& operator<<(std::ostream& out, G4OrderedTable& table);
00082 
00083 };
00084 
00085 typedef G4OrderedTable::iterator G4OrderedTableIterator;
00086 
00087 #include "G4DataVector.hh"
00088 
00089 inline 
00090 void G4OrderedTable::clearAndDestroy() 
00091 {
00092   G4DataVector* a = 0;
00093   while (size()>0)
00094   {
00095     a = back();
00096     pop_back();
00097     for (iterator i=begin(); i!=end(); i++)
00098     {
00099       if (*i==a)
00100       {
00101         erase(i);
00102         i--;
00103       }
00104     } 
00105     if ( a ) { delete a; }
00106   } 
00107 }
00108 
00109 #endif

Generated on Mon May 27 17:49:13 2013 for Geant4 by  doxygen 1.4.7