ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIArrayString.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIArrayString.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 
29 #include <iomanip>
30 #include "G4UIArrayString.hh"
31 
32 static const char strESC= '\033';
33 
37 {
38  nElement=0;
39  nColumn=5; // temporal assignment
40 
41  G4String tmpstr= stream; // G4String::strip() CONST !!
42  G4String astream= tmpstr.strip(G4String::both);
43 
44  // tokenize...
45  G4int indx=0;
46  while(1) {
47  G4int jc= astream.index(" ", indx);
48  nElement++;
49  if(jc == G4int(G4String::npos)) break;
50  jc++; // fix a tiny mistake...
51  for(; jc< G4int(astream.length()); ) { // skip continuing spaces
52  if(astream[(size_t)(jc)]==' ') jc++;
53  else break;
54  }
55  indx= jc;
56  }
57 
58  // allocate string array
60 
61  // push...
62  indx=0;
63  for(G4int i=0; i<nElement; i++){
64  G4int jc= astream.index(" ", indx);
65  if(jc != G4int(G4String::npos))
66  stringArray[i]= astream(indx, jc-indx);
67  else { // last token
68  jc= astream.length()+1;
69  stringArray[i]= astream(indx, jc-indx);
70  }
71  for(G4int j=1; jc+j< G4int(astream.length()); j++ ) { // skip continuing spaces
72  if(astream(jc+j)==' ') jc++;
73  else break;
74  }
75  indx= jc+1;
76  }
77 }
78 
82 {
83  delete [] stringArray;
84 }
85 
89 {
90  if( !(icol>=1 && irow>=1)) // offset of column/row is "1".
91  G4cerr << "G4UIArrayString: overrange" << G4endl;
92  if(icol>nColumn) G4cerr << "G4UIArrayString: overrange" << G4endl;
93 
94  G4int jq= (irow-1)*nColumn + icol;
95  if(jq> nElement) G4cerr << "G4UIArrayString: overrange" << G4endl;
96 
97  jq--;
98  return &stringArray[jq];
99 }
100 
104 {
105  G4int ni;
106  if(nElement%nColumn ==0) ni= nElement/nColumn;
107  else ni= nElement/nColumn + 1;
108 
109  G4int nn= nElement%nColumn;
110  if(nn==0) nn= nColumn;
111 
112  if(icol<= nn) return ni;
113  else return ni-1;
114 }
115 
119 {
120  G4int maxWidth=0;
121  for (G4int iy=1; iy<= GetNRow(icol); iy++) {
122  G4int ilen= GetElement(icol,iy)-> length();
123  // care for color code
124  // if(GetElement(icol,iy)-> index(strESC,0) != G4String::npos) {
125  // if(strESC == (*GetElement(icol,iy))[0] ) {
126  const char tgt = (*GetElement(icol,iy))[(size_t)0];
127  if(strESC == tgt) {
128  ilen-= 5;
129  if(ilen<0) G4cout << "length(c) cal. error." << G4endl;
130  }
131  if(ilen> maxWidth) maxWidth= ilen;
132  }
133 
134  return maxWidth;
135 }
136 
140 {
141  G4int totalWidth= 0;
142 
143  for(G4int ix=1; ix<= nColumn; ix++) {
144  totalWidth+= GetNField(ix);
145  }
146 
147  const G4int nwSpace= 2;
148  totalWidth+= (nColumn-1)*nwSpace; // for space
149 
150  return totalWidth;
151 }
152 
156 {
157  // calculate #colums in need...
158  while( CalculateColumnWidth()< ncol ) {
159  nColumn++;
160  }
161  while( CalculateColumnWidth()> ncol && nColumn>1 ) {
162  nColumn--;
163  }
164 
165  for(G4int iy=1; iy<= GetNRow(1); iy++) {
166  G4int nc= nColumn;
167  if(iy == GetNRow(1)) { // last row
168  nc= nElement%nColumn;
169  if(nc==0) nc= nColumn;
170  }
171  for(G4int ix=1; ix<=nc; ix++) {
172  G4String word= GetElement(ix,iy)-> data();
173 
174  // care for color code
175  G4String colorWord;
176  //if(word.index(strESC,0) != G4String::npos) {
177  //if(strESC == word[0]) {
178  const char tgt = word[(size_t)0];
179  if(strESC == tgt) {
180  colorWord= word(0,5);
181  word.erase(0,5);
182  }
183  if(!colorWord.empty()) G4cout << colorWord << std::flush;
184 
185  G4cout << std::setiosflags(std::ios::left) << std::setw(GetNField(ix))
186  << word.c_str() << std::flush;
187  // against problem w/ g++ iostream
188  if(ix != nc) G4cout << " " << std::flush;
189  else G4cout << G4endl;
190  }
191  }
192 }
193