COPASI API  4.40.278
utility.cpp File Reference
#include <algorithm>
#include <cmath>
#include <limits>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "copasi/copasi.h"
#include "utility.h"
#include "CCopasiMessage.h"


#define toBeEscaped   "\\\""


bool containsTag (const std::string &filename, const std::string &tagname, int numLines)
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)
bool strToIndex (const std::string &str, size_t &index)
C_INT32 strToInt (const char *str, char const **pTail)
unsigned C_INT32 strToUnsignedInt (const char *str, char const **pTail)
time_t timeFromUTC (const std::string utc)
std::string unQuote (const std::string &name)
std::string UTCTimeStamp ()
size_t utf8Length (const std::string &str)

Macro Definition Documentation

◆ toBeEscaped

#define toBeEscaped   "\\\""

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.

filenamethe filename to be tested
tagnamethe tag name to be tested for
numLinesthe number of lines to be tested (default 10)
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.

filenamethe filename to be tested
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

conststd::string & name
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.

conststd::string & name
conststd::string & additionalEscapes (default: "")
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

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

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

◆ stringToPointer()

void* stringToPointer ( const std::string  str)

Convert a character sequence to a void pointer

conststd::string str
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.

conststd::string & str
size_t& index
bool success


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

constchar * str
charconst ** pTail (default: NULL)

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

constchar * str
charconst ** pTail (default: NULL)
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

conststd::string utc
time_t time

Referenced by CCheckForUpdates::checkRequired().

◆ 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.

conststd::string & name
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

conststd::string & str
size_t utf8Length

Referenced by SBMLUnitSupport::createUnitExpressionFor().