1 /**
2  * @file    SBMLInferUnitsConverter.h
3  * @brief   Definition of SBMLInferUnitsConverter, infers units for parameters.
4  * @author  Sarah Keating
5  *
6  * <!--------------------------------------------------------------------------
7  * This file is part of libSBML.  Please visit http://sbml.org for more
8  * information about SBML, and the latest version of libSBML.
9  *
10  * Copyright (C) 2020 jointly by the following organizations:
11  *     1. California Institute of Technology, Pasadena, CA, USA
12  *     2. University of Heidelberg, Heidelberg, Germany
13  *     3. University College London, London, UK
14  *
15  * Copyright (C) 2019 jointly by the following organizations:
16  *     1. California Institute of Technology, Pasadena, CA, USA
17  *     2. University of Heidelberg, Heidelberg, Germany
18  *
19  * Copyright (C) 2013-2018 jointly by the following organizations:
20  *     1. California Institute of Technology, Pasadena, CA, USA
21  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22  *     3. University of Heidelberg, Heidelberg, Germany
23  *
24  * Copyright (C) 2009-2013 jointly by the following organizations:
25  *     1. California Institute of Technology, Pasadena, CA, USA
26  *     2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27  *
28  * Copyright (C) 2006-2008 by the California Institute of Technology,
29  *     Pasadena, CA, USA
30  *
31  * Copyright (C) 2002-2005 jointly by the following organizations:
32  *     1. California Institute of Technology, Pasadena, CA, USA
33  *     2. Japan Science and Technology Agency, Japan
34  *
35  * This library is free software; you can redistribute it and/or modify it
36  * under the terms of the GNU Lesser General Public License as published by
37  * the Free Software Foundation.  A copy of the license agreement is provided
38  * in the file named "LICENSE.txt" included with this software distribution
39  * and also available online as http://sbml.org/software/libsbml/license.html
40  * ------------------------------------------------------------------------ -->
41  *
42  * @class SBMLInferUnitsConverter
43  * @sbmlbrief{core} Converter for inferring and setting parameter units.
44  *
45  * @htmlinclude libsbml-facility-only-warning.html
46  *
47  * This SBML converter takes an SBML document and attempts to infer units for
48  * any Parameter objects whose units are undeclared.  It then sets the
49  * "units" attribute of those parameters to the units inferred (if necessary,
50  * creating new UnitDefinition objects on the model in the process).
51  *
52  * @section SBMLInferUnitsConverter-usage Configuration and use of SBMLInferUnitsConverter
53  *
54  * SBMLInferUnitsConverter is enabled by creating a ConversionProperties
55  * object with the option @c "inferUnits", and passing this
56  * properties object to SBMLDocument::convert(@if java ConversionProperties@endif).
57  * The converter offers no other options.
58  *
59  * @copydetails doc_section_using_sbml_converters
60  */
61 
62 #ifndef SBMLInferUnitsConverter_h
63 #define SBMLInferUnitsConverter_h
64 
65 #include <sbml/conversion/SBMLConverter.h>
66 #include <sbml/conversion/SBMLConverterRegister.h>
67 
68 
69 
70 #ifdef __cplusplus
71 
72 
73 LIBSBML_CPP_NAMESPACE_BEGIN
74 
75 
76 class LIBSBML_EXTERN  SBMLInferUnitsConverter : public SBMLConverter
77 {
78 public:
79 
80   /** @cond doxygenLibsbmlInternal */
81   /**
82    * Register with the ConversionRegistry.
83    */
84   static void init();
85 
86   /** @endcond */
87 
88 
89   /**
90    * Creates a new SBMLInferUnitsConverter object.
91    */
92   SBMLInferUnitsConverter ();
93 
94 
95   /**
96    * Copy constructor; creates a copy of an SBMLInferUnitsConverter
97    * object.
98    *
99    * @param obj the SBMLInferUnitsConverter object to copy.
100    */
101   SBMLInferUnitsConverter(const SBMLInferUnitsConverter& obj);
102 
103 
104   /**
105    * Destroys this object.
106    */
107   virtual ~SBMLInferUnitsConverter ();
108 
109 
110   /**
111    * Assignment operator for SBMLInferUnitsConverter.
112    *
113    * @param rhs the object whose values are used as the basis of the
114    * assignment.
115    */
116   SBMLInferUnitsConverter& operator=(const SBMLInferUnitsConverter& rhs);
117 
118 
119   /**
120    * Creates and returns a deep copy of this SBMLInferUnitsConverter
121    * object.
122    *
123    * @return a (deep) copy of this converter.
124    */
125   virtual SBMLInferUnitsConverter* clone() const;
126 
127 
128   /**
129    * Returns @c true if this converter object's properties match the given
130    * properties.
131    *
132    * A typical use of this method involves creating a ConversionProperties
133    * object, setting the options desired, and then calling this method on
134    * an SBMLInferUnitsConverter object to find out if the object's
135    * property values match the given ones.  This method is also used by
136    * SBMLConverterRegistry::getConverterFor(@if java ConversionProperties@endif)
137    * to search across all registered converters for one matching particular
138    * properties.
139    *
140    * @param props the properties to match.
141    *
142    * @return @c true if this converter's properties match, @c false
143    * otherwise.
144    */
145   virtual bool matchesProperties(const ConversionProperties &props) const;
146 
147 
148   /**
149    * Perform the conversion.
150    *
151    * This method causes the converter to do the actual conversion work,
152    * that is, to convert the SBMLDocument object set by
153    * SBMLConverter::setDocument(@if java SBMLDocument@endif) and
154    * with the configuration options set by
155    * SBMLConverter::setProperties(@if java ConversionProperties@endif).
156    *
157    * @copydetails doc_returns_success_code
158    * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t}
159    * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t}
160    * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t}
161    * @li @sbmlconstant{LIBSBML_CONV_INVALID_SRC_DOCUMENT, OperationReturnValues_t}
162    */
163   virtual int convert();
164 
165 
166   /**
167    * Returns the default properties of this converter.
168    *
169    * A given converter exposes one or more properties that can be adjusted
170    * in order to influence the behavior of the converter.  This method
171    * returns the @em default property settings for this converter.  It is
172    * meant to be called in order to discover all the settings for the
173    * converter object.
174    *
175    * @return the ConversionProperties object describing the default properties
176    * for this converter.
177    */
178   virtual ConversionProperties getDefaultProperties() const;
179 
180 
181   /* Convenience functions for this converter */
182 
183 
184 #ifndef SWIG
185 
186 #endif // SWIG
187 
188 
189 private:
190   /** @cond doxygenLibsbmlInternal */
191   std::string existsAlready(Model& m, UnitDefinition *newUD);
192 
193   unsigned int newIdCount;
194 
195 
196   /** @endcond */
197 };
198 
199 
200 LIBSBML_CPP_NAMESPACE_END
201 
202 #endif  /* __cplusplus */
203 
204 
205 #ifndef SWIG
206 
207 LIBSBML_CPP_NAMESPACE_BEGIN
208 BEGIN_C_DECLS
209 
210 
211 END_C_DECLS
212 LIBSBML_CPP_NAMESPACE_END
213 
214 #endif  /* !SWIG */
215 #endif  /* SBMLInferUnitsConverter_h */
216 
217