COPASI API  4.16.103
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
CExperimentFileInfo Class Reference

#include <CExperimentFileInfo.h>

Collaboration diagram for CExperimentFileInfo:
Collaboration graph
[legend]

Classes

class  CExperimentInfo
 

Public Member Functions

bool adjustForEmptyLines (size_t &First, size_t &Last)
 
 CExperimentFileInfo (CExperimentSet &set)
 
CExperimentgetExperiment (const std::string &name)
 
std::vector< std::string > getExperimentNames () const
 
const std::string & getFileName () const
 
bool getFirstUnusedSection (size_t &First, size_t &Last)
 
bool getNextUnusedSection (size_t &First, size_t &Last)
 
bool setFileName (const std::string &fileName)
 
bool sync ()
 
bool validate () const
 
bool validateFirst (const size_t &index, const size_t &value)
 
bool validateHeader (const size_t &index, const size_t &value)
 
bool validateLast (const size_t &index, const size_t &value)
 
 ~CExperimentFileInfo ()
 

Private Member Functions

 CExperimentFileInfo ()
 

Private Attributes

std::vector< size_t > mEmptyLines
 
std::string mFileName
 
size_t mLines
 
std::vector< CExperimentInfo * > mList
 
CExperimentSetmpSet
 
size_t mUsedEnd
 

Detailed Description

Definition at line 30 of file CExperimentFileInfo.h.

Constructor & Destructor Documentation

CExperimentFileInfo::CExperimentFileInfo ( )
private

Definition at line 28 of file CExperimentFileInfo.cpp.

28  :
29  mpSet(NULL),
30  mFileName(""),
31  mList(),
32  mLines(0),
34  mEmptyLines()
35 {}
std::vector< CExperimentInfo * > mList
#define C_INVALID_INDEX
Definition: copasi.h:222
std::vector< size_t > mEmptyLines
CExperimentSet * mpSet
CExperimentFileInfo::CExperimentFileInfo ( CExperimentSet set)

Definition at line 37 of file CExperimentFileInfo.cpp.

37  :
38  mpSet(&set),
39  mFileName(""),
40  mList(),
41  mLines(0),
43  mEmptyLines()
44 {}
std::vector< CExperimentInfo * > mList
#define C_INVALID_INDEX
Definition: copasi.h:222
std::vector< size_t > mEmptyLines
CExperimentSet * mpSet
CExperimentFileInfo::~CExperimentFileInfo ( )

Definition at line 46 of file CExperimentFileInfo.cpp.

References mList, and pdelete.

47 {
48  size_t i, imax;
49 
50  for (i = 0, imax = mList.size(); i < imax; i++)
51  pdelete(mList[i]);
52 
53  mList.clear();
54 }
#define pdelete(p)
Definition: copasi.h:215
std::vector< CExperimentInfo * > mList

Member Function Documentation

bool CExperimentFileInfo::adjustForEmptyLines ( size_t &  First,
size_t &  Last 
)

Definition at line 270 of file CExperimentFileInfo.cpp.

References getNextUnusedSection(), mEmptyLines, and mUsedEnd.

Referenced by getNextUnusedSection().

272 {
273  std::vector<size_t>::const_iterator it = mEmptyLines.begin();
274  std::vector<size_t>::const_iterator end = mEmptyLines.end();
275 
276  while (it != end && *it < First) ++it;
277 
278  if (it == end)
279  return true;
280 
281  if (it != end && *it == First)
282  {
283  if (First == Last)
284  return getNextUnusedSection(First, Last);
285 
286  First++;
287  return adjustForEmptyLines(First, Last);
288  }
289 
290  if (*it <= Last)
291  {
292  Last = *it - 1;
293  mUsedEnd = Last;
294  }
295 
296  return true;
297 }
bool adjustForEmptyLines(size_t &First, size_t &Last)
std::vector< size_t > mEmptyLines
bool getNextUnusedSection(size_t &First, size_t &Last)
CExperiment * CExperimentFileInfo::getExperiment ( const std::string &  name)

Definition at line 214 of file CExperimentFileInfo.cpp.

References mList.

Referenced by CQExperimentData::slotCheckFrom(), CQExperimentData::slotExperimentChanged(), and CQExperimentData::slotExperimentDelete().

215 {
216  size_t i, imax;
217 
218  for (i = 0, imax = mList.size(); i < imax; i++)
219  if (mList[i]->pExperiment->getObjectName() == name)
220  return mList[i]->pExperiment;
221 
222  return NULL;
223 }
std::vector< CExperimentInfo * > mList
std::vector< std::string > CExperimentFileInfo::getExperimentNames ( ) const

Definition at line 202 of file CExperimentFileInfo.cpp.

References mList.

Referenced by CQExperimentData::slotFileChanged(), and CQExperimentData::syncExperiments().

203 {
204  std::vector< std::string > List;
205 
206  size_t i, imax;
207 
208  for (i = 0, imax = mList.size(); i < imax; i++)
209  List.push_back(mList[i]->pExperiment->getObjectName());
210 
211  return List;
212 }
std::vector< CExperimentInfo * > mList
const std::string & CExperimentFileInfo::getFileName ( ) const

Definition at line 111 of file CExperimentFileInfo.cpp.

References mFileName.

Referenced by CQExperimentData::slotExperimentAdd().

112 {return mFileName;}
bool CExperimentFileInfo::getFirstUnusedSection ( size_t &  First,
size_t &  Last 
)
bool CExperimentFileInfo::getNextUnusedSection ( size_t &  First,
size_t &  Last 
)

Definition at line 233 of file CExperimentFileInfo.cpp.

References adjustForEmptyLines(), C_INVALID_INDEX, mLines, mList, and mUsedEnd.

Referenced by adjustForEmptyLines(), getFirstUnusedSection(), and CQExperimentDataValidator::validate().

235 {
236  First = mUsedEnd + 1;
237 
238  size_t i, imax = mList.size();
239 
240  for (i = 0; i < imax; i++)
241  {
242  if (First < mList[i]->First)
243  {
244  Last = mList[i]->First - 1;
245  mUsedEnd = Last;
246 
247  return adjustForEmptyLines(First, Last);
248  }
249 
250  if (mList[i]->Last + 1 > First)
251  First = mList[i]->Last + 1;
252  }
253 
254  if (First < mLines)
255  {
256  Last = mLines;
257  mUsedEnd = Last;
258 
259  return adjustForEmptyLines(First, Last);
260  }
261 
262  First = C_INVALID_INDEX;
263  Last = C_INVALID_INDEX;
264 
265  mUsedEnd = mLines;
266 
267  return false;
268 }
std::vector< CExperimentInfo * > mList
#define C_INVALID_INDEX
Definition: copasi.h:222
bool adjustForEmptyLines(size_t &First, size_t &Last)
bool CExperimentFileInfo::setFileName ( const std::string &  fileName)

Definition at line 56 of file CExperimentFileInfo.cpp.

References CLocaleString::fromUtf8(), mEmptyLines, mFileName, mLines, and sync().

Referenced by CQExperimentData::slotFileChanged().

57 {
58  mFileName = fileName;
59  mLines = 0;
60  mEmptyLines.clear();
61 
62  std::ifstream in;
63  in.open(CLocaleString::fromUtf8(mFileName).c_str(), std::ios::binary);
64 
65  if (in.fail()) // File can not be opened.
66  {
67  mLines = 0;
68  return sync();
69  }
70 
71  bool isEmpty;
72 
73  // forwind to count lines in file
74  while (!in.eof())
75  {
76  isEmpty = true;
77  char c;
78 
79  for (in.get(c); c != 0x0a && c != 0x0d; in.get(c))
80  {
81  if (in.fail() || in.eof()) break;
82 
83  switch (c)
84  {
85  case '\x20':
86  case '\x09':
87  case '\x0d':
88  case '\x0a':
89  break;
90 
91  default:
92  isEmpty = false;
93  break;
94  }
95  }
96 
97  // Eat additional line break characters appearing on DOS and Mac text format;
98  if ((c == 0x0d && in.peek() == 0x0a) || // DOS
99  (c == 0x0a && in.peek() == 0x0d)) // Mac
100  in.ignore(1);
101 
102  mLines++;
103 
104  if (isEmpty)
105  mEmptyLines.push_back(mLines);
106  }
107 
108  return sync();
109 }
std::vector< size_t > mEmptyLines
static CLocaleString fromUtf8(const std::string &utf8)
bool CExperimentFileInfo::sync ( )

Definition at line 114 of file CExperimentFileInfo.cpp.

References C_INVALID_INDEX, CExperimentSet::getExperiment(), CExperimentSet::getExperimentCount(), CExperiment::getFileName(), mFileName, mList, mpSet, mUsedEnd, pdelete, CExperimentSet::sort(), and validate().

Referenced by CQExperimentData::saveExperiment(), setFileName(), CQExperimentData::slotExperimentAdd(), CQExperimentData::syncExperiments(), and CQExperimentDataValidator::validate().

115 {
116  mpSet->sort();
117 
118  size_t i, imax;
119 
120  for (i = 0, imax = mList.size(); i < imax; i++)
121  pdelete(mList[i]);
122 
123  mList.clear();
124 
125  // Find the desired file name
126  for (i = 0, imax = mpSet->getExperimentCount(); i < imax; i++)
127  if (mpSet->getExperiment(i)->getFileName() == mFileName) break;
128 
129  // Continue as long as the file name does not change
130  for (; i < imax; i++)
131  {
132  if (mpSet->getExperiment(i)->getFileName() != mFileName) break;
133 
134  mList.push_back(new CExperimentInfo(*mpSet->getExperiment(i)));
135  }
136 
138 
139  return validate();
140 }
const std::string & getFileName() const
#define pdelete(p)
Definition: copasi.h:215
std::vector< CExperimentInfo * > mList
#define C_INVALID_INDEX
Definition: copasi.h:222
CExperiment * getExperiment(const size_t &index)
CExperimentSet * mpSet
size_t getExperimentCount() const
bool CExperimentFileInfo::validate ( ) const

Definition at line 142 of file CExperimentFileInfo.cpp.

References mLines, and mList.

Referenced by sync(), validateFirst(), and validateLast().

143 {
144  size_t Last = 0;
145  size_t i, imax;
146 
147  for (i = 0, imax = mList.size(); i < imax; i++)
148  {
149  if (Last >= mList[i]->First) return false;
150 
151  Last = mList[i]->Last;
152 
153  if (Last > mLines) return false;
154  }
155 
156  return true;
157 }
std::vector< CExperimentInfo * > mList
bool CExperimentFileInfo::validateFirst ( const size_t &  index,
const size_t &  value 
)

Definition at line 159 of file CExperimentFileInfo.cpp.

References mLines, mList, and validate().

Referenced by CQExperimentDataValidator::validate().

161 {
162  if (mLines < value ||
163  mList[index]->Last < value ||
164  (value == mList[index]->Last &&
165  value == mList[index]->pExperiment->getHeaderRow())) return false;
166 
167  size_t Saved = mList[index]->First;
168  mList[index]->First = value;
169 
170  bool Result = validate();
171  mList[index]->First = Saved;
172 
173  return Result;
174 }
std::vector< CExperimentInfo * > mList
bool CExperimentFileInfo::validateHeader ( const size_t &  index,
const size_t &  value 
)

Definition at line 193 of file CExperimentFileInfo.cpp.

References mLines, and mList.

Referenced by CQExperimentDataValidator::validate().

195 {
196  return (value <= mLines &&
197  (mList[index]->First < mList[index]->Last ||
198  value < mList[index]->First ||
199  mList[index]->Last < value));
200 }
std::vector< CExperimentInfo * > mList
bool CExperimentFileInfo::validateLast ( const size_t &  index,
const size_t &  value 
)

Definition at line 176 of file CExperimentFileInfo.cpp.

References mLines, mList, and validate().

Referenced by CQExperimentDataValidator::validate().

178 {
179  if (mLines < value ||
180  value < mList[index]->First ||
181  (value == mList[index]->First &&
182  value == mList[index]->pExperiment->getHeaderRow())) return false;
183 
184  size_t Saved = mList[index]->Last;
185  mList[index]->Last = value;
186 
187  bool Result = validate();
188  mList[index]->Last = Saved;
189 
190  return Result;
191 }
std::vector< CExperimentInfo * > mList

Member Data Documentation

std::vector< size_t > CExperimentFileInfo::mEmptyLines
private

Definition at line 188 of file CExperimentFileInfo.h.

Referenced by adjustForEmptyLines(), and setFileName().

std::string CExperimentFileInfo::mFileName
private

Definition at line 168 of file CExperimentFileInfo.h.

Referenced by getFileName(), setFileName(), and sync().

size_t CExperimentFileInfo::mLines
private
std::vector< CExperimentInfo * > CExperimentFileInfo::mList
private
CExperimentSet* CExperimentFileInfo::mpSet
private

Definition at line 163 of file CExperimentFileInfo.h.

Referenced by sync().

size_t CExperimentFileInfo::mUsedEnd
private

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