Changeset 2849 in Sophya for trunk/SophyaLib/HiStats/basedtable.cc
- Timestamp:
- Nov 21, 2005, 12:08:55 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/basedtable.cc
r2831 r2849 3 3 #include "sopnamsp.h" 4 4 #include "pexceptions.h" 5 6 /*! 7 \class SOPHYA::DataTableRow 8 \ingroup HiStats 9 This class is intented to be used with datatable classes 10 (inheriting from BaseDataTable) for representing a row (line) 11 of the table. 12 */ 13 DataTableRow::DataTableRow( vector<string>& colnames ) 14 { 15 if (colnames.size() < 1) 16 throw ParmError("DataTableRow::DataTableRow(vector<string>& cn) cn.size()==0 "); 17 size_ = colnames.size(); 18 mtv_ = new MuTyV[ size_ ]; 19 for(sa_size_t k=0; k<size_; k++) 20 nm2idx_[colnames[k]] = k; 21 } 22 23 DataTableRow::DataTableRow(DataTableRow const & a ) 24 { 25 size_ = a.size_; 26 mtv_ = new MuTyV[ size_ ]; 27 nm2idx_ = a.nm2idx_; 28 } 29 30 MuTyV DataTableRow::get(string const& colname) const 31 { 32 map<string, sa_size_t>::const_iterator it = nm2idx_.find(colname); 33 if (it == nm2idx_.end()) { 34 string msg = "DataTableRow::get( " ; 35 msg += colname; msg += " ) Not found column name"; 36 throw NotFoundExc(msg); 37 } 38 return mtv_[(*it).second]; 39 } 40 41 MuTyV& DataTableRow::get(string const& colname) 42 { 43 map<string, sa_size_t>::const_iterator it = nm2idx_.find(colname); 44 if (it == nm2idx_.end()) { 45 string msg = "DataTableRow::get( " ; 46 msg += colname; msg += " ) const - Not found column name"; 47 throw NotFoundExc(msg); 48 } 49 return mtv_[(*it).second]; 50 } 51 52 ostream& DataTableRow::Print(ostream& os) const 53 { 54 for(sa_size_t k=0; k<size_; k++) 55 os << (string)mtv_[k] << " "; 56 return os; 57 } 5 58 6 59 /*! … … 143 196 } 144 197 198 // Retourne une structure 199 /*! 200 The returned BaseDataTable object can be used for subsequent call to 201 AddRow() or GetRow() methods. 202 Generate an exception if called for a table with no columns 203 */ 204 DataTableRow BaseDataTable::EmptyRow() 205 { 206 if (NCols == 0) 207 throw ParmError("BaseDataTable::EmptyRow() Table has no column !"); 208 vector<string> nms; 209 for(sa_size_t k=0; k<NVar(); k++) nms.push_back(mNames[k].nom); 210 return DataTableRow(nms); 211 } 212 145 213 // 146 214 // A quel index correspond mon nom ? … … 162 230 } 163 231 164 //! Adds a line (or row to the table)with r_8* inout data232 //! Adds a row (or line) to the table with r_8* inout data 165 233 /*! 166 234 The data to be added is provided as an array (vector) of double (r_8). … … 171 239 (data[k] k=0..NbColumns()) 172 240 */ 173 sa_size_t BaseDataTable::Add Line(const r_8* data)241 sa_size_t BaseDataTable::AddRow(const r_8* data) 174 242 { 175 243 if (NVar() == 0) 176 throw ParmError("BaseDataTable::Add Line(const r_8*) Table has no column !");244 throw ParmError("BaseDataTable::AddRow(const r_8*) Table has no column !"); 177 245 if (NEntry() == SegmentSize()*NbSegments()) Extend(); 178 246 sa_size_t n = NEntry(); … … 198 266 } 199 267 200 //! Adds a line (or row to the table)with input data as an array of MuTyV268 //! Adds a row (or line) to the table with input data as an array of MuTyV 201 269 /*! 202 270 The data to be added is provided as an array (vector) of MuTyV. … … 207 275 (data[k] k=0..NbColumns()) 208 276 */ 209 sa_size_t BaseDataTable::Add Line(const MuTyV* data)277 sa_size_t BaseDataTable::AddRow(const MuTyV* data) 210 278 { 211 279 if (NVar() == 0) 212 throw ParmError("BaseDataTable::Add Line(const MuTyV*) Table has no column !");280 throw ParmError("BaseDataTable::AddRow(const MuTyV*) Table has no column !"); 213 281 if (NEntry() == SegmentSize()*NbSegments()) Extend(); 214 282 sa_size_t n = NEntry(); … … 235 303 return mNEnt; 236 304 } 237 305 //! Adds a row (or line) to the table with input data as DataTableRow object 306 /*! 307 The internal MuTyV array of the object contains the date and the 308 MuTyV class conversion operators are used to match against each 309 cell data type. 310 Only the size of the input data object is checked. 311 Return the new number of table rows (lines / entries) 312 \param data : Data for each cell of the row to be appended 313 (data[k] k=0..NbColumns()) 314 */ 315 sa_size_t BaseDataTable::AddRow(DataTableRow const& data) 316 { 317 if ( data.Size() != NCols() ) 318 throw SzMismatchError(" BaseDataTable::AddRow() - data.Size() != NCols() "); 319 return AddRow(data.MTVPtr()); 320 } 321 322 /*! 323 Extends the table (in the row direction). This method is called automatically when needed. 324 */ 238 325 sa_size_t BaseDataTable::Extend() 239 326 { … … 256 343 } 257 344 258 259 MuTyV* BaseDataTable::GetLine(sa_size_t n) const 345 /*! 346 Fills the input \b row object with the content of row \b n. 347 Return a reference to the input \b row object. 348 Generate an exception if the input \b row object has the wrong size. 349 This method is slower(less efficient) than the GetRow(n) method. 350 */ 351 DataTableRow& BaseDataTable::GetRow(sa_size_t n, DataTableRow& row) const 352 { 353 if ( row.Size() != NCols() ) 354 throw SzMismatchError(" BaseDataTable::GetRow(n, row) - row.Size() != NCols() "); 355 MuTyV* rmtv = GetRow(n); 356 for(sa_size_t k=0; k<NCols(); k++) 357 row[k] = rmtv[k]; 358 return row; 359 } 360 361 MuTyV* BaseDataTable::GetRow(sa_size_t n) const 260 362 { 261 363 if ((n < 0) || (n >= NEntry())) 262 throw RangeCheckError("BaseDataTable::Get Line() out of range line index n");364 throw RangeCheckError("BaseDataTable::GetRow() out of range line index n"); 263 365 if (mVarMTV == NULL) mVarMTV = new MuTyV[NVar()]; 264 366 … … 345 447 } 346 448 for(sa_size_t kk=0; kk<a.NEntry(); kk++) 347 Add Line(a.GetLine(kk));449 AddRow(a.GetLine(kk)); 348 450 } 349 451 … … 456 558 } 457 559 } 458 Add Line(mVarMTV);560 AddRow(mVarMTV); 459 561 nl++; 460 562 }
Note:
See TracChangeset
for help on using the changeset viewer.