COPASI API  4.16.103
Classes | Public Member Functions | Static Public Member Functions | Protected Attributes | Static Protected Attributes | List of all members
CKeyFactory Class Reference

#include <CKeyFactory.h>

Collaboration diagram for CKeyFactory:
Collaboration graph
[legend]

Classes

class  CDecisionVector
 
class  HashTable
 

Public Member Functions

std::string add (const std::string &prefix, CCopasiObject *pObject)
 
bool addFix (const std::string &key, CCopasiObject *pObject)
 
 CKeyFactory ()
 
CCopasiObjectget (const std::string &key)
 
bool remove (const std::string &key)
 
 ~CKeyFactory ()
 

Static Public Member Functions

static bool isValidKey (const std::string &key, const std::string &prefix="")
 

Protected Attributes

std::map< std::string, HashTablemKeyTable
 

Static Protected Attributes

static CDecisionVector isDigit
 
static CDecisionVector isPrefix
 

Detailed Description

Definition at line 35 of file CKeyFactory.h.

Constructor & Destructor Documentation

CKeyFactory::CKeyFactory ( )

Default constructor

Definition at line 161 of file CKeyFactory.cpp.

161  :
162  mKeyTable()
163 {}
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
CKeyFactory::~CKeyFactory ( )

Destructor

Definition at line 165 of file CKeyFactory.cpp.

165 {}

Member Function Documentation

std::string CKeyFactory::add ( const std::string &  prefix,
CCopasiObject pObject 
)

Add an object with a key generated from the given prefix to the key map. The return value is the actually generated key.

Parameters
conststd::string & prefix
CCopasiObject* pObject
Returns
std::string key

Definition at line 167 of file CKeyFactory.cpp.

References mKeyTable.

Referenced by CCompartment::CCompartment(), CEvent::CEvent(), CFunction::CFunction(), CLColorDefinition::CLColorDefinition(), CLEllipse::CLEllipse(), CLGlobalRenderInformation::CLGlobalRenderInformation(), CLGlobalStyle::CLGlobalStyle(), CLGradientStop::CLGradientStop(), CLGroup::CLGroup(), CLImage::CLImage(), CLLinearGradient::CLLinearGradient(), CLLineEnding::CLLineEnding(), CLLocalRenderInformation::CLLocalRenderInformation(), CLLocalStyle::CLLocalStyle(), CLPolygon::CLPolygon(), CLRadialGradient::CLRadialGradient(), CLRectangle::CLRectangle(), CLRenderCurve::CLRenderCurve(), CLText::CLText(), CMetab::CMetab(), CModelEntity::CModelEntity(), CReaction::CReaction(), CExperiment::initializeParameter(), and CModel::initObjects().

169 {
170  std::map< std::string, CKeyFactory::HashTable >::iterator it =
171  mKeyTable.find(prefix);
172 
173  if (it == mKeyTable.end())
174  {
175  std::pair<std::map< std::string, CKeyFactory::HashTable >::iterator, bool> ret =
176  mKeyTable.insert(std::map< std::string, CKeyFactory::HashTable >::value_type(prefix, CKeyFactory::HashTable()));
177 
178  it = ret.first;
179  }
180 
181  std::stringstream key;
182  key << prefix + "_" << it->second.add(pObject);
183 
184  return key.str();
185 }
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
bool CKeyFactory::addFix ( const std::string &  key,
CCopasiObject pObject 
)

Add an object with a fix given key. The return value indicate whether the key was actually inserted.

Parameters
conststd::string & key
CCopasiObject* pObject
Returns
bool success

Definition at line 187 of file CKeyFactory.cpp.

References isDigit, and mKeyTable.

Referenced by CCopasiXMLParser::ModelParameterSetElement::start().

188 {
189  size_t pos = key.length() - 1;
190 
191  while (isDigit(key[pos]) && pos) --pos;
192 
193  std::string Prefix = key.substr(0, pos);
194  size_t index = atoi(key.substr(pos + 1).c_str());
195 
196  std::map< std::string, CKeyFactory::HashTable >::iterator it =
197  mKeyTable.find(Prefix);
198 
199  if (it == mKeyTable.end())
200  {
201  std::pair<std::map< std::string, CKeyFactory::HashTable >::iterator, bool> ret =
202  mKeyTable.insert(std::map< std::string, CKeyFactory::HashTable >::value_type(Prefix, CKeyFactory::HashTable()));
203 
204  it = ret.first;
205  }
206 
207  return it->second.addFix(index, pObject);
208 }
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
static CDecisionVector isDigit
Definition: CKeyFactory.h:79
CCopasiObject * CKeyFactory::get ( const std::string &  key)

Retrieve the object referred by key from the key map.

Parameters
conststd::string & key
Returns
CCopasiObject * pObject

Definition at line 235 of file CKeyFactory.cpp.

References isDigit, and mKeyTable.

Referenced by CModelAdd::addCompartmentsExpressions(), CModelAdd::addMetabolitesExpressions(), CModelAdd::addModelValuesExpressions(), CModel::applyActiveParameterSet(), CEventAssignment::compile(), CFunctionAnalyzer::constructCallParametersActualValues(), CModelExpansion::SetOfModelElements::contains(), CModelAdd::copyDelayExpression(), CModelAdd::copyEventAssignmentExpression(), CModelAdd::copyExpression(), CModelAdd::copyInitialExpression(), CModelAdd::copyTriggerExpression(), CModelParameterSet::createFromModel(), CSBMLExporter::createKineticExpression(), CSBMLExporter::createKineticLaw(), CModelExpansion::createLinearArray(), CSBMLExporter::createMassActionExpression(), CMMLOutput::createParameterMapping(), CModelExpansion::createRectangularArray(), CQEventDM::data(), CEvent::deleteAssignment(), CQPlotSubwidget::deletePlot(), CModelExpansion::duplicateReaction(), CCopasiXMLParser::ListOfModelParameterSetsElement::end(), CCopasiXMLParser::PlotItemElement::end(), CCopasiXMLParser::PlotSpecificationElement::end(), CCopasiXMLParser::ListOfReportsElement::end(), CCopasiXMLParser::COPASIElement::end(), CopasiWidget::enter(), CQModelValue::enterProtected(), CQEventWidget1::enterProtected(), CQRDFTreeView::enterProtected(), FunctionWidget1::enterProtected(), CQNotes::enterProtected(), CModelExpansion::ElementsMap::exists(), CSBMLExporter::exportEventAssignments(), CODEExporter::exportKineticFunction(), CODEExporterC::exportTitleData(), FunctionWidget1::functionParametersChanged(), CFitItem::getCrossValidations(), CReactionInterface::getDeletedParameters(), CMetabNameInterface::getDisplayName(), CModelExpansion::ElementsMap::getDuplicateKey(), CObjectLists::getEventTargets(), CFitItem::getExperiments(), CLTextGlyph::getGraphicalObject(), CObjectLists::getListOfConstObjects(), CLMetabReferenceGlyph::getMetabGlyph(), CChemEqElement::getMetabolite(), CLGraphicalObject::getModelObject(), CQModelElementTreeWidgetItem::getObject(), CQSideCompoundWizardPage::CQListWidgetModelItem::getObject(), CTimeSeries::getSBMLId(), CLNAProblem::getSubTask(), CMCAProblem::getSubTask(), CLReferenceGlyph::getTargetGlyph(), CLabel::getText(), CLGraphicalObject::hasValidModelReference(), CSBMLExporter::hasVolumeAssignment(), CReactionInterface::initFromReaction(), CSBMLExporter::isEventAssignmentSBMLCompatible(), CSBMLExporter::isEventSBMLCompatible(), CExperimentSet::keyToIndex(), CODEExporterC::KineticFunction2ODEmember(), FunctionWidget1::leave(), CQNotes::leave(), CQTabWidget::load(), CMIRIAMInfo::load(), CQEventWidget1::loadFromEvent(), CReactionInterface::loadMappingAndValues(), CQFittingItemWidget::loadSelection(), ScanWidget::loadTask(), SensitivitiesWidget::loadTask(), SteadyStateWidget::loadTask(), CModelMerging::mergeInExpression(), SBMLDocumentLoader::postprocessTextGlyph(), printNameForKey(), CModel::printParameterOverview(), CFitProblem::printResult(), CModelParameter::refreshFromModel(), CModel::removeCompartment(), CModel::removeEvent(), CFunctionDB::removeFunction(), CCopasiDataModel::removeLayout(), CModel::removeLocalReactionParameter(), CModel::removeMetabolite(), CModel::removeModelValue(), COutputDefinitionVector::removePlotSpec(), CModel::removeReaction(), CReportDefinitionVector::removeReportDefinition(), CQMCAWidget::runTask(), CQLNAWidget::runTask(), CQFittingWidget::runTask(), CQLyapWidget::runTask(), CQOptimizationWidget::runTask(), CQTabWidget::save(), CMIRIAMInfo::save(), ScanWidget::saveTask(), SensitivitiesWidget::saveTask(), SteadyStateWidget::saveTask(), CQFittingWidget::saveTask(), FunctionWidget1::saveToFunction(), ReactionsWidget1::saveToReaction(), CQNewMainWindow::selectReaction(), CQReactionDM::setEquation(), ReactionsWidget1::setFramework(), SBMLImporter::setInitialValues(), CChemEqElement::setMetabolite(), FunctionWidget1::slotBtnDelete(), ReactionsWidget1::slotBtnDelete(), CQFittingItemWidget::slotCrossValidationChanged(), CQPlotsWidget::slotDoubleClicked(), CQReportsWidget::slotDoubleClicked(), CQFittingItemWidget::slotExperimentChanged(), ReactionsWidget1::slotGotoFunction(), CQBrowserPaneDM::slotNotify(), CQExperimentData::slotOK(), CCopasiXMLParser::StateTemplateVariableElement::start(), CCopasiXMLParser::SourceParameterElement::start(), CCopasiXMLParser::CallParameterElement::start(), CCopasiXMLParser::KineticLawElement::start(), CCopasiXMLParser::ModifierElement::start(), CCopasiXMLParser::ProductElement::start(), CCopasiXMLParser::SubstrateElement::start(), CCopasiXMLParser::ReactionElement::start(), CCopasiXMLParser::MetaboliteElement::start(), CCopasiXMLParser::AssignmentElement::start(), CCopasiXMLParser::ParameterElement::start(), CCopasiXMLParser::SliderElement::start(), CCopasiXMLParser::CompartmentGlyphElement::start(), CCopasiXMLParser::MetaboliteGlyphElement::start(), CCopasiXMLParser::MetaboliteReferenceGlyphElement::start(), CCopasiXMLParser::ReactionGlyphElement::start(), CCopasiXMLParser::TextGlyphElement::start(), CCopasiXMLParser::SBMLMapElement::start(), CCopasiXMLParser::LocalStyleElement::start(), CQFittingWidget::taskFinishedEvent(), test000075::test_import_time_dependent_function_definition(), test000087::test_simulate_reaction_flux_reference_1(), CQLayoutScene::updatePosition(), ParameterTable::updateTable(), CReaction::variable2object(), CReactionInterface::writeBackToReaction(), and CMMLOutput::writeDifferentialEquations().

236 {
237  if (key.length() == 0) return NULL;
238 
239  size_t pos = key.length() - 1; //TODO !!!pos can be invalid (-1); not anymore, but look for other errors like this
240 
241  while (isDigit(key[pos]) && pos) --pos;
242 
243  std::string Prefix = key.substr(0, pos);
244  size_t index = atoi(key.substr(pos + 1).c_str());
245 
246  std::map< std::string, CKeyFactory::HashTable >::iterator it =
247  mKeyTable.find(Prefix);
248 
249  if (it == mKeyTable.end()) return NULL;
250 
251  return it->second.get(index);
252 }
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
static CDecisionVector isDigit
Definition: CKeyFactory.h:79
bool CKeyFactory::isValidKey ( const std::string &  key,
const std::string &  prefix = "" 
)
static

check whether the key is valid

Parameters
conststd::string & key
conststd::string & prefix (default: check for [_a-zA-Z]+_+)
Returns
bool isValid

CKeyFactory class. This class is used to create a unique key whithin COPASI. It also allows retreival of the CCopasiObject the key is assigned to.

Created for Copasi by Stefan Hoops 2003 Copyright Stefan Hoops

Definition at line 30 of file CKeyFactory.cpp.

References isDigit, and isPrefix.

Referenced by CCopasiParameter::isValidValue(), and CCopasiXMLParser::ParameterElement::start().

32 {
33  if (key == "" && prefix == "") return true;
34 
35  size_t digitsStart = key.length() - 1;
36 
37  while (isDigit(key[digitsStart]) && digitsStart) --digitsStart;
38 
39  if (digitsStart < 1 || digitsStart > key.length() - 2 || key[digitsStart] != '_') return false;
40 
41  if (prefix != "")
42  {
43  if (prefix != key.substr(0, digitsStart)) return false;
44  else return true;
45  }
46 
47  size_t prefixEnd = 0;
48 
49  while (isPrefix(key[prefixEnd]) && prefixEnd < digitsStart) ++prefixEnd;
50 
51  return (prefixEnd == digitsStart);
52 }
static CDecisionVector isDigit
Definition: CKeyFactory.h:79
static CDecisionVector isPrefix
Definition: CKeyFactory.h:84
bool CKeyFactory::remove ( const std::string &  key)

Remove the key and the related object from the key map.

Parameters
conststd::string & key
Returns
bool success

Definition at line 210 of file CKeyFactory.cpp.

References isDigit, and mKeyTable.

Referenced by COutputDefinitionVector::cleanup(), CReportDefinitionVector::cleanup(), CReportDefinition::cleanup(), CExperiment::initializeParameter(), CAnnotation::~CAnnotation(), CBiologicalDescription::~CBiologicalDescription(), CCompartment::~CCompartment(), CCopasiParameter::~CCopasiParameter(), CCopasiTask::~CCopasiTask(), CCreator::~CCreator(), CEvent::~CEvent(), CFunction::~CFunction(), CFunctionParameter::~CFunctionParameter(), CLayout::~CLayout(), CLColorDefinition::~CLColorDefinition(), CLEllipse::~CLEllipse(), CLGradientBase::~CLGradientBase(), CLGraphicalObject::~CLGraphicalObject(), CLGroup::~CLGroup(), CLImage::~CLImage(), CListOfLayouts::~CListOfLayouts(), CLPolygon::~CLPolygon(), CLRectangle::~CLRectangle(), CLRenderCurve::~CLRenderCurve(), CLRenderInformationBase::~CLRenderInformationBase(), CLStyle::~CLStyle(), CLText::~CLText(), CMetab::~CMetab(), CModel::~CModel(), CModelParameterSet::~CModelParameterSet(), CModification::~CModification(), CMoiety::~CMoiety(), CReaction::~CReaction(), CReference::~CReference(), and CSlider::~CSlider().

211 {
212  size_t pos = key.length();
213 
214  if (pos == 0) return false;
215 
216  --pos;
217 
218  while (isDigit(key[pos]) && pos) --pos;
219 
220  std::string Prefix = key.substr(0, pos);
221 
222  size_t index = 0;
223 
224  if (pos + 1 < key.length())
225  index = atoi(key.substr(pos + 1).c_str());
226 
227  std::map< std::string, CKeyFactory::HashTable >::iterator it =
228  mKeyTable.find(Prefix);
229 
230  if (it == mKeyTable.end()) return false;
231 
232  return it->second.remove(index);
233 }
std::map< std::string, HashTable > mKeyTable
Definition: CKeyFactory.h:74
static CDecisionVector isDigit
Definition: CKeyFactory.h:79

Member Data Documentation

CKeyFactory::CDecisionVector CKeyFactory::isDigit
staticprotected

Fast way to decide whether a character is a digit.

Definition at line 79 of file CKeyFactory.h.

Referenced by addFix(), get(), isValidKey(), and remove().

CKeyFactory::CDecisionVector CKeyFactory::isPrefix
staticprotected

Fast way to decide whether a character is a valid part of the prefix.

Definition at line 84 of file CKeyFactory.h.

Referenced by isValidKey().

std::map< std::string, HashTable > CKeyFactory::mKeyTable
protected

A map of hash tables for the prefixes.

Definition at line 74 of file CKeyFactory.h.

Referenced by add(), addFix(), get(), and remove().


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