COPASI API  4.16.103
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
COutputHandler Class Reference

#include <COutputHandler.h>

Inheritance diagram for COutputHandler:
Inheritance graph
[legend]
Collaboration diagram for COutputHandler:
Collaboration graph
[legend]

Public Member Functions

virtual void addInterface (COutputInterface *pInterface)
 
virtual bool compile (std::vector< CCopasiContainer * > listOfContainer, const CCopasiDataModel *pDataModel)
 
 COutputHandler ()
 
 COutputHandler (const COutputHandler &src)
 
virtual void finish ()
 
std::set< COutputInterface * > getInterfaces () const
 
bool isMaster () const
 
virtual void output (const Activity &activity)
 
virtual void removeInterface (COutputInterface *pInterface)
 
virtual void separate (const Activity &activity)
 
void setMaster (COutputHandler *pMaster)
 
virtual ~COutputHandler ()
 
- Public Member Functions inherited from COutputInterface
virtual void close ()
 
 COutputInterface ()
 
 COutputInterface (const COutputInterface &src)
 
virtual const std::set< const
CCopasiObject * > & 
getObjects () const
 
virtual ~COutputInterface ()
 

Protected Member Functions

bool compileRefresh (const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiDataModel *pDataModel)
 
void refresh ()
 

Protected Attributes

std::set< COutputInterface * > mInterfaces
 
std::vector< Refresh * > mObjectRefreshes
 
COutputHandlermpMaster
 
- Protected Attributes inherited from COutputInterface
std::set< const CCopasiObject * > mObjects
 

Additional Inherited Members

- Public Types inherited from COutputInterface
enum  Activity { BEFORE = 0x01, DURING = 0x02, AFTER = 0x04 }
 

Detailed Description

This is the lass which drives all output of COPASI.

Definition at line 112 of file COutputHandler.h.

Constructor & Destructor Documentation

COutputHandler::COutputHandler ( )

Default Constructor

Definition at line 26 of file COutputHandler.cpp.

26  :
28  mInterfaces(),
29  mpMaster(NULL),
31 {}
std::vector< Refresh * > mObjectRefreshes
COutputHandler * mpMaster
std::set< COutputInterface * > mInterfaces
COutputHandler::COutputHandler ( const COutputHandler src)

Copy constructor

Parameters
constCOutputInterface & src

Definition at line 33 of file COutputHandler.cpp.

33  :
34  COutputInterface(src),
36  mpMaster(src.mpMaster),
38 {}
std::vector< Refresh * > mObjectRefreshes
COutputHandler * mpMaster
std::set< COutputInterface * > mInterfaces
COutputHandler::~COutputHandler ( )
virtual

Destructor

Definition at line 40 of file COutputHandler.cpp.

40 {};

Member Function Documentation

void COutputHandler::addInterface ( COutputInterface pInterface)
virtual

Add an interface

Parameters
COutputInterface* pInterface;

Definition at line 140 of file COutputHandler.cpp.

References mInterfaces, and setMaster().

Referenced by CScanTask::initialize(), CTSSATask::initialize(), CTrajectoryTask::initialize(), CCrossSectionTask::initialize(), and CCopasiTask::initialize().

141 {
142  mInterfaces.insert(pInterface);
143 
144  // Assure that this is the only one master.
145  COutputHandler * pHandler = dynamic_cast< COutputHandler * >(pInterface);
146 
147  if (pHandler != NULL) pHandler->setMaster(this);
148 }
void setMaster(COutputHandler *pMaster)
std::set< COutputInterface * > mInterfaces
bool COutputHandler::compile ( std::vector< CCopasiContainer * >  listOfContainer,
const CCopasiDataModel pDataModel 
)
virtual

compile the object list from name vector

Parameters
std::vector<CCopasiContainer * > listOfContainer
constCCopasiDataModel* pDataModel
Returns
bool success

Reimplemented from COutputInterface.

Reimplemented in COutputHandlerPlot.

Definition at line 47 of file COutputHandler.cpp.

References compileRefresh(), mInterfaces, COutputInterface::mObjects, mpMaster, and setMaster().

Referenced by COutputHandlerPlot::compile(), CCopasiTask::initialize(), and CMoietiesTask::process().

48 {
49  bool success = true;
50  mObjects.clear();
51 
52  std::set< COutputInterface *>::iterator it = mInterfaces.begin();
53  std::set< COutputInterface *>::iterator end = mInterfaces.end();
54 
55  std::set< const CCopasiObject * >::const_iterator itObj;
56  std::set< const CCopasiObject * >::const_iterator endObj;
57 
58  for (; it != end; ++it)
59  {
60  success &= (*it)->compile(listOfContainer, pDataModel);
61 
62  // Assure that this is the only one master.
63  COutputHandler * pHandler = dynamic_cast< COutputHandler * >(*it);
64 
65  if (pHandler != NULL) pHandler->setMaster(this);
66 
67  // Collect the list of objects
68  const std::set< const CCopasiObject * > & Objects = (*it)->getObjects();
69 
70  for (itObj = Objects.begin(), endObj = Objects.end(); itObj != endObj; ++itObj)
71  mObjects.insert(*itObj);
72  }
73 
74  if (mpMaster == NULL)
75  success &= compileRefresh(listOfContainer, pDataModel);
76 
77  return success;
78 }
COutputHandler * mpMaster
void setMaster(COutputHandler *pMaster)
bool compileRefresh(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiDataModel *pDataModel)
std::set< const CCopasiObject * > mObjects
std::set< COutputInterface * > mInterfaces
bool COutputHandler::compileRefresh ( const std::vector< CCopasiContainer * > &  listOfContainer,
const CCopasiDataModel pDataModel 
)
protected

Compile the object refresh list

Parameters
conststd::vector< CCopasiContainer * > & listOfContainer
Returns
bool success

Definition at line 174 of file COutputHandler.cpp.

References CCopasiObject::buildUpdateSequence(), CCopasiObject::getCN(), CCopasiDataModel::getModel(), CModel::getUptoDateObjects(), mObjectRefreshes, COutputInterface::mObjects, and CCopasiDataModel::ObjectFromName().

Referenced by compile().

175 {
176  const CModel * pModel =
177  dynamic_cast<const CModel * >(pDataModel->ObjectFromName(listOfContainer, pDataModel->getModel()->getCN()));
178 
180 
181  std::set< const CCopasiObject * >::const_iterator it = mObjects.begin();
182  std::set< const CCopasiObject * >::const_iterator end = mObjects.end();
183 
184  // Timers are treated differently they are started during compilation.
185  for (; it != end; ++it)
186  if (dynamic_cast< const CCopasiTimer * >(*it))
187  const_cast< CCopasiTimer * >(static_cast< const CCopasiTimer * >(*it))->start();
188 
189  return true;
190 }
std::vector< Refresh * > mObjectRefreshes
virtual CCopasiObjectName getCN() const
const std::set< const CCopasiObject * > & getUptoDateObjects() const
Definition: CModel.cpp:1178
std::set< const CCopasiObject * > mObjects
static std::vector< Refresh * > buildUpdateSequence(const DataObjectSet &objects, const DataObjectSet &uptoDateObjects, const DataObjectSet &context=DataObjectSet())
Definition: CModel.h:50
CCopasiObject * ObjectFromName(const std::vector< CCopasiContainer * > &listOfContainer, const CCopasiObjectName &CN) const
void COutputHandler::finish ( )
virtual

Finish the output

Reimplemented from COutputInterface.

Definition at line 105 of file COutputHandler.cpp.

References mInterfaces, and removeInterface().

Referenced by main(), and validate().

106 {
107  std::set< COutputInterface *>::iterator it = mInterfaces.begin();
108  std::set< COutputInterface *>::iterator end = mInterfaces.end();
109 
110  // This hack is necessary as the reverse iterator behaves strangely
111  // under Visual C++ 6.0, i.e., removing an object advances the iterator.
112  std::vector< COutputInterface * > ToBeRemoved;
113 
114  // Closing a stream is separated from finishing the output
115  // since subtask may still need to finish their output.
116  for (; it != end; ++it)
117  {
118  (*it)->finish();
119  }
120 
121  for (it = mInterfaces.begin(); it != end; ++it)
122  {
123  (*it)->close();
124 
125  // CTimesSeries and CReport are only used once.
126  if (dynamic_cast< CReport * >(*it) != NULL ||
127  dynamic_cast< CTimeSeries * >(*it) != NULL)
128  ToBeRemoved.push_back(*it);
129  }
130 
131  std::vector< COutputInterface * >::iterator itRemove = ToBeRemoved.begin();
132  std::vector< COutputInterface * >::iterator endRemove = ToBeRemoved.end();
133 
134  for (; itRemove != endRemove; ++itRemove)
135  removeInterface(*itRemove);
136 
137  return;
138 }
virtual void removeInterface(COutputInterface *pInterface)
std::set< COutputInterface * > mInterfaces
std::set< COutputInterface * > COutputHandler::getInterfaces ( ) const

Definition at line 42 of file COutputHandler.cpp.

References mInterfaces.

43 {
44  return mInterfaces;
45 }
std::set< COutputInterface * > mInterfaces
bool COutputHandler::isMaster ( ) const

Check whether the handler is a master

Returns
bool isMaster

Definition at line 163 of file COutputHandler.cpp.

References mpMaster.

164 {return (mpMaster == NULL);}
COutputHandler * mpMaster
void COutputHandler::output ( const Activity activity)
virtual

Perform an output event for the current activity

Parameters
constActivity & activity

Reimplemented from COutputInterface.

Definition at line 80 of file COutputHandler.cpp.

References mInterfaces, mpMaster, and refresh().

Referenced by CCopasiTask::output().

81 {
82  if (mpMaster == NULL)
83  refresh();
84 
85  std::set< COutputInterface *>::iterator it = mInterfaces.begin();
86  std::set< COutputInterface *>::iterator end = mInterfaces.end();
87 
88  for (; it != end; ++it)
89  (*it)->output(activity);
90 
91  return;
92 }
COutputHandler * mpMaster
std::set< COutputInterface * > mInterfaces
void COutputHandler::refresh ( )
protected

Refresh all objects

Definition at line 166 of file COutputHandler.cpp.

References mObjectRefreshes.

Referenced by output().

167 {
168  std::vector< Refresh * >::iterator it = mObjectRefreshes.begin();
169  std::vector< Refresh * >::iterator end = mObjectRefreshes.end();
170 
171  for (; it != end; ++it)(**it)();
172 }
std::vector< Refresh * > mObjectRefreshes
void COutputHandler::removeInterface ( COutputInterface pInterface)
virtual

Remove an interface

Parameters
COutputInterface* pInterface;

Reimplemented in COutputHandlerPlot.

Definition at line 150 of file COutputHandler.cpp.

References mInterfaces, and setMaster().

Referenced by finish(), and COutputHandlerPlot::removeInterface().

151 {
152  mInterfaces.erase(pInterface);
153 
154  // Assure that the removed handler is its own master.
155  COutputHandler * pHandler = dynamic_cast< COutputHandler * >(pInterface);
156 
157  if (pHandler != NULL) pHandler->setMaster(NULL);
158 }
void setMaster(COutputHandler *pMaster)
std::set< COutputInterface * > mInterfaces
void COutputHandler::separate ( const Activity activity)
virtual

Introduce an additional separator into the output

Parameters
constActivity & activity

Reimplemented from COutputInterface.

Definition at line 94 of file COutputHandler.cpp.

References mInterfaces.

Referenced by CCopasiTask::separate().

95 {
96  std::set< COutputInterface *>::iterator it = mInterfaces.begin();
97  std::set< COutputInterface *>::iterator end = mInterfaces.end();
98 
99  for (; it != end; ++it)
100  (*it)->separate(activity);
101 
102  return;
103 }
std::set< COutputInterface * > mInterfaces
void COutputHandler::setMaster ( COutputHandler pMaster)

Set whether the handler is the master handler

Parameters
COutputHandler* pMaster

Definition at line 160 of file COutputHandler.cpp.

References mpMaster.

Referenced by addInterface(), compile(), and removeInterface().

161 {mpMaster = pMaster;}
COutputHandler * mpMaster

Member Data Documentation

std::set<COutputInterface *> COutputHandler::mInterfaces
protected

A list of all active output interfaces.

Definition at line 202 of file COutputHandler.h.

Referenced by addInterface(), COutputHandlerPlot::compile(), compile(), finish(), getInterfaces(), output(), removeInterface(), and separate().

std::vector< Refresh * > COutputHandler::mObjectRefreshes
protected

An ordered list of refresh methods needed by the master

Definition at line 213 of file COutputHandler.h.

Referenced by compileRefresh(), and refresh().

COutputHandler* COutputHandler::mpMaster
protected

Points to the master handler. The master handler is responsible for the and object updates and all the output.

Definition at line 208 of file COutputHandler.h.

Referenced by compile(), isMaster(), output(), and setMaster().


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