COPASI API  4.16.103
Public Member Functions | Static Public Member Functions | List of all members
CCopasiObjectName Class Reference

#include <CCopasiObjectName.h>

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

Public Member Functions

 CCopasiObjectName ()
 
 CCopasiObjectName (const std::string &name)
 
 CCopasiObjectName (const CCopasiObjectName &src)
 
std::string::size_type findEx (const std::string &toFind, const std::string::size_type &pos=0) const
 
size_t getElementIndex (const size_t &pos=0) const
 
std::string getElementName (const size_t &pos, const bool &unescape=true) const
 
std::string getObjectName () const
 
std::string getObjectType () const
 
CCopasiObjectName getPrimary () const
 
CCopasiObjectName getRemainder () const
 
 ~CCopasiObjectName ()
 

Static Public Member Functions

static std::string escape (const std::string &name)
 
static std::string unescape (const std::string &name)
 

Detailed Description

Class CCopasiObjectName

This class is the class for handling Copasi object names.

Copyright Stefan Hoops 2002

Definition at line 32 of file CCopasiObjectName.h.

Constructor & Destructor Documentation

CCopasiObjectName::CCopasiObjectName ( )

Definition at line 40 of file CCopasiObjectName.cpp.

Referenced by getRemainder().

40  :
41  string()
42 {}
CCopasiObjectName::CCopasiObjectName ( const std::string &  name)

Definition at line 44 of file CCopasiObjectName.cpp.

44  :
45  string(name)
46 {}
CCopasiObjectName::CCopasiObjectName ( const CCopasiObjectName src)

Definition at line 48 of file CCopasiObjectName.cpp.

48  :
49  string(src)
50 {}
CCopasiObjectName::~CCopasiObjectName ( )

Definition at line 52 of file CCopasiObjectName.cpp.

53 {}

Member Function Documentation

std::string CCopasiObjectName::escape ( const std::string &  name)
static

Definition at line 126 of file CCopasiObjectName.cpp.

References toBeEscaped.

Referenced by CExperiment::compile(), CCopasiParameter::getCN(), CCopasiObject::getCN(), and CCopasiObject::setObjectName().

127 {
128 #define toBeEscaped "\\[]=,>"
129  std::string Escaped(name);
130  std::string::size_type pos = Escaped.find_first_of(toBeEscaped);
131 
132  while (pos != std::string::npos)
133  {
134  Escaped.insert(pos, "\\");
135  pos += 2;
136  pos = Escaped.find_first_of(toBeEscaped, pos);
137  }
138 
139  return Escaped;
140 #undef toBeEscaped
141 }
#define toBeEscaped
std::string::size_type CCopasiObjectName::findEx ( const std::string &  toFind,
const std::string::size_type &  pos = 0 
) const

Definition at line 159 of file CCopasiObjectName.cpp.

Referenced by getElementName(), getObjectName(), getObjectType(), getPrimary(), and getRemainder().

161 {
162  std::string::size_type where = find_first_of(toFind, pos);
163 
164  std::string::size_type tmp;
165 
166  while (where && where != std::string::npos)
167  {
168  tmp = find_last_not_of("\\", where - 1);
169 
170  if ((where - tmp) % 2)
171  return where;
172 
173  where = find_first_of(toFind, where + 1);
174  }
175 
176  return where;
177 }
size_t CCopasiObjectName::getElementIndex ( const size_t &  pos = 0) const

Definition at line 86 of file CCopasiObjectName.cpp.

References C_INVALID_INDEX, and getElementName().

Referenced by CCopasiVector< CLGeneralGlyph >::getObject(), and CArrayElementReference::getValuePointer().

87 {
88  std::string Index = getElementName(pos);
89  std::stringstream tmp(Index);
90 
91  size_t index = C_INVALID_INDEX;
92 
93  tmp >> index;
94 
95  if (tmp.fail()) return C_INVALID_INDEX;
96 
97  tmp << index;
98 
99  if (Index != tmp.str()) return C_INVALID_INDEX;
100 
101  return index;
102 }
#define C_INVALID_INDEX
Definition: copasi.h:222
std::string getElementName(const size_t &pos, const bool &unescape=true) const
std::string CCopasiObjectName::getElementName ( const size_t &  pos,
const bool &  unescape = true 
) const

Definition at line 104 of file CCopasiObjectName.cpp.

References findEx(), getPrimary(), and unescape().

Referenced by getElementIndex(), CCopasiContainer::getObject(), CArrayAnnotation::getObject(), CCopasiVectorN< CReportDefinition >::getObject(), CArrayElementReference::getValuePointer(), and CModelParameter::nameFromCN().

106 {
107  CCopasiObjectName Primary = getPrimary();
108 
109  std::string::size_type open = findEx("[");
110  size_t i;
111 
112  for (i = 0; i < pos && open != std::string::npos; i++)
113  open = findEx("[", open + 1);
114 
115  std::string::size_type close = findEx("]", open + 1);
116 
117  if (open == std::string::npos || close == std::string::npos) return "";
118 
119  if (unescape)
120  return CCopasiObjectName::unescape(Primary.substr(open + 1,
121  close - open - 1));
122 
123  return Primary.substr(open + 1, close - open - 1);
124 }
static std::string unescape(const std::string &name)
CCopasiObjectName getPrimary() const
std::string::size_type findEx(const std::string &toFind, const std::string::size_type &pos=0) const
std::string CCopasiObjectName::getObjectName ( ) const

Definition at line 74 of file CCopasiObjectName.cpp.

References findEx(), getPrimary(), and unescape().

Referenced by CCopasiContainer::getObject(), CCopasiParameterGroup::getObject(), CCopasiVector< CLGeneralGlyph >::getObject(), CCopasiVectorN< CReportDefinition >::getObject(), and CModelParameter::nameFromCN().

75 {
76  CCopasiObjectName Primary = getPrimary();
77  std::string::size_type pos = Primary.findEx("=");
78 
79  if (pos == std::string::npos) return "";
80 
81  CCopasiObjectName tmp = Primary.substr(pos + 1);
82  return CCopasiObjectName::unescape(tmp.substr(0, tmp.findEx("[")));
83 }
static std::string unescape(const std::string &name)
CCopasiObjectName getPrimary() const
std::string::size_type findEx(const std::string &toFind, const std::string::size_type &pos=0) const
std::string CCopasiObjectName::getObjectType ( ) const
CCopasiObjectName CCopasiObjectName::getPrimary ( ) const

Definition at line 55 of file CCopasiObjectName.cpp.

References findEx().

Referenced by CModelParameterReactionParameter::compile(), getElementName(), CMathContainer::getObject(), getObjectName(), getObjectType(), CModelParameter::nameFromCN(), CModelParameterSpecies::setCN(), and CModelExpansion::updateExpression().

56 {return substr(0, findEx(","));}
std::string::size_type findEx(const std::string &toFind, const std::string::size_type &pos=0) const
CCopasiObjectName CCopasiObjectName::getRemainder ( ) const

Definition at line 58 of file CCopasiObjectName.cpp.

References CCopasiObjectName(), and findEx().

Referenced by CModelParameterReactionParameter::compile(), CCopasiContainer::getObject(), CCopasiParameterGroup::getObject(), CArrayAnnotation::getObject(), CCopasiXMLParser::getObjectFromName(), CModelParameter::nameFromCN(), CCopasiDataModel::ObjectFromCN(), CModelParameterSpecies::setCN(), and CModelExpansion::updateExpression().

59 {
60  std::string::size_type pos = findEx(",");
61 
62  if (pos == std::string::npos) return CCopasiObjectName();
63 
64  return substr(pos + 1);
65 }
std::string::size_type findEx(const std::string &toFind, const std::string::size_type &pos=0) const
std::string CCopasiObjectName::unescape ( const std::string &  name)
static

Definition at line 143 of file CCopasiObjectName.cpp.

Referenced by getElementName(), getObjectName(), and getObjectType().

144 {
145  std::string Unescaped(name);
146  std::string::size_type pos = Unescaped.find("\\");
147 
148  while (pos != std::string::npos)
149  {
150  Unescaped.erase(pos, 1);
151  pos++;
152  pos = Unescaped.find("\\", pos);
153  }
154 
155  return Unescaped;
156 }

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