1 /** 2 * @file RelAbsVector.h 3 * @brief Definition of the RelAbsVector class. 4 * @author Ralph Gauges 5 * @author Frank T. Bergmann 6 * 7 * <!-------------------------------------------------------------------------- 8 * This file is part of libSBML. Please visit http://sbml.org for more 9 * information about SBML, and the latest version of libSBML. 10 * 11 * Copyright (C) 2020 jointly by the following organizations: 12 * 1. California Institute of Technology, Pasadena, CA, USA 13 * 2. University of Heidelberg, Heidelberg, Germany 14 * 3. University College London, London, UK 15 * 16 * Copyright (C) 2019 jointly by the following organizations: 17 * 1. California Institute of Technology, Pasadena, CA, USA 18 * 2. University of Heidelberg, Heidelberg, Germany 19 * 20 * Copyright (C) 2013-2018 jointly by the following organizations: 21 * 1. California Institute of Technology, Pasadena, CA, USA 22 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK 23 * 3. University of Heidelberg, Heidelberg, Germany 24 * 25 * Copyright (C) 2011-2013 jointly by the following organizations: 26 * 1. California Institute of Technology, Pasadena, CA, USA 27 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK 28 * 29 * Copyright 2010 Ralph Gauges 30 * Group for the modeling of biological processes 31 * University of Heidelberg 32 * Im Neuenheimer Feld 267 33 * 69120 Heidelberg 34 * Germany 35 * 36 * This library is free software; you can redistribute it and/or modify it 37 * under the terms of the GNU Lesser General Public License as published by the 38 * Free Software Foundation. A copy of the license agreement is provided in the 39 * file named "LICENSE.txt" included with this software distribution and also 40 * available online as http://sbml.org/software/libsbml/license.html 41 * ------------------------------------------------------------------------ --> 42 * 43 * @class RelAbsVector 44 * @sbmlbrief{render} Vectors with an absolute value and a relative value. 45 * 46 * For many elements in the render extension, it is necessary to specify 47 * coordinates not in terms of absolute values, but rather in terms of 48 * relative values or even a combination of absolute and relative values. 49 * Such a pair of values where one represents an absolute value and the other 50 * represents a relative value can be expressed by a RelAbsVector. The 51 * RelAbsVector class represents a pair of numerical values where one value 52 * represents an absolute value and the other value is a relative value in 53 * percent. 54 * 55 * The relative and absolute values to initialize a RelAbsVector object can 56 * either be given as numerical datatypes (double) or as a valid value 57 * string. A value string is a combination of an absolute value and a 58 * relative value and the absolute value if given has to come first. So valid 59 * value strings would be: "5.0e3+20%", or "100%" or "4". 60 */ 61 62 #ifndef RelAbsVector_H__ 63 #define RelAbsVector_H__ 64 65 #include <sbml/common/extern.h> 66 #include <sbml/common/sbmlfwd.h> 67 #include <sbml/packages/render/common/renderfwd.h> 68 69 #ifdef __cplusplus 70 71 #include <string> 72 #include <ostream> 73 #include <sbml/packages/render/extension/RenderExtension.h> 74 75 LIBSBML_CPP_NAMESPACE_BEGIN 76 77 class LIBSBML_EXTERN RelAbsVector 78 { 79 protected: 80 /** @cond doxygenLibsbmlInternal */ 81 82 double mAbs; 83 bool mIsSetAbs; 84 double mRel; 85 bool mIsSetRel; 86 87 /** @endcond */ 88 89 public: 90 /** 91 * Constructor with two values. 92 * First value sets the absolute value, second sets the relative value (%). 93 * 94 * @param a absolute value 95 * @param r relative value in % (50 -> 50%) 96 */ 97 RelAbsVector(double a=0.0, double r=0.0); 98 99 100 /** 101 * Constructor with a value string. 102 * If the string does not represent a valid value, the relative and the 103 * absolute component of the RelAbsVector are set to NaN. 104 * 105 * @param coordString value as a string 106 */ 107 RelAbsVector(const std::string& coordString); 108 109 110 /** 111 * Copy constructor for RelAbsVector. 112 * 113 * @param orig the RelAbsVector instance to copy. 114 */ 115 RelAbsVector(const RelAbsVector& orig); 116 117 118 /** 119 * Assignment operator for RelAbsVector. 120 * 121 * @param rhs the RelAbsVector object whose values are to be used as the 122 * basis of the assignment. 123 */ 124 RelAbsVector& operator=(const RelAbsVector& rhs); 125 126 127 /** 128 * Creates and returns a deep copy of this RelAbsVector object. 129 * 130 * @return a (deep) copy of this RelAbsVector object. 131 */ 132 virtual RelAbsVector* clone() const; 133 134 135 /** 136 * Destroy this RelAbsVector object. 137 */ 138 virtual ~RelAbsVector (); 139 140 141 /** 142 * Returns the absolute coordinate value. 143 * 144 * @return absolute value 145 */ 146 double getAbsoluteValue() const; 147 148 /** 149 * Returns the relative coordinate value. 150 * 151 * @return absolute value 152 */ 153 double getRelativeValue() const; 154 155 /** 156 * Returns the coordinate value. 157 * 158 * @return absolute value 159 */ 160 std::string getCoordinate() const; 161 162 /** 163 * Predicate returning @c true if this RelAbsVector's "abs" attribute is set. 164 * 165 * @return @c true if this RelAbsVector's "abs" attribute has been set, 166 * otherwise @c false is returned. 167 */ 168 bool isSetAbsoluteValue() const; 169 170 171 /** 172 * Predicate returning @c true if this RelAbsVector's "rel" attribute is set. 173 * 174 * @return @c true if this RelAbsVector's "rel" attribute has been set, 175 * otherwise @c false is returned. 176 */ 177 bool isSetRelativeValue() const; 178 179 180 /** 181 * Predicate returning @c true if this RelAbsVector's coordinate attribute is set. 182 * 183 * @return @c true if this RelAbsVector's coordinate attribute has been set, 184 * otherwise @c false is returned. 185 */ 186 bool isSetCoordinate() const; 187 188 189 190 /** 191 * Sets the absolute coordinate value. 192 * 193 * Calling this function with an argument of @c 0.0 or @c NaN is 194 * equivalent to unsetting the value. 195 * 196 * @param abs double value of the "abs" attribute to be set. 197 */ 198 int setAbsoluteValue(double abs); 199 200 /** 201 * Sets the relative coordinate value. 202 * 203 * Calling this function with an argument of @c 0.0 or @c NaN is 204 * equivalent to unsetting the value. 205 * 206 * @param rel double value of the "rel" attribute to be set. 207 */ 208 int setRelativeValue(double rel); 209 210 /** 211 * Sets the relative and absolute value. 212 * 213 * Calling this function with an argument of @c 0.0 or @c NaN is 214 * equivalent to unsetting the value. 215 * 216 * @param abs absolute value 217 * @param rel relative value. If the relative value is omitted, it is set to 0. 218 */ 219 int setCoordinate(double abs,double rel=0.0); 220 221 /** 222 * Sets the coordinates from the given string. 223 * If the string does not represent a valid value, the relative and the 224 * absolute component of the RelAbsVector are set to NaN. 225 * 226 * Calling this function with either cooredinate having a value of @c "0.0" 227 * or @c "NaN" is equivalent to unsetting the value. 228 * 229 * @param coordString value string 230 */ 231 int setCoordinate(const std::string& coordString); 232 233 234 /** 235 * Unsets the value of the "abs" attribute of this RelAbsVector. 236 * 237 * @copydetails doc_returns_one_success_code 238 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 239 */ 240 int unsetAbsoluteValue(); 241 242 243 /** 244 * Unsets the value of the relative coordinate attribute of this RelAbsVector. 245 * 246 * @copydetails doc_returns_one_success_code 247 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 248 */ 249 int unsetRelativeValue(); 250 251 252 /** 253 * Unsets the value of the "rel" attribute of this RelAbsVector. 254 * 255 * @copydetails doc_returns_one_success_code 256 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 257 */ 258 int unsetCoordinate(); 259 260 261 /** 262 * addition operator for RelAbsVector objects 263 */ 264 RelAbsVector operator+(const RelAbsVector& other) const; 265 266 /** 267 * Divides a RelAbsVector object by a double value. 268 * 269 * @param x divisor 270 * 271 * @return result of division as a new RelAbsVector object 272 */ 273 RelAbsVector operator/(double x) const; 274 275 /** 276 * Comparison operator. 277 * Return true if two RelAbsVector objects are equal. 278 * 279 * @return bool true if the two RelAbsValueObjects are equal and 280 * false otherwise. 281 */ 282 bool operator==(const RelAbsVector& other) const; 283 284 /** 285 * Inverse comparison operator. 286 * Return false if two RelAbsVector objects are equal. 287 * 288 * @return bool false if the two RelAbsValueObjects are equal and 289 * true otherwise. 290 */ 291 bool operator!=(const RelAbsVector& other) const; 292 293 /** 294 * @return an indication whether this element has been set 295 * (i.e., no zero entries for either relative or absolute coordinate) 296 */ 297 bool empty() const; 298 299 /** 300 * @return a string representation of this object 301 */ 302 std::string toString() const; 303 304 /** 305 * resets this element by setting the two coordinates to @c 0.0 306 */ 307 void erase(); 308 309 /** @cond doxygenLibsbmlInternal */ 310 friend std::ostream& operator<<(std::ostream& os,const RelAbsVector& v); 311 /** @endcond */ 312 }; 313 314 /** 315 * Output operator for RelAbsVector objects. 316 */ 317 std::ostream& operator<<(std::ostream& os,const RelAbsVector& v); 318 319 LIBSBML_CPP_NAMESPACE_END 320 321 322 #endif /* __cplusplus */ 323 324 325 326 327 #ifndef SWIG 328 329 330 331 332 LIBSBML_CPP_NAMESPACE_BEGIN 333 334 335 336 337 BEGIN_C_DECLS 338 339 340 /** 341 * Creates a new RelAbsVector_t . 342 * 343 * @param abs a double, the absolute value to assign to this 344 * RelAbsVector_t. 345 * 346 * @param rel a double, the relative value to assign to this 347 * RelAbsVector_t. 348 * 349 * @memberof RelAbsVector_t 350 */ 351 LIBSBML_EXTERN 352 RelAbsVector_t * 353 RelAbsVector_create(double abs, double rel); 354 355 356 /** 357 * Creates and returns a deep copy of this RelAbsVector_t object. 358 * 359 * @param rav the RelAbsVector_t structure. 360 * 361 * @return a (deep) copy of this RelAbsVector_t object. 362 * 363 * @copydetails doc_warning_returns_owned_pointer 364 * 365 * @memberof RelAbsVector_t 366 */ 367 LIBSBML_EXTERN 368 RelAbsVector_t* 369 RelAbsVector_clone(const RelAbsVector_t* rav); 370 371 372 /** 373 * Frees this RelAbsVector_t object. 374 * 375 * @param rav the RelAbsVector_t structure. 376 * 377 * @memberof RelAbsVector_t 378 */ 379 LIBSBML_EXTERN 380 void 381 RelAbsVector_free(RelAbsVector_t* rav); 382 383 384 /** 385 * Returns the value of the "abs" attribute of this RelAbsVector_t. 386 * 387 * @param rav the RelAbsVector_t structure whose abs is sought. 388 * 389 * @return the value of the "abs" attribute of this RelAbsVector_t as a double. 390 * 391 * @memberof RelAbsVector_t 392 */ 393 LIBSBML_EXTERN 394 double 395 RelAbsVector_getAbsoluteValue(const RelAbsVector_t * rav); 396 397 398 /** 399 * Returns the value of the "rel" attribute of this RelAbsVector_t. 400 * 401 * @param rav the RelAbsVector_t structure whose rel is sought. 402 * 403 * @return the value of the "rel" attribute of this RelAbsVector_t as a double. 404 * 405 * @memberof RelAbsVector_t 406 */ 407 LIBSBML_EXTERN 408 double 409 RelAbsVector_getRelativeValue(const RelAbsVector_t * rav); 410 411 412 /** 413 * Predicate returning @c 1 (true) if this RelAbsVector_t's "abs" attribute is 414 * set. 415 * 416 * @param rav the RelAbsVector_t structure. 417 * 418 * @return @c 1 (true) if this RelAbsVector_t's "abs" attribute has been set, 419 * otherwise @c 0 (false) is returned. 420 * 421 * @memberof RelAbsVector_t 422 */ 423 LIBSBML_EXTERN 424 int 425 RelAbsVector_isSetAbsoluteValue(const RelAbsVector_t * rav); 426 427 428 /** 429 * Predicate returning @c 1 (true) if this RelAbsVector_t's "rel" attribute is 430 * set. 431 * 432 * @param rav the RelAbsVector_t structure. 433 * 434 * @return @c 1 (true) if this RelAbsVector_t's "rel" attribute has been set, 435 * otherwise @c 0 (false) is returned. 436 * 437 * @memberof RelAbsVector_t 438 */ 439 LIBSBML_EXTERN 440 int 441 RelAbsVector_isSetRelativeValue(const RelAbsVector_t * rav); 442 443 444 /** 445 * Sets the value of the "abs" attribute of this RelAbsVector_t. 446 * 447 * @param rav the RelAbsVector_t structure. 448 * 449 * @param abs double value of the "abs" attribute to be set. 450 * 451 * @copydetails doc_returns_success_code 452 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 453 * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} 454 * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} 455 * 456 * @memberof RelAbsVector_t 457 */ 458 LIBSBML_EXTERN 459 int 460 RelAbsVector_setAbsoluteValue(RelAbsVector_t * rav, double abs); 461 462 463 /** 464 * Sets the value of the "rel" attribute of this RelAbsVector_t. 465 * 466 * @param rav the RelAbsVector_t structure. 467 * 468 * @param rel double value of the "rel" attribute to be set. 469 * 470 * @copydetails doc_returns_success_code 471 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 472 * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} 473 * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} 474 * 475 * @memberof RelAbsVector_t 476 */ 477 LIBSBML_EXTERN 478 int 479 RelAbsVector_setRelativeValue(RelAbsVector_t * rav, double rel); 480 481 482 /** 483 * Unsets the value of the "abs" attribute of this RelAbsVector_t. 484 * 485 * @param rav the RelAbsVector_t structure. 486 * 487 * @copydetails doc_returns_success_code 488 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 489 * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} 490 * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} 491 * 492 * @memberof RelAbsVector_t 493 */ 494 LIBSBML_EXTERN 495 int 496 RelAbsVector_unsetAbsoluteValue(RelAbsVector_t * rav); 497 498 499 /** 500 * Unsets the value of the "rel" attribute of this RelAbsVector_t. 501 * 502 * @param rav the RelAbsVector_t structure. 503 * 504 * @copydetails doc_returns_success_code 505 * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} 506 * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} 507 * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} 508 * 509 * @memberof RelAbsVector_t 510 */ 511 LIBSBML_EXTERN 512 int 513 RelAbsVector_unsetRelativeValue(RelAbsVector_t * rav); 514 515 516 517 518 END_C_DECLS 519 520 521 522 523 LIBSBML_CPP_NAMESPACE_END 524 525 526 527 528 #endif /* !SWIG */ 529 530 531 532 533 #endif /* !RelAbsVector_H__ */ 534 535 536