Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4UIArrayString Class Reference

#include <G4UIArrayString.hh>

Public Member Functions

 G4UIArrayString (const G4String &stream)
 
void Show (G4int ncol)
 
 ~G4UIArrayString ()
 

Private Member Functions

G4int CalculateColumnWidth () const
 
G4String * GetElement (G4int icol, G4int irow) const
 
G4int GetNField (G4int icol) const
 
G4int GetNRow (G4int icol) const
 

Private Attributes

G4int nColumn
 
G4int nElement
 
G4String * stringArray
 

Detailed Description

Definition at line 40 of file G4UIArrayString.hh.

Constructor & Destructor Documentation

◆ G4UIArrayString()

G4UIArrayString::G4UIArrayString ( const G4String &  stream)

Definition at line 35 of file G4UIArrayString.cc.

37{
38 nElement=0;
39 nColumn=5; // temporal assignment
40
41 G4String astream = G4StrUtil::strip_copy(stream);
42
43 // tokenize...
44 G4int indx=0;
45 while(1) {
46 G4int jc= astream.find(" ", indx);
47 nElement++;
48 if(jc == G4int(G4String::npos)) break;
49 jc++; // fix a tiny mistake...
50 for(; jc< G4int(astream.length()); ) { // skip continuing spaces
51 if(astream[(size_t)(jc)]==' ') jc++;
52 else break;
53 }
54 indx= jc;
55 }
56
57 // allocate string array
59
60 // push...
61 indx=0;
62 for(G4int i=0; i<nElement; i++){
63 G4int jc= astream.find(" ", indx);
64 if(jc != G4int(G4String::npos))
65 stringArray[i]= astream.substr(indx, jc-indx);
66 else { // last token
67 jc= astream.length()+1;
68 stringArray[i]= astream.substr(indx, jc-indx);
69 }
70 for(G4int j=1; jc+j< G4int(astream.length()); j++ ) { // skip continuing spaces
71 if(astream[jc+j]==' ') jc++;
72 else break;
73 }
74 indx= jc+1;
75 }
76}
int G4int
Definition: G4Types.hh:85
G4String * stringArray
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.

References nColumn, nElement, stringArray, and G4StrUtil::strip_copy().

◆ ~G4UIArrayString()

G4UIArrayString::~G4UIArrayString ( )

Definition at line 79 of file G4UIArrayString.cc.

81{
82 delete [] stringArray;
83}

References stringArray.

Member Function Documentation

◆ CalculateColumnWidth()

int G4UIArrayString::CalculateColumnWidth ( ) const
private

Definition at line 137 of file G4UIArrayString.cc.

139{
140 G4int totalWidth= 0;
141
142 for(G4int ix=1; ix<= nColumn; ix++) {
143 totalWidth+= GetNField(ix);
144 }
145
146 const G4int nwSpace= 2;
147 totalWidth+= (nColumn-1)*nwSpace; // for space
148
149 return totalWidth;
150}
G4int GetNField(G4int icol) const

References GetNField(), and nColumn.

Referenced by Show().

◆ GetElement()

G4String * G4UIArrayString::GetElement ( G4int  icol,
G4int  irow 
) const
private

Definition at line 86 of file G4UIArrayString.cc.

88{
89 if( !(icol>=1 && irow>=1)) // offset of column/row is "1".
90 G4cerr << "G4UIArrayString: overrange" << G4endl;
91 if(icol>nColumn) G4cerr << "G4UIArrayString: overrange" << G4endl;
92
93 G4int jq= (irow-1)*nColumn + icol;
94 if(jq> nElement) G4cerr << "G4UIArrayString: overrange" << G4endl;
95
96 jq--;
97 return &stringArray[jq];
98}
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57

References G4cerr, and G4endl.

Referenced by Show().

◆ GetNField()

G4int G4UIArrayString::GetNField ( G4int  icol) const
private

Definition at line 116 of file G4UIArrayString.cc.

118{
119 G4int maxWidth=0;
120 for (G4int iy=1; iy<= GetNRow(icol); iy++) {
121 G4int ilen= GetElement(icol,iy)-> length();
122 // care for color code
123 // if(GetElement(icol,iy)-> index(strESC,0) != G4String::npos) {
124 // if(strESC == (*GetElement(icol,iy))[0] ) {
125 const char tgt = (*GetElement(icol,iy))[(size_t)0];
126 if(strESC == tgt) {
127 ilen-= 5;
128 if(ilen<0) G4cout << "length(c) cal. error." << G4endl;
129 }
130 if(ilen> maxWidth) maxWidth= ilen;
131 }
132
133 return maxWidth;
134}
static const char strESC
G4GLOB_DLL std::ostream G4cout
G4String * GetElement(G4int icol, G4int irow) const
G4int GetNRow(G4int icol) const

References G4cout, G4endl, and strESC.

Referenced by CalculateColumnWidth(), and Show().

◆ GetNRow()

G4int G4UIArrayString::GetNRow ( G4int  icol) const
private

Definition at line 101 of file G4UIArrayString.cc.

103{
104 G4int ni;
105 if(nElement%nColumn ==0) ni= nElement/nColumn;
106 else ni= nElement/nColumn + 1;
107
109 if(nn==0) nn= nColumn;
110
111 if(icol<= nn) return ni;
112 else return ni-1;
113}

References G4InuclParticleNames::nn.

Referenced by Show().

◆ Show()

void G4UIArrayString::Show ( G4int  ncol)

Definition at line 153 of file G4UIArrayString.cc.

155{
156 // calculate #colums in need...
157 while( CalculateColumnWidth()< ncol ) {
158 nColumn++;
159 }
160 while( CalculateColumnWidth()> ncol && nColumn>1 ) {
161 nColumn--;
162 }
163
164 for(G4int iy=1; iy<= GetNRow(1); iy++) {
165 G4int nc= nColumn;
166 if(iy == GetNRow(1)) { // last row
167 nc= nElement%nColumn;
168 if(nc==0) nc= nColumn;
169 }
170 for(G4int ix=1; ix<=nc; ix++) {
171 G4String word= GetElement(ix,iy)-> data();
172
173 // care for color code
174 G4String colorWord;
175 const char tgt = word[(size_t)0];
176 if(strESC == tgt) {
177 colorWord= word.substr(0,5);
178 word.erase(0,5);
179 }
180 if(!colorWord.empty()) G4cout << colorWord << std::flush;
181
182 G4cout << std::setiosflags(std::ios::left) << std::setw(GetNField(ix))
183 << word.c_str() << std::flush;
184 // against problem w/ g++ iostream
185 if(ix != nc) G4cout << " " << std::flush;
186 else G4cout << G4endl;
187 }
188 }
189}
G4int CalculateColumnWidth() const

References CalculateColumnWidth(), G4cout, G4endl, GetElement(), GetNField(), GetNRow(), nColumn, nElement, and strESC.

Referenced by G4VUIshell::ListCommand().

Field Documentation

◆ nColumn

G4int G4UIArrayString::nColumn
private

Definition at line 44 of file G4UIArrayString.hh.

Referenced by CalculateColumnWidth(), G4UIArrayString(), and Show().

◆ nElement

G4int G4UIArrayString::nElement
private

Definition at line 43 of file G4UIArrayString.hh.

Referenced by G4UIArrayString(), and Show().

◆ stringArray

G4String* G4UIArrayString::stringArray
private

Definition at line 42 of file G4UIArrayString.hh.

Referenced by G4UIArrayString(), and ~G4UIArrayString().


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