COPASI API  4.16.103
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
CTableRow Class Reference

#include <CTableCell.h>

Collaboration diagram for CTableRow:
Collaboration graph
[legend]

Public Member Functions

 CTableRow (const size_t &size=0, const char &separator= '\t')
 
 CTableRow (const CTableRow &src)
 
const std::vector< CTableCell > & getCells () const
 
const size_t & getLastFilledCell () const
 
size_t guessColumnNumber (std::istream &is, const bool &rewind)
 
const bool & isEmpty () const
 
bool resize (const size_t &size)
 
size_t size () const
 
 ~CTableRow ()
 

Private Member Functions

std::istream & readLine (std::istream &is)
 

Private Attributes

std::vector< CTableCellmCells
 
bool mIsEmpty
 
size_t mLastFilledCell
 
char mSeparator
 

Friends

std::istream & operator>> (std::istream &is, CTableRow &cell)
 

Detailed Description

Definition at line 109 of file CTableCell.h.

Constructor & Destructor Documentation

CTableRow::CTableRow ( const size_t &  size = 0,
const char &  separator = '\t' 
)

Default constructor

Parameters
constunisgned C_INT32 & size (default: 0)
constchar & separator (default: '')

Definition at line 124 of file CTableCell.cpp.

References resize().

125  :
126  mCells(0),
127  mSeparator(separator),
128  mIsEmpty(true),
130 {resize(size);}
char mSeparator
Definition: CTableCell.h:195
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
#define C_INVALID_INDEX
Definition: copasi.h:222
bool mIsEmpty
Definition: CTableCell.h:197
size_t size() const
Definition: CTableCell.cpp:157
size_t mLastFilledCell
Definition: CTableCell.h:199
bool resize(const size_t &size)
Definition: CTableCell.cpp:144
CTableRow::CTableRow ( const CTableRow src)

Copy constructor

Parameters
constCTableRow & src

Definition at line 132 of file CTableCell.cpp.

132  :
133  mCells(src.mCells),
134  mSeparator(src.mSeparator),
135  mIsEmpty(src.mIsEmpty),
137 {}
char mSeparator
Definition: CTableCell.h:195
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
#define C_INVALID_INDEX
Definition: copasi.h:222
bool mIsEmpty
Definition: CTableCell.h:197
size_t mLastFilledCell
Definition: CTableCell.h:199
CTableRow::~CTableRow ( )

Destructor

Definition at line 139 of file CTableCell.cpp.

139 {}

Member Function Documentation

const std::vector< CTableCell > & CTableRow::getCells ( ) const

Retrieve the cells.

Returns
const std::vector< CTableCell > & cells

Definition at line 141 of file CTableCell.cpp.

References mCells.

Referenced by CExperiment::read(), and CExperiment::readColumnNames().

142 {return mCells;}
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
const size_t & CTableRow::getLastFilledCell ( ) const

Retrieve the index of the last non empty cell in the last read operation. size_t & lastFilledCell

Definition at line 160 of file CTableCell.cpp.

References mLastFilledCell.

161 {return mLastFilledCell;}
size_t mLastFilledCell
Definition: CTableCell.h:199
size_t CTableRow::guessColumnNumber ( std::istream &  is,
const bool &  rewind 
)

Try to guess the number of columns in the current line

Parameters
std::istream&is
constbool & rewind
Returns
size_t numColumns

Definition at line 163 of file CTableCell.cpp.

References C_INVALID_INDEX, isEmpty(), and mCells.

Referenced by CExperiment::guessColumnNumber().

165 {
166  std::istream::pos_type pos;
167 
168  if (rewind) pos = is.tellg();
169 
170  is >> *this;
171 
172  if (rewind) is.seekg(pos);
173 
174  size_t count;
175 
176  for (count = mCells.size() - 1; count != C_INVALID_INDEX; count--)
177  if (!mCells[count].isEmpty()) break;
178 
179  return count + 1;
180 }
const bool & isEmpty() const
Definition: CTableCell.cpp:182
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
#define C_INVALID_INDEX
Definition: copasi.h:222
const bool & CTableRow::isEmpty ( ) const

Check whether row contains any cells with data A row is considered empty when it all cells are empty.

Definition at line 182 of file CTableCell.cpp.

References mIsEmpty.

Referenced by guessColumnNumber().

182 {return mIsEmpty;}
bool mIsEmpty
Definition: CTableCell.h:197
std::istream & CTableRow::readLine ( std::istream &  is)
private

Fill the row with data from the inpute stream until End_Of_Line is encountered and advance the stream accordingly.

Parameters
std::istream& is
Returns
std::istream & is

Definition at line 184 of file CTableCell.cpp.

References C_INT, C_INVALID_INDEX, mCells, mIsEmpty, mLastFilledCell, and mSeparator.

Referenced by operator>>().

185 {
186  // Clear the line;
187  std::stringstream line;
188 
189  char c;
190 
191  for (is.get(c); c != 0x0a && c != 0x0d; is.get(c))
192  {
193  if (is.fail() || is.eof()) break;
194 
195  line.put(c);
196  }
197 
198  // Eat additional line break characters appearing on DOS and Mac text format;
199  if ((c == 0x0d && is.peek() == 0x0a) || // DOS
200  (c == 0x0a && is.peek() == 0x0d)) // Mac
201  is.ignore(1);
202 
203  mIsEmpty = true;
205 
206  std::vector< CTableCell >::iterator it = mCells.begin();
207  std::vector< CTableCell >::iterator end = mCells.end();
208 
209  unsigned C_INT count;
210 
211  for (count = 0; it != end && !line.fail(); ++it, ++count)
212  {
213  line >> *it;
214 
215  if (!it->isEmpty())
216  {
217  mIsEmpty = false;
218  mLastFilledCell = count;
219  }
220  }
221 
222  bool Finished = false;
223 
224  if (it == end)
225  Finished = true;
226 
227  CTableCell Unread(mSeparator);
228 
229  while (!line.fail() && !line.eof())
230  {
231  mCells.push_back(Unread);
232  line >> mCells.back();
233 
234  if (!mCells.back().isEmpty())
235  {
236  mIsEmpty = false;
237  mLastFilledCell = count;
238  }
239 
240  count++;
241  }
242 
243  if (!Finished)
244  {
245  // Missing columns are filled with default
246  for (; it != end; ++it)
247  *it = Unread;
248  }
249 
250  return is;
251 }
#define C_INT
Definition: copasi.h:115
char mSeparator
Definition: CTableCell.h:195
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
#define C_INVALID_INDEX
Definition: copasi.h:222
bool mIsEmpty
Definition: CTableCell.h:197
size_t mLastFilledCell
Definition: CTableCell.h:199
bool CTableRow::resize ( const size_t &  size)

Resize

Parameters
constsize_t & size
Returns
bool success

Definition at line 144 of file CTableCell.cpp.

References mCells, and mSeparator.

Referenced by CTableRow().

145 {
146  mCells.resize(size);
147 
148  std::vector< CTableCell >::iterator it = mCells.begin();
149  std::vector< CTableCell >::iterator end = mCells.end();
150 
151  for (; it != end; ++it)
152  it->setSeparator(mSeparator);
153 
154  return true;
155 }
char mSeparator
Definition: CTableCell.h:195
std::vector< CTableCell > mCells
Definition: CTableCell.h:193
size_t size() const
Definition: CTableCell.cpp:157
size_t CTableRow::size ( ) const

Retrieve the size of the row

Returns
const size_t size

Definition at line 157 of file CTableCell.cpp.

References mCells.

158 {return mCells.size();}
std::vector< CTableCell > mCells
Definition: CTableCell.h:193

Friends And Related Function Documentation

std::istream& operator>> ( std::istream &  is,
CTableRow cell 
)
friend

Formated stream input operator

Parameters
CTableRow& cell
Returns
std::istream &

Definition at line 253 of file CTableCell.cpp.

254 {return row.readLine(is);}

Member Data Documentation

std::vector< CTableCell > CTableRow::mCells
private

Definition at line 193 of file CTableCell.h.

Referenced by getCells(), guessColumnNumber(), readLine(), resize(), and size().

bool CTableRow::mIsEmpty
private

Definition at line 197 of file CTableCell.h.

Referenced by isEmpty(), and readLine().

size_t CTableRow::mLastFilledCell
private

Definition at line 199 of file CTableCell.h.

Referenced by getLastFilledCell(), and readLine().

char CTableRow::mSeparator
private

Definition at line 195 of file CTableCell.h.

Referenced by readLine(), and resize().


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