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

#include <CLRelAbsVector.h>

Public Member Functions

 CLRelAbsVector (double a=0.0, double r=0.0)
 
 CLRelAbsVector (const std::string &coordString)
 
 CLRelAbsVector (const RelAbsVector &source)
 
double getAbsoluteValue () const
 
double getRelativeValue () const
 
bool operator!= (const CLRelAbsVector &other) const
 
CLRelAbsVector operator+ (const CLRelAbsVector &other) const
 
CLRelAbsVector operator/ (double x) const
 
CLRelAbsVectoroperator= (const CLRelAbsVector &src)
 
bool operator== (const CLRelAbsVector &other) const
 
void setAbsoluteValue (double abs)
 
void setCoordinate (double abs, double rel=0.0)
 
void setCoordinate (const std::string &coordString)
 
void setRelativeValue (double rel)
 
RelAbsVector * toSBML () const
 
std::string toString () const
 

Protected Attributes

double mAbs
 
double mRel
 

Detailed Description

Definition at line 22 of file CLRelAbsVector.h.

Constructor & Destructor Documentation

CLRelAbsVector::CLRelAbsVector ( double  a = 0.0,
double  r = 0.0 
)

Constructor with two values. First value sets the absolute value, econd sets the relative value.

Definition at line 30 of file CLRelAbsVector.cpp.

Referenced by operator+(), and operator/().

30  : mAbs(a), mRel(r)
31 {
32 }
CLRelAbsVector::CLRelAbsVector ( const std::string &  coordString)

Constructor with a string. The string has to be parsed. If the string does not represent a valid value, the relative and the absolute component of the CLRelAbsVector are set to NaN.

Constructor with two values. First value sets the absolute value, econd sets the relative value.

Definition at line 38 of file CLRelAbsVector.cpp.

References setCoordinate().

38  : mAbs(0.0), mRel(0.0)
39 {
40  setCoordinate(coordString);
41 }
void setCoordinate(double abs, double rel=0.0)
CLRelAbsVector::CLRelAbsVector ( const RelAbsVector &  source)

Constructor to generate object from the corresponding SBML object.

Definition at line 46 of file CLRelAbsVector.cpp.

46  :
47  mAbs(source.getAbsoluteValue()),
48  mRel(source.getRelativeValue())
49 {
50 }

Member Function Documentation

double CLRelAbsVector::getAbsoluteValue ( ) const
double CLRelAbsVector::getRelativeValue ( ) const
bool CLRelAbsVector::operator!= ( const CLRelAbsVector other) const

Definition at line 218 of file CLRelAbsVector.cpp.

219 {
220  return !((*this) == other);
221 }
CLRelAbsVector CLRelAbsVector::operator+ ( const CLRelAbsVector other) const

addition operator

Definition at line 177 of file CLRelAbsVector.cpp.

References CLRelAbsVector(), mAbs, and mRel.

178 {
179  return CLRelAbsVector(this->mAbs + other.mAbs, this->mRel + other.mRel);
180 }
CLRelAbsVector(double a=0.0, double r=0.0)
CLRelAbsVector CLRelAbsVector::operator/ ( double  x) const

division by a double.

Definition at line 185 of file CLRelAbsVector.cpp.

References CLRelAbsVector(), mAbs, and mRel.

186 {
187  return CLRelAbsVector(this->mAbs / x, this->mRel / x);
188 }
CLRelAbsVector(double a=0.0, double r=0.0)
CLRelAbsVector & CLRelAbsVector::operator= ( const CLRelAbsVector src)

Definition at line 254 of file CLRelAbsVector.cpp.

References mAbs, and mRel.

255 {
256  if (&src != this)
257  {
258  this->mAbs = src.mAbs;
259  this->mRel = src.mRel;
260  }
261 
262  return *this;
263 }
bool CLRelAbsVector::operator== ( const CLRelAbsVector other) const

Definition at line 190 of file CLRelAbsVector.cpp.

References mAbs, and mRel.

191 {
192  bool result = true;
193 
194  if (this->mAbs == 0.0)
195  {
196  result = (fabs(other.mAbs) < 1e-12);
197  }
198  else
199  {
200  result = (fabs((this->mAbs - other.mAbs) / this->mAbs) < 1e-12);
201  }
202 
203  if (result)
204  {
205  if (this->mRel == 0.0)
206  {
207  result = (fabs(other.mRel) < 1e-12);
208  }
209  else
210  {
211  result = (fabs((this->mRel - other.mRel) / this->mRel) < 1e-12);
212  }
213  }
214 
215  return result;
216 }
void CLRelAbsVector::setAbsoluteValue ( double  abs)

Sets the absolute coordinate value.

Definition at line 145 of file CLRelAbsVector.cpp.

References abs, and mAbs.

146 {
147  this->mAbs = abs;
148 }
#define abs(x)
Definition: f2c.h:173
void CLRelAbsVector::setCoordinate ( double  abs,
double  rel = 0.0 
)

Sets the coordiantes.

Definition at line 55 of file CLRelAbsVector.cpp.

References abs, mAbs, and mRel.

Referenced by CLRelAbsVector().

56 {
57  this->mAbs = abs;
58  this->mRel = rel;
59 }
#define abs(x)
Definition: f2c.h:173
void CLRelAbsVector::setCoordinate ( const std::string &  coordString)

Sets the coordiantes from the given string.

Definition at line 64 of file CLRelAbsVector.cpp.

References mAbs, and mRel.

65 {
66  bool result = true;
67  // first we remove all whitespaces from the string
68  size_t i, iMax = coordString.size();
69  std::string trimmed;
70 
71  for (i = 0; i < iMax; ++i)
72  {
73  if (!(coordString[i] == ' ' || coordString[i] == '\t' || coordString[i] == '\n' || coordString[i] == '\r'))
74  {
75  trimmed += coordString[i];
76  }
77  }
78 
79  if (trimmed.empty())
80  {
81  result = false;
82  }
83  else
84  {
85  char* s = new char[trimmed.size()+1];
86  strncpy(s, trimmed.c_str(), trimmed.size() + 1);
87  char* p = s;
88  char* pp;
89  // p is changed if the value is parsed
90  double value = strtod(p, &pp);
91 
92  // check if strtod stopped at the '%' and if it is the last character in the string
93  if ((*pp) == '%' && pp == (s + trimmed.size() - 1))
94  {
95  // we only have a relative value
96  this->mAbs = 0.0;
97  this->mRel = value;
98  }
99  else
100  {
101  // either pp is at the end, then we only have an absolute value
102  // or pp has stopped on a '+' or '-' which connects the relative to the absolute value
103  // or we have an error
104  if ((*pp) == '\0')
105  {
106  this->mAbs = value;
107  this->mRel = 0.0;
108  }
109  else if ((*pp) == '+' || (*pp) == '-')
110  {
111  this->mAbs = value;
112  p = pp;
113  double value = strtod(p, &pp);
114 
115  // pp must point to the '%' character
116  if ((*pp) != '%' || pp != (s + trimmed.size() - 1))
117  {
118  result = false;
119  }
120  else
121  {
122  this->mRel = value;
123  }
124  }
125  else
126  {
127  result = false;
128  }
129  }
130 
131  delete[] s;
132  }
133 
134  if (result == false)
135  {
136  // set relative and absolute value to NaN
137  this->mAbs = std::numeric_limits<double>::quiet_NaN();
138  this->mRel = std::numeric_limits<double>::quiet_NaN();
139  }
140 }
void CLRelAbsVector::setRelativeValue ( double  rel)

Sets the relative coordinate value.

Definition at line 153 of file CLRelAbsVector.cpp.

References mRel.

154 {
155  this->mRel = rel;
156 }
RelAbsVector * CLRelAbsVector::toSBML ( ) const

Converts this object to the corresponding SBML object.

Definition at line 268 of file CLRelAbsVector.cpp.

References mAbs, and mRel.

Referenced by CLRenderPoint::addSBMLAttributes(), CLGradientStop::toSBML(), CLLinearGradient::toSBML(), CLRadialGradient::toSBML(), CLImage::toSBML(), CLEllipse::toSBML(), CLRenderCubicBezier::toSBML(), CLRectangle::toSBML(), CLText::toSBML(), and CLGroup::toSBML().

269 {
270  return new RelAbsVector(mAbs, mRel);
271 }
std::string CLRelAbsVector::toString ( ) const

Definition at line 223 of file CLRelAbsVector.cpp.

References mAbs, and mRel.

Referenced by operator<<(), CCopasiXML::saveEllipseElement(), CCopasiXML::saveGradientStop(), CCopasiXML::saveImageElement(), CCopasiXML::saveLinearGradient(), CCopasiXML::saveRadialGradient(), CCopasiXML::saveRectangleElement(), CCopasiXML::saveRenderPoint(), and CCopasiXML::saveRenderTextElement().

224 {
225  std::ostringstream os;
226 
227  if (this->mAbs != 0.0 || this->mRel == 0.0)
228  {
229  os << this->mAbs;
230 
231  if (this->mRel < 0.0)
232  {
233  os << this->mRel << "%";
234  }
235  else if (this->mRel > 0.0)
236  {
237  os << "+" << this->mRel << "%";
238  }
239  }
240  else
241  {
242  os << this->mRel << "%";
243  }
244 
245  return os.str();
246 }

Member Data Documentation

double CLRelAbsVector::mAbs
protected
double CLRelAbsVector::mRel
protected

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