Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DataVector Class Reference

#include <G4DataVector.hh>

+ Inheritance diagram for G4DataVector:

Public Types

enum  { T_G4DataVector = 100 }
 

Public Member Functions

 G4DataVector ()
 
 G4DataVector (const G4DataVector &)=default
 
 G4DataVector (G4DataVector &&)=default
 
 G4DataVector (std::size_t cap)
 
 G4DataVector (std::size_t cap, G4double value)
 
virtual ~G4DataVector ()
 
G4DataVectoroperator= (const G4DataVector &)=default
 
G4DataVectoroperator= (G4DataVector &&)=default
 
void insertAt (std::size_t, const G4double &)
 
std::size_t index (const G4double &)
 
G4bool contains (const G4double &) const
 
G4bool remove (const G4double &)
 
std::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 46 of file G4DataVector.hh.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
T_G4DataVector 

Definition at line 85 of file G4DataVector.hh.

86 {
87 T_G4DataVector = 100
88 };

Constructor & Destructor Documentation

◆ G4DataVector() [1/5]

G4DataVector::G4DataVector ( )

Definition at line 35 of file G4DataVector.cc.

36 : std::vector<G4double>()
37{}

◆ G4DataVector() [2/5]

G4DataVector::G4DataVector ( const G4DataVector )
default

◆ G4DataVector() [3/5]

G4DataVector::G4DataVector ( G4DataVector &&  )
default

◆ G4DataVector() [4/5]

G4DataVector::G4DataVector ( std::size_t  cap)
explicit

Definition at line 40 of file G4DataVector.cc.

41 : std::vector<G4double>(cap, 0.0)
42{}

◆ G4DataVector() [5/5]

G4DataVector::G4DataVector ( std::size_t  cap,
G4double  value 
)

Definition at line 45 of file G4DataVector.cc.

46 : std::vector<G4double>(cap, value)
47{}

◆ ~G4DataVector()

G4DataVector::~G4DataVector ( )
virtual

Definition at line 50 of file G4DataVector.cc.

50{}

Member Function Documentation

◆ contains()

G4bool G4DataVector::contains ( const G4double ) const
inline

◆ index()

std::size_t G4DataVector::index ( const G4double )
inline

◆ insertAt()

void G4DataVector::insertAt ( std::size_t  ,
const G4double  
)
inline

◆ operator=() [1/2]

G4DataVector & G4DataVector::operator= ( const G4DataVector )
default

◆ operator=() [2/2]

G4DataVector & G4DataVector::operator= ( G4DataVector &&  )
default

◆ remove()

G4bool G4DataVector::remove ( const G4double )
inline

◆ removeAll()

std::size_t G4DataVector::removeAll ( const G4double )
inline

◆ Retrieve()

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

Definition at line 79 of file G4DataVector.cc.

80{
81 clear();
82 G4int sizeV = 0;
83
84 // retrieve in ascii mode
85 if(ascii)
86 {
87 // contents
88 fIn >> sizeV;
89 if(fIn.fail())
90 {
91 return false;
92 }
93 if(sizeV <= 0)
94 {
95#ifdef G4VERBOSE
96 G4cerr << "G4DataVector::Retrieve():";
97 G4cerr << " Invalid vector size: " << sizeV << G4endl;
98#endif
99 return false;
100 }
101
102 reserve(sizeV);
103 for(G4int i = 0; i < sizeV; ++i)
104 {
105 G4double vData = 0.0;
106 fIn >> vData;
107 if(fIn.fail())
108 {
109 return false;
110 }
111 push_back(vData);
112 }
113 return true;
114 }
115
116 // retrieve in binary mode
117 fIn.read((char*) (&sizeV), sizeof sizeV);
118
119 G4double* value = new G4double[sizeV];
120 fIn.read((char*) (value), sizeV * (sizeof(G4double)));
121 if(G4int(fIn.gcount()) != G4int(sizeV * (sizeof(G4double))))
122 {
123 delete[] value;
124 return false;
125 }
126
127 reserve(sizeV);
128 for(G4int i = 0; i < sizeV; ++i)
129 {
130 push_back(value[i]);
131 }
132 delete[] value;
133 return true;
134}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57

Referenced by G4OrderedTable::Retrieve().

◆ Store()

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

Definition at line 53 of file G4DataVector.cc.

54{
55 // Ascii mode
56 if(ascii)
57 {
58 fOut << *this;
59 return true;
60 }
61
62 // Binary Mode
63 G4int sizeV = G4int(size());
64 fOut.write((char*) (&sizeV), sizeof sizeV);
65
66 G4double* value = new G4double[sizeV];
67 std::size_t i = 0;
68 for(auto itr = cbegin(); itr != cend(); ++itr, ++i)
69 {
70 value[i] = *itr;
71 }
72 fOut.write((char*) (value), sizeV * (sizeof(G4double)));
73 delete[] value;
74
75 return true;
76}

Friends And Related Function Documentation

◆ operator<<

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

Definition at line 137 of file G4DataVector.cc.

138{
139 out << pv.size() << std::setprecision(12) << G4endl;
140 for(std::size_t i = 0; i < pv.size(); ++i)
141 {
142 out << pv[i] << G4endl;
143 }
144 out << std::setprecision(6);
145
146 return out;
147}

The documentation for this class was generated from the following files: