1 /**
2 * @file SedListOfAppliedDimensions.cpp
3 * @brief Implementation of the SedListOfAppliedDimensions 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/SedListOfAppliedDimensions.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 SedListOfAppliedDimensions using the given SED-ML Level and @
52 * p version values.
53 */
SedListOfAppliedDimensions(unsigned int level,unsigned int version)54 SedListOfAppliedDimensions::SedListOfAppliedDimensions(unsigned int level,
55 unsigned int
56 version)
57 : SedListOf(level, version)
58 {
59 setSedNamespacesAndOwn(new SedNamespaces(level, version));
60 }
61
62
63 /*
64 * Creates a new SedListOfAppliedDimensions using the given SedNamespaces
65 * object @p sedmlns.
66 */
SedListOfAppliedDimensions(SedNamespaces * sedmlns)67 SedListOfAppliedDimensions::SedListOfAppliedDimensions(SedNamespaces
68 *sedmlns)
69 : SedListOf(sedmlns)
70 {
71 setElementNamespace(sedmlns->getURI());
72 }
73
74
75 /*
76 * Copy constructor for SedListOfAppliedDimensions.
77 */
SedListOfAppliedDimensions(const SedListOfAppliedDimensions & orig)78 SedListOfAppliedDimensions::SedListOfAppliedDimensions(const
79 SedListOfAppliedDimensions& orig)
80 : SedListOf( orig )
81 {
82 }
83
84
85 /*
86 * Assignment operator for SedListOfAppliedDimensions.
87 */
88 SedListOfAppliedDimensions&
operator =(const SedListOfAppliedDimensions & rhs)89 SedListOfAppliedDimensions::operator=(const SedListOfAppliedDimensions&
90 rhs)
91 {
92 if (&rhs != this)
93 {
94 SedListOf::operator=(rhs);
95 }
96
97 return *this;
98 }
99
100
101 /*
102 * Creates and returns a deep copy of this SedListOfAppliedDimensions object.
103 */
104 SedListOfAppliedDimensions*
clone() const105 SedListOfAppliedDimensions::clone() const
106 {
107 return new SedListOfAppliedDimensions(*this);
108 }
109
110
111 /*
112 * Destructor for SedListOfAppliedDimensions.
113 */
~SedListOfAppliedDimensions()114 SedListOfAppliedDimensions::~SedListOfAppliedDimensions()
115 {
116 }
117
118
119 /*
120 * Get a SedAppliedDimension from the SedListOfAppliedDimensions.
121 */
122 SedAppliedDimension*
get(unsigned int n)123 SedListOfAppliedDimensions::get(unsigned int n)
124 {
125 return static_cast<SedAppliedDimension*>(SedListOf::get(n));
126 }
127
128
129 /*
130 * Get a SedAppliedDimension from the SedListOfAppliedDimensions.
131 */
132 const SedAppliedDimension*
get(unsigned int n) const133 SedListOfAppliedDimensions::get(unsigned int n) const
134 {
135 return static_cast<const SedAppliedDimension*>(SedListOf::get(n));
136 }
137
138
139 /*
140 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
141 * its identifier.
142 */
143 SedAppliedDimension*
get(const std::string & sid)144 SedListOfAppliedDimensions::get(const std::string& sid)
145 {
146 return const_cast<SedAppliedDimension*>(static_cast<const
147 SedListOfAppliedDimensions&>(*this).get(sid));
148 }
149
150
151 /*
152 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
153 * its identifier.
154 */
155 const SedAppliedDimension*
get(const std::string & sid) const156 SedListOfAppliedDimensions::get(const std::string& sid) const
157 {
158 vector<SedBase*>::const_iterator result;
159 result = find_if(mItems.begin(), mItems.end(),
160 SedIdEq<SedAppliedDimension>(sid));
161 return (result == mItems.end()) ? 0 : static_cast <const
162 SedAppliedDimension*> (*result);
163 }
164
165
166 /*
167 * Removes the nth SedAppliedDimension from this SedListOfAppliedDimensions
168 * and returns a pointer to it.
169 */
170 SedAppliedDimension*
remove(unsigned int n)171 SedListOfAppliedDimensions::remove(unsigned int n)
172 {
173 return static_cast<SedAppliedDimension*>(SedListOf::remove(n));
174 }
175
176
177 /*
178 * Removes the SedAppliedDimension from this SedListOfAppliedDimensions
179 * based on its identifier and returns a pointer to it.
180 */
181 SedAppliedDimension*
remove(const std::string & sid)182 SedListOfAppliedDimensions::remove(const std::string& sid)
183 {
184 SedBase* item = NULL;
185 vector<SedBase*>::iterator result;
186
187 result = find_if(mItems.begin(), mItems.end(),
188 SedIdEq<SedAppliedDimension>(sid));
189
190 if (result != mItems.end())
191 {
192 item = *result;
193 mItems.erase(result);
194 }
195
196 return static_cast <SedAppliedDimension*> (item);
197 }
198
199
200 /*
201 * Adds a copy of the given SedAppliedDimension to this
202 * SedListOfAppliedDimensions.
203 */
204 int
addAppliedDimension(const SedAppliedDimension * srd)205 SedListOfAppliedDimensions::addAppliedDimension(const
206 SedAppliedDimension* srd)
207 {
208 if (srd == NULL)
209 {
210 return LIBSEDML_OPERATION_FAILED;
211 }
212 else if (srd->hasRequiredAttributes() == false)
213 {
214 return LIBSEDML_INVALID_OBJECT;
215 }
216 else if (getLevel() != srd->getLevel())
217 {
218 return LIBSEDML_LEVEL_MISMATCH;
219 }
220 else if (getVersion() != srd->getVersion())
221 {
222 return LIBSEDML_VERSION_MISMATCH;
223 }
224 else if (matchesRequiredSedNamespacesForAddition(static_cast<const
225 SedBase*>(srd)) == false)
226 {
227 return LIBSEDML_NAMESPACES_MISMATCH;
228 }
229 else
230 {
231 return append(srd);
232 }
233 }
234
235
236 /*
237 * Get the number of SedAppliedDimension objects in this
238 * SedListOfAppliedDimensions.
239 */
240 unsigned int
getNumAppliedDimensions() const241 SedListOfAppliedDimensions::getNumAppliedDimensions() const
242 {
243 return size();
244 }
245
246
247 /*
248 * Creates a new SedAppliedDimension object, adds it to this
249 * SedListOfAppliedDimensions object and returns the SedAppliedDimension
250 * object created.
251 */
252 SedAppliedDimension*
createAppliedDimension()253 SedListOfAppliedDimensions::createAppliedDimension()
254 {
255 SedAppliedDimension* srd = NULL;
256
257 try
258 {
259 srd = new SedAppliedDimension(getSedNamespaces());
260 }
261 catch (...)
262 {
263 }
264
265 if (srd != NULL)
266 {
267 appendAndOwn(srd);
268 }
269
270 return srd;
271 }
272
273
274 /*
275 * Used by SedListOfAppliedDimensions::get() to lookup a
276 * SedAppliedDimension based on its Target.
277 */
278 struct SedIdEqT
279 {
280 const string& id;
281
SedIdEqTSedIdEqT282 SedIdEqT (const string& id) : id(id) { }
operator ()SedIdEqT283 bool operator() (SedBase* sb)
284 {
285 return (static_cast<SedAppliedDimension*>(sb)->getTarget() == id);
286 }
287 };
288
289
290 /*
291 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
292 * the Target to which it refers.
293 */
294 const SedAppliedDimension*
getByTarget(const std::string & sid) const295 SedListOfAppliedDimensions::getByTarget(const std::string& sid) const
296 {
297 vector<SedBase*>::const_iterator result;
298 result = find_if(mItems.begin(), mItems.end(), SedIdEqT(sid));
299 return (result == mItems.end()) ? 0 : static_cast <const
300 SedAppliedDimension*> (*result);
301 }
302
303
304 /*
305 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
306 * the Target to which it refers.
307 */
308 SedAppliedDimension*
getByTarget(const std::string & sid)309 SedListOfAppliedDimensions::getByTarget(const std::string& sid)
310 {
311 return const_cast<SedAppliedDimension*>(static_cast<const
312 SedListOfAppliedDimensions&>(*this).getByTarget(sid));
313 }
314
315
316 /*
317 * Used by SedListOfAppliedDimensions::get() to lookup a
318 * SedAppliedDimension based on its DimensionTarget.
319 */
320 struct SedIdEqDT
321 {
322 const string& id;
323
SedIdEqDTSedIdEqDT324 SedIdEqDT (const string& id) : id(id) { }
operator ()SedIdEqDT325 bool operator() (SedBase* sb)
326 {
327 return (static_cast<SedAppliedDimension*>(sb)->getDimensionTarget() == id);
328 }
329 };
330
331
332 /*
333 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
334 * the DimensionTarget to which it refers.
335 */
336 const SedAppliedDimension*
getByDimensionTarget(const std::string & sid) const337 SedListOfAppliedDimensions::getByDimensionTarget(const std::string& sid)
338 const
339 {
340 vector<SedBase*>::const_iterator result;
341 result = find_if(mItems.begin(), mItems.end(), SedIdEqDT(sid));
342 return (result == mItems.end()) ? 0 : static_cast <const
343 SedAppliedDimension*> (*result);
344 }
345
346
347 /*
348 * Get a SedAppliedDimension from the SedListOfAppliedDimensions based on
349 * the DimensionTarget to which it refers.
350 */
351 SedAppliedDimension*
getByDimensionTarget(const std::string & sid)352 SedListOfAppliedDimensions::getByDimensionTarget(const std::string& sid)
353 {
354 return const_cast<SedAppliedDimension*>(static_cast<const
355 SedListOfAppliedDimensions&>(*this).getByDimensionTarget(sid));
356 }
357
358
359 /*
360 * Returns the XML element name of this SedListOfAppliedDimensions object.
361 */
362 const std::string&
getElementName() const363 SedListOfAppliedDimensions::getElementName() const
364 {
365 static const string name = "listOfAppliedDimensions";
366 return name;
367 }
368
369
370 /*
371 * Returns the libSEDML type code for this SedListOfAppliedDimensions object.
372 */
373 int
getTypeCode() const374 SedListOfAppliedDimensions::getTypeCode() const
375 {
376 return SEDML_LIST_OF;
377 }
378
379
380 /*
381 * Returns the libSEDML type code for the SED-ML objects contained in this
382 * SedListOfAppliedDimensions object.
383 */
384 int
getItemTypeCode() const385 SedListOfAppliedDimensions::getItemTypeCode() const
386 {
387 return SEDML_APPLIEDDIMENSION;
388 }
389
390
391
392 /** @cond doxygenLibSEDMLInternal */
393
394 /*
395 * Creates a new SedAppliedDimension in this SedListOfAppliedDimensions
396 */
397 SedBase*
createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream & stream)398 SedListOfAppliedDimensions::createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER
399 XMLInputStream& stream)
400 {
401 const std::string& name = stream.peek().getName();
402 SedBase* object = NULL;
403
404 if (name == "appliedDimension")
405 {
406 object = new SedAppliedDimension(getSedNamespaces());
407 appendAndOwn(object);
408 }
409
410 return object;
411 }
412
413 /** @endcond */
414
415
416
417
418 #endif /* __cplusplus */
419
420
421 /*
422 * Get a SedAppliedDimension_t from the SedListOf_t.
423 */
424 LIBSEDML_EXTERN
425 SedAppliedDimension_t*
SedListOfAppliedDimensions_getAppliedDimension(SedListOf_t * slo,unsigned int n)426 SedListOfAppliedDimensions_getAppliedDimension(SedListOf_t* slo,
427 unsigned int n)
428 {
429 if (slo == NULL)
430 {
431 return NULL;
432 }
433
434 return static_cast <SedListOfAppliedDimensions*>(slo)->get(n);
435 }
436
437
438 /*
439 * Get a SedAppliedDimension_t from the SedListOf_t based on its identifier.
440 */
441 LIBSEDML_EXTERN
442 SedAppliedDimension_t*
SedListOfAppliedDimensions_getById(SedListOf_t * slo,const char * sid)443 SedListOfAppliedDimensions_getById(SedListOf_t* slo, const char *sid)
444 {
445 if (slo == NULL)
446 {
447 return NULL;
448 }
449
450 return (sid != NULL) ? static_cast
451 <SedListOfAppliedDimensions*>(slo)->get(sid) : NULL;
452 }
453
454
455 /*
456 * Removes the nth SedAppliedDimension_t from this SedListOf_t and returns a
457 * pointer to it.
458 */
459 LIBSEDML_EXTERN
460 SedAppliedDimension_t*
SedListOfAppliedDimensions_remove(SedListOf_t * slo,unsigned int n)461 SedListOfAppliedDimensions_remove(SedListOf_t* slo, unsigned int n)
462 {
463 if (slo == NULL)
464 {
465 return NULL;
466 }
467
468 return static_cast <SedListOfAppliedDimensions*>(slo)->remove(n);
469 }
470
471
472 /*
473 * Removes the SedAppliedDimension_t from this SedListOf_t based on its
474 * identifier and returns a pointer to it.
475 */
476 LIBSEDML_EXTERN
477 SedAppliedDimension_t*
SedListOfAppliedDimensions_removeById(SedListOf_t * slo,const char * sid)478 SedListOfAppliedDimensions_removeById(SedListOf_t* slo, const char* sid)
479 {
480 if (slo == NULL)
481 {
482 return NULL;
483 }
484
485 return (sid != NULL) ? static_cast
486 <SedListOfAppliedDimensions*>(slo)->remove(sid) : NULL;
487 }
488
489
490
491
492 LIBSEDML_CPP_NAMESPACE_END
493
494
495