COPASI API  4.16.103
Functions
CTableCell.cpp File Reference
#include <limits>
#include <iostream>
#include <sstream>
#include <string.h>
#include <stdlib.h>
#include "copasi.h"
#include "CTableCell.h"
#include "utilities/utility.h"
Include dependency graph for CTableCell.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

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

Formated stream input operator

Parameters
CTableCell& cell
Returns
std::istream &

Definition at line 61 of file CTableCell.cpp.

References CTableCell::mIsEmpty, CTableCell::mIsValue, CTableCell::mName, CTableCell::mSeparator, CTableCell::mValue, and strToDouble().

62 {
63  static char buffer[256];
64 
65  cell.mName = "";
66 
67  do
68  {
69  is.clear();
70  is.getline(buffer, 256, cell.mSeparator);
71  cell.mName += buffer;
72  }
73  while (strlen(buffer) == 255 && !is.eof());
74 
75  /* Trim leading and trailing whitespaces from the string */
76  std::string::size_type begin = cell.mName.find_first_not_of("\x20\x09\x0d\x0a");
77 
78  if (begin == std::string::npos)
79  {
80  cell.mName = "";
81  cell.mIsValue = false;
82  cell.mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
83  cell.mIsEmpty = true;
84 
85  return is;
86  }
87 
88  std::string::size_type end = cell.mName.find_last_not_of("\x20\x09\x0d\x0a");
89 
90  if (end == std::string::npos)
91  cell.mName = cell.mName.substr(begin);
92  else
93  cell.mName = cell.mName.substr(begin, end - begin + 1);
94 
95  cell.mIsEmpty = false;
96 
97  /* Try to convert the string into a number */
98  const char * Tail = NULL;
99  cell.mValue = strToDouble(cell.mName.c_str(), & Tail);
100 
101  if (Tail != NULL && *Tail == 0x0)
102  {
103  cell.mIsValue = true;
104  }
105  else if (cell.mName == "INF")
106  {
107  cell.mIsValue = true;
108  cell.mValue = std::numeric_limits<C_FLOAT64>::infinity();
109  }
110  else if (cell.mName == "-INF")
111  {
112  cell.mIsValue = true;
113  cell.mValue = - std::numeric_limits<C_FLOAT64>::infinity();
114  }
115  else
116  {
117  cell.mIsValue = false;
118  cell.mValue = std::numeric_limits<C_FLOAT64>::quiet_NaN();
119  }
120 
121  return is;
122 }
bool mIsEmpty
Definition: CTableCell.h:106
std::string mName
Definition: CTableCell.h:100
char mSeparator
Definition: CTableCell.h:98
bool mIsValue
Definition: CTableCell.h:104
C_FLOAT64 mValue
Definition: CTableCell.h:102
double strToDouble(const char *str, char const **pTail)
Definition: utility.cpp:325
std::istream& operator>> ( std::istream &  is,
CTableRow row 
)

Formated stream input operator

Parameters
CTableRow& cell
Returns
std::istream &

Definition at line 253 of file CTableCell.cpp.

References CTableRow::readLine().

254 {return row.readLine(is);}
std::istream & readLine(std::istream &is)
Definition: CTableCell.cpp:184