COPASI API  4.16.103
CSBMLunit.h
Go to the documentation of this file.
1 // Copyright (C) 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Sven Sahle and University of Heidelberg
7 // All rights reserved.
8 
9 #ifndef CUNIT
10 #define CUNIT
11 
12 #include <string>
13 #include <sbml/UnitDefinition.h>
14 
15 class UnitDefinition;
16 
17 /**
18  * The current implementation of the units is just a wrapper for the
19  * libsbml UnitDefinition class.
20  */
21 class CSBMLunit
22 {
23 public:
24  ///Default constructor
25  CSBMLunit(unsigned int sbmlLevel, unsigned int sbmlVersion);
26 
27  ///Copy constructor
28  CSBMLunit(const CSBMLunit & src);
29 
30  ///Constructor from libsbml units
31  CSBMLunit(const UnitDefinition* ud);
32 
33  virtual ~CSBMLunit();
34 
35  bool multiply(const CSBMLunit & unit);
36  void invert();
37 
38  ///apply numeric exponent to the unit.
39  /**
40  * The current implementation only supports integer exponents.
41  */
42  void applyExponent(double exp);
43 
44  /**
45  * This method applies a symbol as an exponent to the unit. The result is
46  * not really a valid unit itself, but the exponent can cancel out later during
47  * the calculations (via applyInverseExponent() ).
48  * In the current implementation, a string and an integer (sbml id + frame stack index)
49  * are sufficient to uniquely identify a symbol within one expression. In other words:
50  * Once we know the frame index the ID is unique.
51  */
52  ///apply symbolic exponent to the unit
53  void applyExponent(const std::string& id, size_t frame);
54 
55  /**
56  * This method applies a symbol as a reverse exponent to the unit. The result is
57  * not really a valid unit itself, but the exponent can cancel out later.
58  * See applyExponent(std::string id, int frame)
59  */
60  ///apply inverse of symbolic exponent to the unit
61  void applyInverseExponent(const std::string& id, size_t frame);
62 
63  static bool isEqual(const CSBMLunit & unit1, const CSBMLunit & unit2);
64 
65  virtual std::string getDisplayString() const;
66 
67  bool isDimensionless() const;
68 
69  UnitDefinition & getSBMLUnitDefinition() {return mUD;};
70  const UnitDefinition & getSBMLUnitDefinition() const {return mUD;};
71 
72  int getSymbolicExpExp() const {return mSymExpExp;};
73  const std::string & getSymbolicExponent() const {return mSymExp.mID;};
74 
75 private:
76  UnitDefinition mUD;
77 
78  /// this class uniquely (in a given context) identifies a symbol
80  {
81  public:
82  std::string mID;
83  size_t mFrame;
85  SymbolicExponent(std::string id, size_t frame): mID(id), mFrame(frame) {};
86  bool isEqual(const SymbolicExponent & se) const {return mID == se.mID && mFrame == se.mFrame;};
87  //bool isEmpty() const {return (mID=="")&&(mFrame==0)};
88  };
89 
92 };
93 
94 /**
95  * This class contains one unit definition plus some meta information,
96  * e.g. whether the unit was provided or calculated, if it is unknown or
97  * if there is a conflict.
98  */
100 {
101 public:
102  ///this enum encodes the status of a units information
103  enum INFO
104  {
105  /// the units is unknown
106  UNKNOWN = 0,
107  /// the units is determined from the sbml defaults
109  /// the units is determined from the model-wide definitions
111  ///the units if provided for a specific object explicitly
113  ///the units was determined by reasoning
115  };
116 
117  ///Default constructor
118  CSBMLunitInformation(unsigned int sbmlLevel, unsigned int sbmlVersion);
119 
120  CSBMLunitInformation(unsigned int sbmlLevel, unsigned int sbmlVersion, INFO info, bool conflict = false);
121 
122  CSBMLunitInformation(const CSBMLunit& u, INFO info, bool conflict = false);
123 
124  CSBMLunitInformation(const UnitDefinition* ud, INFO info, bool conflict = false);
125 
126  ///set the status information
127  void setInfo(INFO info) {mInfo = info;};
128 
129  ///get the status information
130  INFO getInfo() const {return mInfo;};
131 
132  ///set the conflict flag
133  void setConflict(bool c) {mConflict = c;};
134 
135  ///retrieve the conflict flag
136  bool isConflict() const {return mConflict;};
137 
138  virtual std::string getDisplayString() const;
139 
140  static bool isEqual(const CSBMLunitInformation & unit1, const CSBMLunitInformation & unit2);
141 
142 private:
144 
145  ///indicated whether a conflict occurred while trying to determine the unit.
146  bool mConflict;
147 };
148 
149 #endif
the units is determined from the sbml defaults
Definition: CSBMLunit.h:108
this class uniquely (in a given context) identifies a symbol
Definition: CSBMLunit.h:79
virtual std::string getDisplayString() const
Definition: CSBMLunit.cpp:210
bool isDimensionless() const
Definition: CSBMLunit.cpp:175
virtual std::string getDisplayString() const
Definition: CSBMLunit.cpp:44
UnitDefinition mUD
Definition: CSBMLunit.h:73
void applyExponent(double exp)
apply numeric exponent to the unit.
Definition: CSBMLunit.cpp:104
the units is unknown
Definition: CSBMLunit.h:106
bool mConflict
indicated whether a conflict occurred while trying to determine the unit.
Definition: CSBMLunit.h:146
CSBMLunit(unsigned int sbmlLevel, unsigned int sbmlVersion)
Default constructor.
Definition: CSBMLunit.cpp:12
SymbolicExponent(std::string id, size_t frame)
Definition: CSBMLunit.h:85
static bool isEqual(const CSBMLunit &unit1, const CSBMLunit &unit2)
Definition: CSBMLunit.cpp:159
int mSymExpExp
Definition: CSBMLunit.h:91
INFO
this enum encodes the status of a units information
Definition: CSBMLunit.h:103
the units is determined from the model-wide definitions
Definition: CSBMLunit.h:110
void applyInverseExponent(const std::string &id, size_t frame)
apply inverse of symbolic exponent to the unit
Definition: CSBMLunit.cpp:140
INFO getInfo() const
get the status information
Definition: CSBMLunit.h:130
void setConflict(bool c)
set the conflict flag
Definition: CSBMLunit.h:133
int getSymbolicExpExp() const
Definition: CSBMLunit.h:72
const UnitDefinition & getSBMLUnitDefinition() const
Definition: CSBMLunit.h:70
the units if provided for a specific object explicitly
Definition: CSBMLunit.h:112
CSBMLunitInformation(unsigned int sbmlLevel, unsigned int sbmlVersion)
Default constructor.
Definition: CSBMLunit.cpp:182
UnitDefinition & getSBMLUnitDefinition()
Definition: CSBMLunit.h:69
SymbolicExponent mSymExp
Definition: CSBMLunit.h:90
static bool isEqual(const CSBMLunitInformation &unit1, const CSBMLunitInformation &unit2)
Definition: CSBMLunit.cpp:240
void setInfo(INFO info)
set the status information
Definition: CSBMLunit.h:127
the units was determined by reasoning
Definition: CSBMLunit.h:114
bool multiply(const CSBMLunit &unit)
Definition: CSBMLunit.cpp:60
const std::string & getSymbolicExponent() const
Definition: CSBMLunit.h:73
void invert()
Definition: CSBMLunit.cpp:88
bool isEqual(const SymbolicExponent &se) const
Definition: CSBMLunit.h:86
virtual ~CSBMLunit()
Definition: CSBMLunit.cpp:40
bool isConflict() const
retrieve the conflict flag
Definition: CSBMLunit.h:136