Ignore:
Timestamp:
Nov 21, 2005, 12:08:55 PM (20 years ago)
Author:
ansari
Message:

Ajout de la classe DataTableRow , modifs/ajout interface BaseDataTable - Reza 21/11/2005

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/HiStats/basedtable.cc

    r2831 r2849  
    33#include "sopnamsp.h"
    44#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*/
     13DataTableRow::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
     23DataTableRow::DataTableRow(DataTableRow const & a )
     24{
     25  size_ = a.size_;
     26  mtv_ = new MuTyV[ size_ ];
     27  nm2idx_ = a.nm2idx_;
     28}
     29
     30MuTyV 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
     41MuTyV& 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
     52ostream&   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}
    558
    659/*!
     
    143196}
    144197
     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*/
     204DataTableRow 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
    145213//
    146214// A quel index correspond mon nom ?
     
    162230}
    163231
    164 //! Adds a line (or row to the table) with r_8* inout data
     232//! Adds a row (or line) to the table with r_8* inout data
    165233/*!
    166234  The data to be added is provided as an array (vector) of double (r_8).
     
    171239  (data[k] k=0..NbColumns())
    172240*/
    173 sa_size_t BaseDataTable::AddLine(const r_8* data)
     241sa_size_t BaseDataTable::AddRow(const r_8* data)
    174242{
    175243  if (NVar() == 0)
    176     throw ParmError("BaseDataTable::AddLine(const r_8*) Table has no column !");
     244    throw ParmError("BaseDataTable::AddRow(const r_8*) Table has no column !");
    177245  if (NEntry() == SegmentSize()*NbSegments())  Extend();
    178246  sa_size_t n = NEntry();
     
    198266}
    199267
    200 //! Adds a line (or row to the table) with input data as an array of MuTyV
     268//! Adds a row (or line) to the table with input data as an array of MuTyV
    201269/*!
    202270  The data to be added is provided as an array (vector) of MuTyV.
     
    207275  (data[k] k=0..NbColumns())
    208276*/
    209 sa_size_t BaseDataTable::AddLine(const MuTyV* data)
     277sa_size_t BaseDataTable::AddRow(const MuTyV* data)
    210278{
    211279  if (NVar() == 0)
    212     throw ParmError("BaseDataTable::AddLine(const MuTyV*) Table has no column !");
     280    throw ParmError("BaseDataTable::AddRow(const MuTyV*) Table has no column !");
    213281  if (NEntry() == SegmentSize()*NbSegments())  Extend();
    214282  sa_size_t n = NEntry();
     
    235303  return mNEnt;
    236304}
    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*/
     315sa_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*/
    238325sa_size_t BaseDataTable::Extend()
    239326{
     
    256343}
    257344
    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*/
     351DataTableRow& 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
     361MuTyV* BaseDataTable::GetRow(sa_size_t n) const
    260362{
    261363  if ((n < 0) || (n >= NEntry()))
    262     throw RangeCheckError("BaseDataTable::GetLine() out of range line index n");
     364    throw RangeCheckError("BaseDataTable::GetRow() out of range line index n");
    263365  if (mVarMTV == NULL) mVarMTV = new MuTyV[NVar()];
    264366
     
    345447  }
    346448  for(sa_size_t kk=0; kk<a.NEntry(); kk++)
    347     AddLine(a.GetLine(kk));
     449    AddRow(a.GetLine(kk));
    348450}
    349451
     
    456558        }
    457559      }
    458       AddLine(mVarMTV);
     560      AddRow(mVarMTV);
    459561      nl++;
    460562    }
Note: See TracChangeset for help on using the changeset viewer.