COPASI API  4.40.278
utility.h File Reference
#include <string>
#include <array>
#include <string.h>
#include <stdarg.h>
#include "copasi/copasi.h"

Macros

#define INITIALTEXTSIZE   1024
 

Functions

bool containsTag (const std::string &filename, const std::string &tagname, int numLines=10)
 
void FixSName (const std::string &original, std::string &fixed)
 
bool isNumber (const std::string &str)
 
std::string ISODateTime (tm *pTime)
 
bool isProbablySBML (const std::string &filename)
 
std::string LocalTimeStamp ()
 
std::string nameToSbmlId (const std::string &name)
 
std::string pointerToString (const void *pVoid)
 
std::string quote (const std::string &name, const std::string &additionalEscapes="")
 
std::string StringPrint (const char *format,...)
 
bool stringReplace (std::string &str, const std::string &target, const std::string &replacement)
 
void * stringToPointer (const std::string str)
 
double strToDouble (const char *str, char const **pTail=NULL)
 
bool strToIndex (const std::string &str, size_t &index)
 
C_INT32 strToInt (const char *str, char const **pTail=NULL)
 
unsigned C_INT32 strToUnsignedInt (const char *str, char const **pTail=NULL)
 
time_t timeFromUTC (const std::string utc)
 
template<class CType >
CType toEnum (const char *attribute, const char **enumNames, const CType &enumDefault)
 
template<class CType >
CType toEnum (const std::string &attribute, const std::string *enumNames, const CType &enumDefault)
 
std::string unQuote (const std::string &name)
 
std::string UTCTimeStamp ()
 
size_t utf8Length (const std::string &str)
 

Macro Definition Documentation

◆ INITIALTEXTSIZE

#define INITIALTEXTSIZE   1024

Function Documentation

◆ containsTag()

bool containsTag ( const std::string &  filename,
const std::string &  tagname,
int  numLines = 10 
)

Test whether a given XML tag is present in the first number of lines of a given file.

Parameters
filenamethe filename to be tested
tagnamethe tag name to be tested for
numLinesthe number of lines to be tested (default 10)
Returns
boolean indicating whether the tag appeared in the first numLines.

Referenced by isProbablySBML().

◆ FixSName()

void FixSName ( const std::string &  original,
std::string &  fixed 
)

◆ isNumber()

◆ ISODateTime()

std::string ISODateTime ( tm *  pTime)

Returns the time pointed to by pTime in ISO format

Referenced by COptLogItem::fillString(), LocalTimeStamp(), and UTCTimeStamp().

◆ isProbablySBML()

bool isProbablySBML ( const std::string &  filename)

Tests whether the file is SBML by reading the first 10 lines and looking for the presence of the sbml tag.

Parameters
filenamethe filename to be tested
Returns
true, if the first 10 lines contain the sbml tag, false otherwise.

References containsTag().

Referenced by CDataModel::addModel().

◆ LocalTimeStamp()

std::string LocalTimeStamp ( )

Returns the current local time in ISO format

References ISODateTime().

Referenced by COptLogEntry::COptLogEntry(), and CCopasiMessage::handler().

◆ nameToSbmlId()

std::string nameToSbmlId ( const std::string &  name)

Convert a utf8 encoded name to a XmlId

Parameters
conststd::string & name
Returns
std::string SbmlId

Referenced by CSBMLExporter::createFunctionDefinition(), and CSBMLExporter::createUniqueId().

◆ pointerToString()

◆ quote()

std::string quote ( const std::string &  name,
const std::string &  additionalEscapes = "" 
)

Surround a name with quotes if the name contains a space or double quote else the name is returned unmodified. In the quoted name " and \ are escaped. The parameter additionalEscapes forces quotes around names containing any of the character in the parameter.

Parameters
conststd::string & name
conststd::string & additionalEscapes (default: "")
Returns
std::string quote

References toBeEscaped.

Referenced by CChemEqInterface::addModifier(), CMetabNameInterface::createUniqueDisplayName(), CEvaluationNodeCall::getBerkeleyMadonnaString(), CEvaluationNodeCall::getCCodeString(), CEvaluationNodeCall::getData(), CMetabNameInterface::getDisplayName(), CEvaluationNodeCall::getDisplayString(), CEvaluationNodeCall::getInfix(), CEvaluationNodeCall::getMMLString(), CEvaluationNodeCall::getXPPString(), CUnitDefinitionDB::quoteSymbol(), CEvaluationNodeCall::setData(), and CMetabNameInterface::splitDisplayName().

◆ StringPrint()

◆ stringReplace()

bool stringReplace ( std::string &  str,
const std::string &  target,
const std::string &  replacement 
)

Replaces the all occurrences of target string in str with the replacement and returns true if the target string was replaced

Parameters
std::string& str
conststd::string & target
conststd::string & replacement
Returns
bool replaced

Referenced by CUnit::buildExpression(), and CModel::replaceInExpressions().

◆ stringToPointer()

void* stringToPointer ( const std::string  str)

Convert a character sequence to a void pointer

Parameters
conststd::string str
Returns
void * pVoid

Referenced by CEvaluationNodeObject::CEvaluationNodeObject(), CEvaluationNodeObject::compile(), and CMathExpression::relocate().

◆ strToDouble()

◆ strToIndex()

bool strToIndex ( const std::string &  str,
size_t &  index 
)

Convert a string to a size_t index. Returns true if the conversion is successful, i.e., the whole string has been converted.

Parameters
conststd::string & str
size_t& index
Returns
bool success

References C_INVALID_INDEX.

Referenced by CDataArray::cnToIndex(), CDataArray::displayNamesToCN(), CCommonName::getElementIndex(), and CArrayElementReference::updateObjectName().

◆ strToInt()

C_INT32 strToInt ( const char *  str,
char const **  pTail = NULL 
)

Convert a character sequence to a double

Parameters
constchar * str
charconst ** pTail (default: NULL)
Returns
C_INT32

References C_INT32.

Referenced by COPASIHandler::processStart(), ParameterHandler::processStart(), and CVersion::setVersion().

◆ strToUnsignedInt()

unsigned C_INT32 strToUnsignedInt ( const char *  str,
char const **  pTail = NULL 
)

Convert a character sequence to a double

Parameters
constchar * str
charconst ** pTail (default: NULL)
Returns
unsigned C_INT32

References C_INT32.

Referenced by CCopasiParameterGroup::getObject(), CompartmentHandler::processStart(), ParameterDescriptionHandler::processStart(), ParameterHandler::processStart(), ReportDefinitionHandler::processStart(), and SliderHandler::processStart().

◆ timeFromUTC()

time_t timeFromUTC ( const std::string  utc)

Converts the UTC time to time_t

Parameters
conststd::string utc
Returns
time_t time

Referenced by CCheckForUpdates::checkRequired().

◆ toEnum() [1/2]

template<class CType >
CType toEnum ( const char *  attribute,
const char **  enumNames,
const CType &  enumDefault 
)

Convert an attribute to enum. If attribute is NULL or no matching name is found the parameter enumDefault is returned. Note: enumNames must be zero terminated.

Parameters
constchar * attribute
constchar ** enumNames
constCType & enumDefault
Returns
CType enum

Referenced by CCompartment::applyData(), CReaction::applyData(), CCopasiTask::applyData(), CCopasiTask::createUndoData(), CCopasiTask::fromData(), CPlotItem::getActivity(), CConfigurationFile::initializeParameter(), CModelParameterSet::insert(), FunctionHandler::processStart(), PlotItemHandler::processStart(), PlotSpecificationHandler::processStart(), SliderHandler::processStart(), and CPlotItem::setType().

◆ toEnum() [2/2]

template<class CType >
CType toEnum ( const std::string &  attribute,
const std::string *  enumNames,
const CType &  enumDefault 
)

Convert an attribute to enum. If attribute is "" or no matching name is found the parameter enumDefault is returned. Note: enumNames must be zero terminated.

Parameters
conststd::string & attribute
conststd::string * enumNames
constCType & enumDefault
Returns
CType enum

◆ unQuote()

std::string unQuote ( const std::string &  name)

Unesacape a quoted name. If the name is surrounded by quotes these are removed and included escape sequences '.' are reduced to '.' else the name is returned unmodified.

Parameters
conststd::string & name
Returns
std::string unQuote

Referenced by CModel::findMetabByName(), CEvaluationNodeCall::getData(), CDataVectorN< CType >::getIndex(), CUnitDefinitionDB::getUnitDefFromSymbol(), and CEvaluationNodeCall::setData().

◆ UTCTimeStamp()

◆ utf8Length()

size_t utf8Length ( const std::string &  str)

calculate the number of utf8 characters in a givent string

Parameters
conststd::string & str
Returns
size_t utf8Length

Referenced by SBMLUnitSupport::createUnitExpressionFor().