1 /**
2 * @file SedLeastSquareObjectiveFunction.cpp
3 * @brief Implementation of the SedLeastSquareObjectiveFunction class.
4 * @author DEVISER
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSEDML. Please visit http://sed-ml.org for more
8 * information about SED-ML. The latest version of libSEDML can be found on
9 * github: https://github.com/fbergmann/libSEDML/
10 *
11
12 * Copyright (c) 2013-2019, Frank T. Bergmann
13 * All rights reserved.
14 *
15
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions are met:
18 *
19
20 * 1. Redistributions of source code must retain the above copyright notice,
21 * this
22 * list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright notice,
24 * this list of conditions and the following disclaimer in the documentation
25 * and/or other materials provided with the distribution.
26 *
27 * This library is free software; you can redistribute it and/or modify it
28 * under the terms of the GNU Lesser General Public License as published by the
29 * Free Software Foundation. A copy of the license agreement is provided in the
30 * file named "LICENSE.txt" included with this software distribution and also
31 * available online as http://sbml.org/software/libsbml/license.html
32 * ------------------------------------------------------------------------ -->
33 */
34 #include <sedml/SedLeastSquareObjectiveFunction.h>
35 #include <sbml/xml/XMLInputStream.h>
36
37
38 using namespace std;
39
40
41
42 LIBSEDML_CPP_NAMESPACE_BEGIN
43
44
45
46
47 #ifdef __cplusplus
48
49
50 /*
51 * Creates a new SedLeastSquareObjectiveFunction using the given SED-ML Level
52 * and @ p version values.
53 */
SedLeastSquareObjectiveFunction(unsigned int level,unsigned int version)54 SedLeastSquareObjectiveFunction::SedLeastSquareObjectiveFunction(
55 unsigned int
56 level,
57 unsigned int
58 version)
59 : SedObjective(level, version)
60 {
61 setSedNamespacesAndOwn(new SedNamespaces(level, version));
62 }
63
64
65 /*
66 * Creates a new SedLeastSquareObjectiveFunction using the given SedNamespaces
67 * object @p sedmlns.
68 */
SedLeastSquareObjectiveFunction(SedNamespaces * sedmlns)69 SedLeastSquareObjectiveFunction::SedLeastSquareObjectiveFunction(SedNamespaces
70 *sedmlns)
71 : SedObjective(sedmlns)
72 {
73 setElementNamespace(sedmlns->getURI());
74 }
75
76
77 /*
78 * Copy constructor for SedLeastSquareObjectiveFunction.
79 */
SedLeastSquareObjectiveFunction(const SedLeastSquareObjectiveFunction & orig)80 SedLeastSquareObjectiveFunction::SedLeastSquareObjectiveFunction(const
81 SedLeastSquareObjectiveFunction& orig)
82 : SedObjective( orig )
83 {
84 }
85
86
87 /*
88 * Assignment operator for SedLeastSquareObjectiveFunction.
89 */
90 SedLeastSquareObjectiveFunction&
operator =(const SedLeastSquareObjectiveFunction & rhs)91 SedLeastSquareObjectiveFunction::operator=(const
92 SedLeastSquareObjectiveFunction& rhs)
93 {
94 if (&rhs != this)
95 {
96 SedObjective::operator=(rhs);
97 }
98
99 return *this;
100 }
101
102
103 /*
104 * Creates and returns a deep copy of this SedLeastSquareObjectiveFunction
105 * object.
106 */
107 SedLeastSquareObjectiveFunction*
clone() const108 SedLeastSquareObjectiveFunction::clone() const
109 {
110 return new SedLeastSquareObjectiveFunction(*this);
111 }
112
113
114 /*
115 * Destructor for SedLeastSquareObjectiveFunction.
116 */
~SedLeastSquareObjectiveFunction()117 SedLeastSquareObjectiveFunction::~SedLeastSquareObjectiveFunction()
118 {
119 }
120
121
122 /*
123 * Returns the XML element name of this SedLeastSquareObjectiveFunction object.
124 */
125 const std::string&
getElementName() const126 SedLeastSquareObjectiveFunction::getElementName() const
127 {
128 static const string name = "leastSquareObjectiveFunction";
129 return name;
130 }
131
132
133 /*
134 * Returns the libSEDML type code for this SedLeastSquareObjectiveFunction
135 * object.
136 */
137 int
getTypeCode() const138 SedLeastSquareObjectiveFunction::getTypeCode() const
139 {
140 return SEDML_LEAST_SQUARE_OBJECTIVE;
141 }
142
143
144 /*
145 * Predicate returning @c true if all the required attributes for this
146 * SedLeastSquareObjectiveFunction object have been set.
147 */
148 bool
hasRequiredAttributes() const149 SedLeastSquareObjectiveFunction::hasRequiredAttributes() const
150 {
151 bool allPresent = SedObjective::hasRequiredAttributes();
152
153 return allPresent;
154 }
155
156
157
158 /** @cond doxygenLibSEDMLInternal */
159
160 /*
161 * Write any contained elements
162 */
163 void
writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const164 SedLeastSquareObjectiveFunction::writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER
165 XMLOutputStream& stream) const
166 {
167 SedObjective::writeElements(stream);
168 }
169
170 /** @endcond */
171
172
173
174 /** @cond doxygenLibSEDMLInternal */
175
176 /*
177 * Accepts the given SedVisitor
178 */
179 bool
accept(SedVisitor & v) const180 SedLeastSquareObjectiveFunction::accept(SedVisitor& v) const
181 {
182 return false;
183 }
184
185 /** @endcond */
186
187
188
189 /** @cond doxygenLibSEDMLInternal */
190
191 /*
192 * Sets the parent SedDocument
193 */
194 void
setSedDocument(SedDocument * d)195 SedLeastSquareObjectiveFunction::setSedDocument(SedDocument* d)
196 {
197 SedObjective::setSedDocument(d);
198 }
199
200 /** @endcond */
201
202
203
204 /** @cond doxygenLibSEDMLInternal */
205
206 /*
207 * Gets the value of the "attributeName" attribute of this
208 * SedLeastSquareObjectiveFunction.
209 */
210 int
getAttribute(const std::string & attributeName,bool & value) const211 SedLeastSquareObjectiveFunction::getAttribute(const std::string& attributeName,
212 bool& value) const
213 {
214 int return_value = SedObjective::getAttribute(attributeName, value);
215
216 return return_value;
217 }
218
219 /** @endcond */
220
221
222
223 /** @cond doxygenLibSEDMLInternal */
224
225 /*
226 * Gets the value of the "attributeName" attribute of this
227 * SedLeastSquareObjectiveFunction.
228 */
229 int
getAttribute(const std::string & attributeName,int & value) const230 SedLeastSquareObjectiveFunction::getAttribute(const std::string& attributeName,
231 int& value) const
232 {
233 int return_value = SedObjective::getAttribute(attributeName, value);
234
235 return return_value;
236 }
237
238 /** @endcond */
239
240
241
242 /** @cond doxygenLibSEDMLInternal */
243
244 /*
245 * Gets the value of the "attributeName" attribute of this
246 * SedLeastSquareObjectiveFunction.
247 */
248 int
getAttribute(const std::string & attributeName,double & value) const249 SedLeastSquareObjectiveFunction::getAttribute(const std::string& attributeName,
250 double& value) const
251 {
252 int return_value = SedObjective::getAttribute(attributeName, value);
253
254 return return_value;
255 }
256
257 /** @endcond */
258
259
260
261 /** @cond doxygenLibSEDMLInternal */
262
263 /*
264 * Gets the value of the "attributeName" attribute of this
265 * SedLeastSquareObjectiveFunction.
266 */
267 int
getAttribute(const std::string & attributeName,unsigned int & value) const268 SedLeastSquareObjectiveFunction::getAttribute(const std::string& attributeName,
269 unsigned int& value) const
270 {
271 int return_value = SedObjective::getAttribute(attributeName, value);
272
273 return return_value;
274 }
275
276 /** @endcond */
277
278
279
280 /** @cond doxygenLibSEDMLInternal */
281
282 /*
283 * Gets the value of the "attributeName" attribute of this
284 * SedLeastSquareObjectiveFunction.
285 */
286 int
getAttribute(const std::string & attributeName,std::string & value) const287 SedLeastSquareObjectiveFunction::getAttribute(const std::string& attributeName,
288 std::string& value) const
289 {
290 int return_value = SedObjective::getAttribute(attributeName, value);
291
292 return return_value;
293 }
294
295 /** @endcond */
296
297
298
299 /** @cond doxygenLibSEDMLInternal */
300
301 /*
302 * Predicate returning @c true if this SedLeastSquareObjectiveFunction's
303 * attribute "attributeName" is set.
304 */
305 bool
isSetAttribute(const std::string & attributeName) const306 SedLeastSquareObjectiveFunction::isSetAttribute(const std::string&
307 attributeName) const
308 {
309 bool value = SedObjective::isSetAttribute(attributeName);
310
311 return value;
312 }
313
314 /** @endcond */
315
316
317
318 /** @cond doxygenLibSEDMLInternal */
319
320 /*
321 * Sets the value of the "attributeName" attribute of this
322 * SedLeastSquareObjectiveFunction.
323 */
324 int
setAttribute(const std::string & attributeName,bool value)325 SedLeastSquareObjectiveFunction::setAttribute(const std::string& attributeName,
326 bool value)
327 {
328 int return_value = SedObjective::setAttribute(attributeName, value);
329
330 return return_value;
331 }
332
333 /** @endcond */
334
335
336
337 /** @cond doxygenLibSEDMLInternal */
338
339 /*
340 * Sets the value of the "attributeName" attribute of this
341 * SedLeastSquareObjectiveFunction.
342 */
343 int
setAttribute(const std::string & attributeName,int value)344 SedLeastSquareObjectiveFunction::setAttribute(const std::string& attributeName,
345 int value)
346 {
347 int return_value = SedObjective::setAttribute(attributeName, value);
348
349 return return_value;
350 }
351
352 /** @endcond */
353
354
355
356 /** @cond doxygenLibSEDMLInternal */
357
358 /*
359 * Sets the value of the "attributeName" attribute of this
360 * SedLeastSquareObjectiveFunction.
361 */
362 int
setAttribute(const std::string & attributeName,double value)363 SedLeastSquareObjectiveFunction::setAttribute(const std::string& attributeName,
364 double value)
365 {
366 int return_value = SedObjective::setAttribute(attributeName, value);
367
368 return return_value;
369 }
370
371 /** @endcond */
372
373
374
375 /** @cond doxygenLibSEDMLInternal */
376
377 /*
378 * Sets the value of the "attributeName" attribute of this
379 * SedLeastSquareObjectiveFunction.
380 */
381 int
setAttribute(const std::string & attributeName,unsigned int value)382 SedLeastSquareObjectiveFunction::setAttribute(const std::string& attributeName,
383 unsigned int value)
384 {
385 int return_value = SedObjective::setAttribute(attributeName, value);
386
387 return return_value;
388 }
389
390 /** @endcond */
391
392
393
394 /** @cond doxygenLibSEDMLInternal */
395
396 /*
397 * Sets the value of the "attributeName" attribute of this
398 * SedLeastSquareObjectiveFunction.
399 */
400 int
setAttribute(const std::string & attributeName,const std::string & value)401 SedLeastSquareObjectiveFunction::setAttribute(const std::string& attributeName,
402 const std::string& value)
403 {
404 int return_value = SedObjective::setAttribute(attributeName, value);
405
406 return return_value;
407 }
408
409 /** @endcond */
410
411
412
413 /** @cond doxygenLibSEDMLInternal */
414
415 /*
416 * Unsets the value of the "attributeName" attribute of this
417 * SedLeastSquareObjectiveFunction.
418 */
419 int
unsetAttribute(const std::string & attributeName)420 SedLeastSquareObjectiveFunction::unsetAttribute(const std::string&
421 attributeName)
422 {
423 int value = SedObjective::unsetAttribute(attributeName);
424
425 return value;
426 }
427
428 /** @endcond */
429
430
431
432 /** @cond doxygenLibSEDMLInternal */
433
434 /*
435 * Creates a new object from the next XMLToken on the XMLInputStream
436 */
437 SedBase*
createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream & stream)438 SedLeastSquareObjectiveFunction::createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER
439 XMLInputStream& stream)
440 {
441 SedBase* obj = SedObjective::createObject(stream);
442
443 connectToChild();
444
445 return obj;
446 }
447
448 /** @endcond */
449
450
451
452 /** @cond doxygenLibSEDMLInternal */
453
454 /*
455 * Adds the expected attributes for this element
456 */
457 void
addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & attributes)458 SedLeastSquareObjectiveFunction::addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
459 ExpectedAttributes& attributes)
460 {
461 SedObjective::addExpectedAttributes(attributes);
462 }
463
464 /** @endcond */
465
466
467
468 /** @cond doxygenLibSEDMLInternal */
469
470 /*
471 * Reads the expected attributes into the member data variables
472 */
473 void
readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes,const LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & expectedAttributes)474 SedLeastSquareObjectiveFunction::readAttributes(
475 const
476 LIBSBML_CPP_NAMESPACE_QUALIFIER
477 XMLAttributes& attributes,
478 const
479 LIBSBML_CPP_NAMESPACE_QUALIFIER
480 ExpectedAttributes&
481 expectedAttributes)
482 {
483 unsigned int level = getLevel();
484 unsigned int version = getVersion();
485 unsigned int numErrs;
486 bool assigned = false;
487 SedErrorLog* log = getErrorLog();
488
489 SedObjective::readAttributes(attributes, expectedAttributes);
490
491 if (log)
492 {
493 numErrs = log->getNumErrors();
494
495 for (int n = numErrs-1; n >= 0; n--)
496 {
497 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
498 {
499 const std::string details = log->getError(n)->getMessage();
500 log->remove(SedUnknownCoreAttribute);
501 log->logError(SedUnknown, level, version, details, getLine(),
502 getColumn());
503 }
504 }
505 }
506 }
507
508 /** @endcond */
509
510
511
512 /** @cond doxygenLibSEDMLInternal */
513
514 /*
515 * Writes the attributes to the stream
516 */
517 void
writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const518 SedLeastSquareObjectiveFunction::writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
519 XMLOutputStream& stream) const
520 {
521 SedObjective::writeAttributes(stream);
522 }
523
524 /** @endcond */
525
526
527
528
529 #endif /* __cplusplus */
530
531
532 /*
533 * Creates a new SedLeastSquareObjectiveFunction_t using the given SED-ML Level
534 * and @ p version values.
535 */
536 LIBSEDML_EXTERN
537 SedLeastSquareObjectiveFunction_t *
SedLeastSquareObjectiveFunction_create(unsigned int level,unsigned int version)538 SedLeastSquareObjectiveFunction_create(unsigned int level,
539 unsigned int version)
540 {
541 return new SedLeastSquareObjectiveFunction(level, version);
542 }
543
544
545 /*
546 * Creates and returns a deep copy of this SedLeastSquareObjectiveFunction_t
547 * object.
548 */
549 LIBSEDML_EXTERN
550 SedLeastSquareObjectiveFunction_t*
SedLeastSquareObjectiveFunction_clone(const SedLeastSquareObjectiveFunction_t * slsof)551 SedLeastSquareObjectiveFunction_clone(const SedLeastSquareObjectiveFunction_t*
552 slsof)
553 {
554 if (slsof != NULL)
555 {
556 return static_cast<SedLeastSquareObjectiveFunction_t*>(slsof->clone());
557 }
558 else
559 {
560 return NULL;
561 }
562 }
563
564
565 /*
566 * Frees this SedLeastSquareObjectiveFunction_t object.
567 */
568 LIBSEDML_EXTERN
569 void
SedLeastSquareObjectiveFunction_free(SedLeastSquareObjectiveFunction_t * slsof)570 SedLeastSquareObjectiveFunction_free(SedLeastSquareObjectiveFunction_t* slsof)
571 {
572 if (slsof != NULL)
573 {
574 delete slsof;
575 }
576 }
577
578
579 /*
580 * Predicate returning @c 1 (true) if all the required attributes for this
581 * SedLeastSquareObjectiveFunction_t object have been set.
582 */
583 LIBSEDML_EXTERN
584 int
SedLeastSquareObjectiveFunction_hasRequiredAttributes(const SedLeastSquareObjectiveFunction_t * slsof)585 SedLeastSquareObjectiveFunction_hasRequiredAttributes(const
586 SedLeastSquareObjectiveFunction_t * slsof)
587 {
588 return (slsof != NULL) ? static_cast<int>(slsof->hasRequiredAttributes()) :
589 0;
590 }
591
592
593
594
595 LIBSEDML_CPP_NAMESPACE_END
596
597
598