COPASI API  4.16.103
CProcessReport.cpp
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CProcessReport.cpp,v $
3  $Revision: 1.12 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2012/06/01 17:25:40 $
7  End CVS Header */
8 
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
16 // All rights reserved.
17 
18 #include "copasi.h"
19 
20 #include "CProcessReport.h"
21 
22 #include "CVector.h"
23 #include "CopasiTime.h"
24 
25 #include "report/CCopasiObject.h"
26 
28  CCopasiParameter("NoName", CCopasiParameter::DOUBLE),
29  mEndValue(),
30  mHasEndValue(false)
31 {
32  mEndValue = mValue;
33  mValue.pDOUBLE = NULL;
34 }
35 
36 CProcessReportItem::CProcessReportItem(const std::string & name,
37  const Type & type,
38  const void * pValue,
39  const void * pEndValue):
40  CCopasiParameter(name, type, pEndValue, NULL, "ProcessReportItem"),
41  mEndValue(),
42  mHasEndValue(pEndValue != NULL)
43 {
44  mEndValue = mValue;
45  mValue.pVOID = const_cast<void *>(pValue);
46 }
47 
49  CCopasiParameter(src.getObjectName(), src.getType(), src.mEndValue.pVOID, NULL, "ProcessReportItem"),
50  mEndValue(),
51  mHasEndValue(src.mHasEndValue)
52 {
53  mEndValue = mValue;
54  mValue = src.mValue;
55 }
56 
58 {
59  mValue = mEndValue;
60 }
61 
62 const bool & CProcessReportItem::hasEndValue() const {return mHasEndValue;}
63 
65 {return mEndValue;}
66 
68 {return mEndValue;}
69 
70 CProcessReport::CProcessReport(const unsigned int & maxTime):
71  mProcessReportItemList(1),
72  mpEndTime(NULL)
73 {
74  mProcessReportItemList[0] = NULL;
75 
76  if (maxTime > 0)
77  {
79  }
80 }
81 
83 {
84  size_t i, imax = mProcessReportItemList.size();
85 
86  for (i = 0; i < imax; i++)
88 
90 }
91 
92 size_t CProcessReport::addItem(const std::string & name,
93  const std::string & value,
94  const std::string * pEndValue)
95 {
96  return addItem(name, CCopasiParameter::STRING, &value, pEndValue);
97 }
98 
99 size_t CProcessReport::addItem(const std::string & name,
100  const C_INT32 & value,
101  const C_INT32 * pEndValue)
102 {
103  return addItem(name, CCopasiParameter::INT, &value, pEndValue);
104 }
105 
106 size_t CProcessReport::addItem(const std::string & name,
107  const unsigned C_INT32 & value,
108  const unsigned C_INT32 * pEndValue)
109 {
110  return addItem(name, CCopasiParameter::UINT, &value, pEndValue);
111 }
112 
113 size_t CProcessReport::addItem(const std::string & name,
114  const C_FLOAT64 & value,
115  const C_FLOAT64 * pEndValue)
116 {
117  return addItem(name, CCopasiParameter::DOUBLE, &value, pEndValue);
118 }
119 
120 size_t CProcessReport::addItem(const std::string & name,
121  const CCopasiParameter::Type & type,
122  const void * pValue,
123  const void * pEndValue)
124 {
125  size_t i, imax = mProcessReportItemList.size();
126 
127  for (i = 0; i < imax; i++)
128  if (mProcessReportItemList[i] == NULL) break;
129 
130  size_t handle = i;
131 
132  if (i == imax) // We need to resize.
133  {
135  mProcessReportItemList.resize(2 * imax); // Note, imax is never zero
136 
137  for (i = 0; i < imax; i++) // Copy existing items
138  mProcessReportItemList[i] = tmp[i];
139 
140  imax *= 2;
141 
142  while (i < imax) mProcessReportItemList[i++] = NULL;
143  }
144 
145  mProcessReportItemList[handle] = new CProcessReportItem(name, type, pValue, pEndValue);
146  return handle;
147 }
148 
150 {
151  bool success = true;
152  size_t i, imax = mProcessReportItemList.size();
153 
154  for (i = 0; i < imax; i++)
155  if (mProcessReportItemList[i] && !progressItem(i)) success = false;
156 
157  return success && proceed();
158 }
159 
160 bool CProcessReport::progressItem(const size_t & handle)
161 {
162  return isValidHandle(handle) && proceed();
163 }
164 
166 {
167  if (mpEndTime == NULL) return true;
168 
170 }
171 
173 {
174  bool success = true;
175  size_t i, imax = mProcessReportItemList.size();
176 
177  for (i = 0; i < imax; i++)
178  if (mProcessReportItemList[i] && !resetItem(i)) success = false;
179 
180  return success;
181 }
182 
183 bool CProcessReport::resetItem(const size_t & handle)
184 {
185  return isValidHandle(handle) && proceed();
186 }
187 
189 {
190  bool success = true;
191  size_t i, imax = mProcessReportItemList.size();
192 
193  for (i = 0; i < imax; i++)
194  if (mProcessReportItemList[i] && !finishItem(i)) success = false;
195 
196  return success;
197 }
198 
199 bool CProcessReport::finishItem(const size_t & handle)
200 {
201  if (!isValidHandle(handle)) return false;
202 
204  return true;
205 }
206 
207 bool CProcessReport::isValidHandle(const size_t handle) const
208 {
209  return (handle < mProcessReportItemList.size() &&
210  mProcessReportItemList[handle] != NULL);
211 }
212 
213 bool CProcessReport::setName(const std::string & name)
214 {
215  mName = name;
216  return true;
217 }
#define pdelete(p)
Definition: copasi.h:215
CProcessReport(const unsigned int &maxTime=0)
virtual bool finish()
std::string mName
virtual bool isValidHandle(const size_t handle) const
virtual bool setName(const std::string &name)
void resize(size_t size, const bool &copy=false)
Definition: CVector.h:301
virtual bool resetItem(const size_t &handle)
#define C_INT32
Definition: copasi.h:90
CVector< CProcessReportItem * > mProcessReportItemList
virtual bool progressItem(const size_t &handle)
virtual bool proceed()
virtual bool reset()
virtual bool progress()
size_t addItem(const std::string &name, const std::string &value, const std::string *pEndValue=NULL)
virtual ~CProcessReport()
const CCopasiParameter::Value & getEndValue() const
static CCopasiTimeVariable getCurrentWallTime()
Definition: CopasiTime.cpp:160
virtual bool finishItem(const size_t &handle)
size_t size() const
Definition: CVector.h:100
#define LLONG_CONST(n)
Definition: copasi.h:89
#define C_FLOAT64
Definition: copasi.h:92
const bool & hasEndValue() const
CCopasiTimeVariable * mpEndTime
CCopasiParameter::Value mEndValue