1 /**
2 * @file SedListOfOutputs.cpp
3 * @brief Implementation of the SedListOfOutputs 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/SedListOfOutputs.h>
35 #include <sbml/xml/XMLInputStream.h>
36
37 #include <sedml/SedReport.h>
38 #include <sedml/SedPlot2D.h>
39 #include <sedml/SedPlot3D.h>
40 #include <sedml/SedFigure.h>
41 #include <sedml/SedParameterEstimationResultPlot.h>
42
43
44 using namespace std;
45
46
47
48 LIBSEDML_CPP_NAMESPACE_BEGIN
49
50
51
52
53 #ifdef __cplusplus
54
55
56 /*
57 * Creates a new SedListOfOutputs using the given SED-ML Level and @ p version
58 * values.
59 */
SedListOfOutputs(unsigned int level,unsigned int version)60 SedListOfOutputs::SedListOfOutputs(unsigned int level, unsigned int version)
61 : SedListOf(level, version)
62 , mElementName("listOfOutputs")
63 {
64 setSedNamespacesAndOwn(new SedNamespaces(level, version));
65 }
66
67
68 /*
69 * Creates a new SedListOfOutputs using the given SedNamespaces object @p
70 * sedmlns.
71 */
SedListOfOutputs(SedNamespaces * sedmlns)72 SedListOfOutputs::SedListOfOutputs(SedNamespaces *sedmlns)
73 : SedListOf(sedmlns)
74 , mElementName("listOfOutputs")
75 {
76 setElementNamespace(sedmlns->getURI());
77 }
78
79
80 /*
81 * Copy constructor for SedListOfOutputs.
82 */
SedListOfOutputs(const SedListOfOutputs & orig)83 SedListOfOutputs::SedListOfOutputs(const SedListOfOutputs& orig)
84 : SedListOf( orig )
85 , mElementName ( orig.mElementName )
86 {
87 }
88
89
90 /*
91 * Assignment operator for SedListOfOutputs.
92 */
93 SedListOfOutputs&
operator =(const SedListOfOutputs & rhs)94 SedListOfOutputs::operator=(const SedListOfOutputs& rhs)
95 {
96 if (&rhs != this)
97 {
98 SedListOf::operator=(rhs);
99 mElementName = rhs.mElementName;
100 }
101
102 return *this;
103 }
104
105
106 /*
107 * Creates and returns a deep copy of this SedListOfOutputs object.
108 */
109 SedListOfOutputs*
clone() const110 SedListOfOutputs::clone() const
111 {
112 return new SedListOfOutputs(*this);
113 }
114
115
116 /*
117 * Destructor for SedListOfOutputs.
118 */
~SedListOfOutputs()119 SedListOfOutputs::~SedListOfOutputs()
120 {
121 }
122
123
124 /*
125 * Get a SedOutput from the SedListOfOutputs.
126 */
127 SedOutput*
get(unsigned int n)128 SedListOfOutputs::get(unsigned int n)
129 {
130 return static_cast<SedOutput*>(SedListOf::get(n));
131 }
132
133
134 /*
135 * Get a SedOutput from the SedListOfOutputs.
136 */
137 const SedOutput*
get(unsigned int n) const138 SedListOfOutputs::get(unsigned int n) const
139 {
140 return static_cast<const SedOutput*>(SedListOf::get(n));
141 }
142
143
144 /*
145 * Get a SedOutput from the SedListOfOutputs based on its identifier.
146 */
147 SedOutput*
get(const std::string & sid)148 SedListOfOutputs::get(const std::string& sid)
149 {
150 return const_cast<SedOutput*>(static_cast<const
151 SedListOfOutputs&>(*this).get(sid));
152 }
153
154
155 /*
156 * Get a SedOutput from the SedListOfOutputs based on its identifier.
157 */
158 const SedOutput*
get(const std::string & sid) const159 SedListOfOutputs::get(const std::string& sid) const
160 {
161 vector<SedBase*>::const_iterator result;
162 result = find_if(mItems.begin(), mItems.end(), SedIdEq<SedOutput>(sid));
163 return (result == mItems.end()) ? 0 : static_cast <const SedOutput*>
164 (*result);
165 }
166
167
168 /*
169 * Removes the nth SedOutput from this SedListOfOutputs and returns a pointer
170 * to it.
171 */
172 SedOutput*
remove(unsigned int n)173 SedListOfOutputs::remove(unsigned int n)
174 {
175 return static_cast<SedOutput*>(SedListOf::remove(n));
176 }
177
178
179 /*
180 * Removes the SedOutput from this SedListOfOutputs based on its identifier and
181 * returns a pointer to it.
182 */
183 SedOutput*
remove(const std::string & sid)184 SedListOfOutputs::remove(const std::string& sid)
185 {
186 SedBase* item = NULL;
187 vector<SedBase*>::iterator result;
188
189 result = find_if(mItems.begin(), mItems.end(), SedIdEq<SedOutput>(sid));
190
191 if (result != mItems.end())
192 {
193 item = *result;
194 mItems.erase(result);
195 }
196
197 return static_cast <SedOutput*> (item);
198 }
199
200
201 /*
202 * Adds a copy of the given SedOutput to this SedListOfOutputs.
203 */
204 int
addOutput(const SedOutput * so)205 SedListOfOutputs::addOutput(const SedOutput* so)
206 {
207 if (so == NULL)
208 {
209 return LIBSEDML_OPERATION_FAILED;
210 }
211 else if (so->hasRequiredAttributes() == false)
212 {
213 return LIBSEDML_INVALID_OBJECT;
214 }
215 else if (getLevel() != so->getLevel())
216 {
217 return LIBSEDML_LEVEL_MISMATCH;
218 }
219 else if (getVersion() != so->getVersion())
220 {
221 return LIBSEDML_VERSION_MISMATCH;
222 }
223 else if (matchesRequiredSedNamespacesForAddition(static_cast<const
224 SedBase*>(so)) == false)
225 {
226 return LIBSEDML_NAMESPACES_MISMATCH;
227 }
228 else
229 {
230 return append(so);
231 }
232 }
233
234
235 /*
236 * Get the number of SedOutput objects in this SedListOfOutputs.
237 */
238 unsigned int
getNumOutputs() const239 SedListOfOutputs::getNumOutputs() const
240 {
241 return size();
242 }
243
244
245 /*
246 * Creates a new SedReport object, adds it to this SedListOfOutputs object and
247 * returns the SedReport object created.
248 */
249 SedReport*
createReport()250 SedListOfOutputs::createReport()
251 {
252 SedReport* sr = NULL;
253
254 try
255 {
256 sr = new SedReport(getSedNamespaces());
257 }
258 catch (...)
259 {
260 }
261
262 if (sr != NULL)
263 {
264 appendAndOwn(sr);
265 }
266
267 return sr;
268 }
269
270
271 /*
272 * Creates a new SedPlot2D object, adds it to this SedListOfOutputs object and
273 * returns the SedPlot2D object created.
274 */
275 SedPlot2D*
createPlot2D()276 SedListOfOutputs::createPlot2D()
277 {
278 SedPlot2D* spd = NULL;
279
280 try
281 {
282 spd = new SedPlot2D(getSedNamespaces());
283 }
284 catch (...)
285 {
286 }
287
288 if (spd != NULL)
289 {
290 appendAndOwn(spd);
291 }
292
293 return spd;
294 }
295
296
297 /*
298 * Creates a new SedPlot3D object, adds it to this SedListOfOutputs object and
299 * returns the SedPlot3D object created.
300 */
301 SedPlot3D*
createPlot3D()302 SedListOfOutputs::createPlot3D()
303 {
304 SedPlot3D* spd = NULL;
305
306 try
307 {
308 spd = new SedPlot3D(getSedNamespaces());
309 }
310 catch (...)
311 {
312 }
313
314 if (spd != NULL)
315 {
316 appendAndOwn(spd);
317 }
318
319 return spd;
320 }
321
322
323 /*
324 * Creates a new SedFigure object, adds it to this SedListOfOutputs object and
325 * returns the SedFigure object created.
326 */
327 SedFigure*
createFigure()328 SedListOfOutputs::createFigure()
329 {
330 SedFigure* sf = NULL;
331
332 try
333 {
334 sf = new SedFigure(getSedNamespaces());
335 }
336 catch (...)
337 {
338 }
339
340 if (sf != NULL)
341 {
342 appendAndOwn(sf);
343 }
344
345 return sf;
346 }
347
348
349 /*
350 * Creates a new SedParameterEstimationResultPlot object, adds it to this
351 * SedListOfOutputs object and returns the SedParameterEstimationResultPlot
352 * object created.
353 */
354 SedParameterEstimationResultPlot*
createParameterEstimationResultPlot()355 SedListOfOutputs::createParameterEstimationResultPlot()
356 {
357 SedParameterEstimationResultPlot* sperp = NULL;
358
359 try
360 {
361 sperp = new SedParameterEstimationResultPlot(getSedNamespaces());
362 }
363 catch (...)
364 {
365 }
366
367 if (sperp != NULL)
368 {
369 appendAndOwn(sperp);
370 }
371
372 return sperp;
373 }
374
375
376 /*
377 * Returns the XML element name of this SedListOfOutputs object.
378 */
379 const std::string&
getElementName() const380 SedListOfOutputs::getElementName() const
381 {
382 return mElementName;
383 }
384
385
386
387 /** @cond doxygenLibSEDMLInternal */
388
389 /*
390 * Sets the XML name of this SedListOfOutputs object.
391 */
392 void
setElementName(const std::string & name)393 SedListOfOutputs::setElementName(const std::string& name)
394 {
395 mElementName = name;
396 }
397
398 /** @endcond */
399
400
401 /*
402 * Returns the libSEDML type code for this SedListOfOutputs object.
403 */
404 int
getTypeCode() const405 SedListOfOutputs::getTypeCode() const
406 {
407 return SEDML_LIST_OF;
408 }
409
410
411 /*
412 * Returns the libSEDML type code for the SED-ML objects contained in this
413 * SedListOfOutputs object.
414 */
415 int
getItemTypeCode() const416 SedListOfOutputs::getItemTypeCode() const
417 {
418 return SEDML_OUTPUT;
419 }
420
421
422
423 /** @cond doxygenLibSEDMLInternal */
424
425 /*
426 * Creates a new SedOutput in this SedListOfOutputs
427 */
428 SedBase*
createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream & stream)429 SedListOfOutputs::createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream&
430 stream)
431 {
432 const std::string& name = stream.peek().getName();
433 SedBase* object = NULL;
434
435 if (name == "output")
436 {
437 object = new SedOutput(getSedNamespaces());
438 appendAndOwn(object);
439 }
440
441 if (name == "report")
442 {
443 object = new SedReport(getSedNamespaces());
444 appendAndOwn(object);
445 }
446
447 if (name == "plot2D")
448 {
449 object = new SedPlot2D(getSedNamespaces());
450 appendAndOwn(object);
451 }
452
453 if (name == "plot3D")
454 {
455 object = new SedPlot3D(getSedNamespaces());
456 appendAndOwn(object);
457 }
458
459 if (name == "figure")
460 {
461 object = new SedFigure(getSedNamespaces());
462 appendAndOwn(object);
463 }
464
465 if (name == "parameterEstimationResultPlot")
466 {
467 object = new SedParameterEstimationResultPlot(getSedNamespaces());
468 appendAndOwn(object);
469 }
470
471 return object;
472 }
473
474 /** @endcond */
475
476
477
478 /** @cond doxygenLibSEDMLInternal */
479
480 /*
481 * checks concrete types
482 */
483 bool
isValidTypeForList(SedBase * item)484 SedListOfOutputs::isValidTypeForList(SedBase* item)
485 {
486 unsigned int tc = item->getTypeCode();
487
488 return ((tc == SEDML_OUTPUT_REPORT) || (tc == SEDML_OUTPUT_PLOT2D) || (tc ==
489 SEDML_OUTPUT_PLOT3D) || (tc == SEDML_FIGURE) || (tc ==
490 SEDML_PARAMETERESTIMATIONRESULTPLOT));
491 }
492
493 /** @endcond */
494
495
496
497
498 #endif /* __cplusplus */
499
500
501 /*
502 * Get a SedOutput_t from the SedListOf_t.
503 */
504 LIBSEDML_EXTERN
505 SedOutput_t*
SedListOfOutputs_getOutput(SedListOf_t * slo,unsigned int n)506 SedListOfOutputs_getOutput(SedListOf_t* slo, unsigned int n)
507 {
508 if (slo == NULL)
509 {
510 return NULL;
511 }
512
513 return static_cast <SedListOfOutputs*>(slo)->get(n);
514 }
515
516
517 /*
518 * Get a SedOutput_t from the SedListOf_t based on its identifier.
519 */
520 LIBSEDML_EXTERN
521 SedOutput_t*
SedListOfOutputs_getById(SedListOf_t * slo,const char * sid)522 SedListOfOutputs_getById(SedListOf_t* slo, const char *sid)
523 {
524 if (slo == NULL)
525 {
526 return NULL;
527 }
528
529 return (sid != NULL) ? static_cast <SedListOfOutputs*>(slo)->get(sid) : NULL;
530 }
531
532
533 /*
534 * Removes the nth SedOutput_t from this SedListOf_t and returns a pointer to
535 * it.
536 */
537 LIBSEDML_EXTERN
538 SedOutput_t*
SedListOfOutputs_remove(SedListOf_t * slo,unsigned int n)539 SedListOfOutputs_remove(SedListOf_t* slo, unsigned int n)
540 {
541 if (slo == NULL)
542 {
543 return NULL;
544 }
545
546 return static_cast <SedListOfOutputs*>(slo)->remove(n);
547 }
548
549
550 /*
551 * Removes the SedOutput_t from this SedListOf_t based on its identifier and
552 * returns a pointer to it.
553 */
554 LIBSEDML_EXTERN
555 SedOutput_t*
SedListOfOutputs_removeById(SedListOf_t * slo,const char * sid)556 SedListOfOutputs_removeById(SedListOf_t* slo, const char* sid)
557 {
558 if (slo == NULL)
559 {
560 return NULL;
561 }
562
563 return (sid != NULL) ? static_cast <SedListOfOutputs*>(slo)->remove(sid) :
564 NULL;
565 }
566
567
568
569
570 LIBSEDML_CPP_NAMESPACE_END
571
572
573