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