G4DataVector Class Reference

#include <G4DataVector.hh>


Public Types

 T_G4DataVector = 100
enum  { T_G4DataVector = 100 }

Public Member Functions

 G4DataVector ()
 G4DataVector (size_t cap)
 G4DataVector (size_t cap, G4double value)
virtual ~G4DataVector ()
void insertAt (size_t, const G4double &)
size_t index (const G4double &)
G4bool contains (const G4double &) const
G4bool remove (const G4double &)
size_t removeAll (const G4double &)
G4bool Store (std::ofstream &fOut, G4bool ascii=false)
G4bool Retrieve (std::ifstream &fIn, G4bool ascii=false)

Friends

std::ostream & operator<< (std::ostream &, const G4DataVector &)


Detailed Description

Definition at line 50 of file G4DataVector.hh.


Member Enumeration Documentation

anonymous enum

Enumerator:
T_G4DataVector 

Definition at line 83 of file G4DataVector.hh.

00083 {T_G4DataVector = 100};


Constructor & Destructor Documentation

G4DataVector::G4DataVector (  ) 

Definition at line 42 of file G4DataVector.cc.

00043   : std::vector<G4double>()
00044 {
00045 }

G4DataVector::G4DataVector ( size_t  cap  )  [explicit]

Definition at line 47 of file G4DataVector.cc.

00048   : std::vector<G4double>(cap, 0.0)
00049 {
00050 }

G4DataVector::G4DataVector ( size_t  cap,
G4double  value 
)

Definition at line 52 of file G4DataVector.cc.

00053   : std::vector<G4double>(cap, value)
00054 {
00055 }

G4DataVector::~G4DataVector (  )  [virtual]

Definition at line 57 of file G4DataVector.cc.

00058 {
00059 }


Member Function Documentation

G4bool G4DataVector::contains ( const G4double  )  const [inline]

Definition at line 55 of file G4DataVector.icc.

Referenced by G4VCrossSectionHandler::ActiveElements(), and G4AugerData::BuildAugerTransitionTable().

00056 {
00057   for (const_iterator i=begin(); i!=end(); i++)
00058     { if (!(*i!=a)) { return true; } }
00059 
00060   return false;
00061 }

size_t G4DataVector::index ( const G4double  )  [inline]

Definition at line 45 of file G4DataVector.icc.

00046 { 
00047   size_t ptn = 0;
00048   for (iterator i=begin(); i!=end(); i++,ptn++)
00049     { if (!(*i!=a)) { return ptn; } }
00050 
00051   return (ptn=~(size_t)0);
00052 }

void G4DataVector::insertAt ( size_t  ,
const G4double  
) [inline]

Definition at line 34 of file G4DataVector.icc.

00035 { 
00036   iterator i = begin();
00037   for (size_t ptn=0; (ptn<pos)&&(i!=end()); i++,ptn++) {;}
00038   if (i!=end())
00039     { insert(i,a); }
00040   else
00041     { push_back(a); }
00042 }

G4bool G4DataVector::remove ( const G4double  )  [inline]

Definition at line 64 of file G4DataVector.icc.

00065 {
00066   G4bool found = false;
00067 
00068   for (iterator i=begin(); i!=end(); i++)
00069   {
00070     if (!(*i!=a))
00071     {
00072       erase(i);
00073       found = true;
00074       break;
00075     }
00076   }
00077   return found;
00078 }

size_t G4DataVector::removeAll ( const G4double  )  [inline]

Definition at line 81 of file G4DataVector.icc.

00082 {
00083   size_t ptn=0;
00084 
00085   for (iterator i=begin(); i!=end(); i++)
00086   {
00087     if (!(*i!=a))
00088     {
00089       erase(i);
00090       ptn++;
00091       i--;
00092     } 
00093   }
00094   return ptn;
00095 }

G4bool G4DataVector::Retrieve ( std::ifstream &  fIn,
G4bool  ascii = false 
)

Definition at line 86 of file G4DataVector.cc.

References G4cerr, and G4endl.

Referenced by G4OrderedTable::Retrieve().

00087 {
00088   clear();
00089   G4int sizeV=0;
00090   
00091   // retrieve in ascii mode
00092   if (ascii)
00093   {
00094     // contents
00095     fIn >> sizeV;
00096     if (fIn.fail())  { return false; }
00097     if (sizeV<=0)
00098     {
00099 #ifdef G4VERBOSE  
00100       G4cerr << "G4DataVector::Retrieve():";
00101       G4cerr << " Invalid vector size: " << sizeV << G4endl;
00102 #endif
00103       return false;
00104     }
00105 
00106     reserve(sizeV);
00107     for(G4int i = 0; i < sizeV ; i++)
00108     {
00109       G4double vData=0.0;
00110       fIn >> vData;
00111       if (fIn.fail())  { return false; }
00112       push_back(vData);
00113     }
00114     return true ;
00115   }
00116   
00117   // retrieve in binary mode
00118   fIn.read((char*)(&sizeV), sizeof sizeV); 
00119  
00120   G4double* value = new G4double[sizeV];
00121   fIn.read((char*)(value),  sizeV*(sizeof(G4double)) );
00122   if (G4int(fIn.gcount()) != G4int(sizeV*(sizeof(G4double))) )
00123   {
00124     delete [] value;
00125     return false;
00126   }
00127 
00128   reserve(sizeV);
00129   for(G4int i = 0; i < sizeV; i++) 
00130   {
00131     push_back(value[i]);
00132   }
00133   delete [] value;
00134   return true;
00135 }

G4bool G4DataVector::Store ( std::ofstream &  fOut,
G4bool  ascii = false 
)

Definition at line 61 of file G4DataVector.cc.

00062 {
00063   // Ascii mode
00064   if (ascii)
00065   {
00066     fOut << *this;
00067     return true;
00068   } 
00069 
00070   // Binary Mode
00071   size_t sizeV = size(); 
00072   fOut.write((char*)(&sizeV), sizeof sizeV);
00073 
00074   G4double* value = new G4double[sizeV];
00075   size_t i=0;
00076   for (const_iterator itr=begin(); itr!=end(); itr++, i++)
00077   {
00078     value[i]  =  *itr;
00079   }
00080   fOut.write((char*)(value), sizeV*(sizeof (G4double)) );
00081   delete [] value;
00082   
00083   return true;
00084 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const G4DataVector pv 
) [friend]

Definition at line 137 of file G4DataVector.cc.

00138 {
00139   out << pv.size() << std::setprecision(12) << G4endl; 
00140   for(size_t i = 0; i < pv.size(); i++)
00141   {
00142     out << pv[i] << G4endl;
00143   }
00144   out << std::setprecision(6);
00145 
00146   return out;
00147 }


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:51:44 2013 for Geant4 by  doxygen 1.4.7