1 /**
2 * @file SedFill.cpp
3 * @brief Implementation of the SedFill 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/SedFill.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 SedFill using the given SED-ML Level and @ p version values.
52 */
SedFill(unsigned int level,unsigned int version)53 SedFill::SedFill(unsigned int level, unsigned int version)
54 : SedBase(level, version)
55 , mColor ("")
56 //, mSecondColor ("")
57 {
58 setSedNamespacesAndOwn(new SedNamespaces(level, version));
59 }
60
61
62 /*
63 * Creates a new SedFill using the given SedNamespaces object @p sedmlns.
64 */
SedFill(SedNamespaces * sedmlns)65 SedFill::SedFill(SedNamespaces *sedmlns)
66 : SedBase(sedmlns)
67 , mColor ("")
68 //, mSecondColor ("")
69 {
70 setElementNamespace(sedmlns->getURI());
71 }
72
73
74 /*
75 * Copy constructor for SedFill.
76 */
SedFill(const SedFill & orig)77 SedFill::SedFill(const SedFill& orig)
78 : SedBase( orig )
79 , mColor ( orig.mColor )
80 //, mSecondColor ( orig.mSecondColor )
81 {
82 }
83
84
85 /*
86 * Assignment operator for SedFill.
87 */
88 SedFill&
operator =(const SedFill & rhs)89 SedFill::operator=(const SedFill& rhs)
90 {
91 if (&rhs != this)
92 {
93 SedBase::operator=(rhs);
94 mColor = rhs.mColor;
95 //mSecondColor = rhs.mSecondColor;
96 }
97
98 return *this;
99 }
100
101
102 /*
103 * Creates and returns a deep copy of this SedFill object.
104 */
105 SedFill*
clone() const106 SedFill::clone() const
107 {
108 return new SedFill(*this);
109 }
110
111
112 /*
113 * Destructor for SedFill.
114 */
~SedFill()115 SedFill::~SedFill()
116 {
117 }
118
119
120 /*
121 * Returns the value of the "color" attribute of this SedFill.
122 */
123 const std::string&
getColor() const124 SedFill::getColor() const
125 {
126 return mColor;
127 }
128
129
130 /*
131 * Returns the value of the "secondColor" attribute of this SedFill.
132 */
133 //const std::string&
134 //SedFill::getSecondColor() const
135 //{
136 // return mSecondColor;
137 //}
138
139
140 /*
141 * Predicate returning @c true if this SedFill's "color" attribute is set.
142 */
143 bool
isSetColor() const144 SedFill::isSetColor() const
145 {
146 return (mColor.empty() == false);
147 }
148
149
150 /*
151 * Predicate returning @c true if this SedFill's "secondColor" attribute is
152 * set.
153 */
154 //bool
155 //SedFill::isSetSecondColor() const
156 //{
157 // return (mSecondColor.empty() == false);
158 //}
159
160
161 /*
162 * Sets the value of the "color" attribute of this SedFill.
163 */
164 int
setColor(const std::string & color)165 SedFill::setColor(const std::string& color)
166 {
167 mColor = color;
168 return LIBSEDML_OPERATION_SUCCESS;
169 }
170
171
172 /*
173 * Sets the value of the "secondColor" attribute of this SedFill.
174 */
175 //int
176 //SedFill::setSecondColor(const std::string& secondColor)
177 //{
178 // mSecondColor = secondColor;
179 // return LIBSEDML_OPERATION_SUCCESS;
180 //}
181
182
183 /*
184 * Unsets the value of the "color" attribute of this SedFill.
185 */
186 int
unsetColor()187 SedFill::unsetColor()
188 {
189 mColor.erase();
190
191 if (mColor.empty() == true)
192 {
193 return LIBSEDML_OPERATION_SUCCESS;
194 }
195 else
196 {
197 return LIBSEDML_OPERATION_FAILED;
198 }
199 }
200
201
202 /*
203 * Unsets the value of the "secondColor" attribute of this SedFill.
204 */
205 //int
206 //SedFill::unsetSecondColor()
207 //{
208 // mSecondColor.erase();
209 //
210 // if (mSecondColor.empty() == true)
211 // {
212 // return LIBSEDML_OPERATION_SUCCESS;
213 // }
214 // else
215 // {
216 // return LIBSEDML_OPERATION_FAILED;
217 // }
218 //}
219
220
221 /*
222 * Returns the XML element name of this SedFill object.
223 */
224 const std::string&
getElementName() const225 SedFill::getElementName() const
226 {
227 static const string name = "fill";
228 return name;
229 }
230
231
232 /*
233 * Returns the libSEDML type code for this SedFill object.
234 */
235 int
getTypeCode() const236 SedFill::getTypeCode() const
237 {
238 return SEDML_FILL;
239 }
240
241
242 /*
243 * Predicate returning @c true if all the required attributes for this SedFill
244 * object have been set.
245 */
246 bool
hasRequiredAttributes() const247 SedFill::hasRequiredAttributes() const
248 {
249 bool allPresent = true;
250
251 if (isSetColor() == false)
252 {
253 allPresent = false;
254 }
255
256 return allPresent;
257 }
258
259
260
261 /** @cond doxygenLibSEDMLInternal */
262
263 /*
264 * Write any contained elements
265 */
266 void
writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const267 SedFill::writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream& stream)
268 const
269 {
270 SedBase::writeElements(stream);
271 }
272
273 /** @endcond */
274
275
276
277 /** @cond doxygenLibSEDMLInternal */
278
279 /*
280 * Accepts the given SedVisitor
281 */
282 bool
accept(SedVisitor & v) const283 SedFill::accept(SedVisitor& v) const
284 {
285 return false;
286 }
287
288 /** @endcond */
289
290
291
292 /** @cond doxygenLibSEDMLInternal */
293
294 /*
295 * Sets the parent SedDocument
296 */
297 void
setSedDocument(SedDocument * d)298 SedFill::setSedDocument(SedDocument* d)
299 {
300 SedBase::setSedDocument(d);
301 }
302
303 /** @endcond */
304
305
306
307 /** @cond doxygenLibSEDMLInternal */
308
309 /*
310 * Gets the value of the "attributeName" attribute of this SedFill.
311 */
312 int
getAttribute(const std::string & attributeName,bool & value) const313 SedFill::getAttribute(const std::string& attributeName, bool& value) const
314 {
315 int return_value = SedBase::getAttribute(attributeName, value);
316
317 return return_value;
318 }
319
320 /** @endcond */
321
322
323
324 /** @cond doxygenLibSEDMLInternal */
325
326 /*
327 * Gets the value of the "attributeName" attribute of this SedFill.
328 */
329 int
getAttribute(const std::string & attributeName,int & value) const330 SedFill::getAttribute(const std::string& attributeName, int& value) const
331 {
332 int return_value = SedBase::getAttribute(attributeName, value);
333
334 return return_value;
335 }
336
337 /** @endcond */
338
339
340
341 /** @cond doxygenLibSEDMLInternal */
342
343 /*
344 * Gets the value of the "attributeName" attribute of this SedFill.
345 */
346 int
getAttribute(const std::string & attributeName,double & value) const347 SedFill::getAttribute(const std::string& attributeName, double& value) const
348 {
349 int return_value = SedBase::getAttribute(attributeName, value);
350
351 return return_value;
352 }
353
354 /** @endcond */
355
356
357
358 /** @cond doxygenLibSEDMLInternal */
359
360 /*
361 * Gets the value of the "attributeName" attribute of this SedFill.
362 */
363 int
getAttribute(const std::string & attributeName,unsigned int & value) const364 SedFill::getAttribute(const std::string& attributeName,
365 unsigned int& value) const
366 {
367 int return_value = SedBase::getAttribute(attributeName, value);
368
369 return return_value;
370 }
371
372 /** @endcond */
373
374
375
376 /** @cond doxygenLibSEDMLInternal */
377
378 /*
379 * Gets the value of the "attributeName" attribute of this SedFill.
380 */
381 int
getAttribute(const std::string & attributeName,std::string & value) const382 SedFill::getAttribute(const std::string& attributeName,
383 std::string& value) const
384 {
385 int return_value = SedBase::getAttribute(attributeName, value);
386
387 if (return_value == LIBSEDML_OPERATION_SUCCESS)
388 {
389 return return_value;
390 }
391
392 if (attributeName == "color")
393 {
394 value = getColor();
395 return_value = LIBSEDML_OPERATION_SUCCESS;
396 }
397 //else if (attributeName == "secondColor")
398 //{
399 // value = getSecondColor();
400 // return_value = LIBSEDML_OPERATION_SUCCESS;
401 //}
402
403 return return_value;
404 }
405
406 /** @endcond */
407
408
409
410 /** @cond doxygenLibSEDMLInternal */
411
412 /*
413 * Predicate returning @c true if this SedFill's attribute "attributeName" is
414 * set.
415 */
416 bool
isSetAttribute(const std::string & attributeName) const417 SedFill::isSetAttribute(const std::string& attributeName) const
418 {
419 bool value = SedBase::isSetAttribute(attributeName);
420
421 if (attributeName == "color")
422 {
423 value = isSetColor();
424 }
425 //else if (attributeName == "secondColor")
426 //{
427 // value = isSetSecondColor();
428 //}
429
430 return value;
431 }
432
433 /** @endcond */
434
435
436
437 /** @cond doxygenLibSEDMLInternal */
438
439 /*
440 * Sets the value of the "attributeName" attribute of this SedFill.
441 */
442 int
setAttribute(const std::string & attributeName,bool value)443 SedFill::setAttribute(const std::string& attributeName, bool value)
444 {
445 int return_value = SedBase::setAttribute(attributeName, value);
446
447 return return_value;
448 }
449
450 /** @endcond */
451
452
453
454 /** @cond doxygenLibSEDMLInternal */
455
456 /*
457 * Sets the value of the "attributeName" attribute of this SedFill.
458 */
459 int
setAttribute(const std::string & attributeName,int value)460 SedFill::setAttribute(const std::string& attributeName, int value)
461 {
462 int return_value = SedBase::setAttribute(attributeName, value);
463
464 return return_value;
465 }
466
467 /** @endcond */
468
469
470
471 /** @cond doxygenLibSEDMLInternal */
472
473 /*
474 * Sets the value of the "attributeName" attribute of this SedFill.
475 */
476 int
setAttribute(const std::string & attributeName,double value)477 SedFill::setAttribute(const std::string& attributeName, double value)
478 {
479 int return_value = SedBase::setAttribute(attributeName, value);
480
481 return return_value;
482 }
483
484 /** @endcond */
485
486
487
488 /** @cond doxygenLibSEDMLInternal */
489
490 /*
491 * Sets the value of the "attributeName" attribute of this SedFill.
492 */
493 int
setAttribute(const std::string & attributeName,unsigned int value)494 SedFill::setAttribute(const std::string& attributeName, unsigned int value)
495 {
496 int return_value = SedBase::setAttribute(attributeName, value);
497
498 return return_value;
499 }
500
501 /** @endcond */
502
503
504
505 /** @cond doxygenLibSEDMLInternal */
506
507 /*
508 * Sets the value of the "attributeName" attribute of this SedFill.
509 */
510 int
setAttribute(const std::string & attributeName,const std::string & value)511 SedFill::setAttribute(const std::string& attributeName,
512 const std::string& value)
513 {
514 int return_value = SedBase::setAttribute(attributeName, value);
515
516 if (attributeName == "color")
517 {
518 return_value = setColor(value);
519 }
520 //else if (attributeName == "secondColor")
521 //{
522 // return_value = setSecondColor(value);
523 //}
524
525 return return_value;
526 }
527
528 /** @endcond */
529
530
531
532 /** @cond doxygenLibSEDMLInternal */
533
534 /*
535 * Unsets the value of the "attributeName" attribute of this SedFill.
536 */
537 int
unsetAttribute(const std::string & attributeName)538 SedFill::unsetAttribute(const std::string& attributeName)
539 {
540 int value = SedBase::unsetAttribute(attributeName);
541
542 if (attributeName == "color")
543 {
544 value = unsetColor();
545 }
546 //else if (attributeName == "secondColor")
547 //{
548 // value = unsetSecondColor();
549 //}
550
551 return value;
552 }
553
554 /** @endcond */
555
556
557
558 /** @cond doxygenLibSEDMLInternal */
559
560 /*
561 * Adds the expected attributes for this element
562 */
563 void
addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & attributes)564 SedFill::addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
565 ExpectedAttributes& attributes)
566 {
567 SedBase::addExpectedAttributes(attributes);
568
569 attributes.add("color");
570
571 //attributes.add("secondColor");
572 }
573
574 /** @endcond */
575
576
577
578 /** @cond doxygenLibSEDMLInternal */
579
580 /*
581 * Reads the expected attributes into the member data variables
582 */
583 void
readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes,const LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & expectedAttributes)584 SedFill::readAttributes(
585 const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes&
586 attributes,
587 const LIBSBML_CPP_NAMESPACE_QUALIFIER
588 ExpectedAttributes& expectedAttributes)
589 {
590 unsigned int level = getLevel();
591 unsigned int version = getVersion();
592 unsigned int numErrs;
593 bool assigned = false;
594 SedErrorLog* log = getErrorLog();
595
596 SedBase::readAttributes(attributes, expectedAttributes);
597
598 if (log)
599 {
600 numErrs = log->getNumErrors();
601
602 for (int n = numErrs-1; n >= 0; n--)
603 {
604 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
605 {
606 const std::string details = log->getError(n)->getMessage();
607 log->remove(SedUnknownCoreAttribute);
608 log->logError(SedmlFillAllowedAttributes, level, version, details,
609 getLine(), getColumn());
610 }
611 }
612 }
613
614 //
615 // color string (use = "required" )
616 //
617
618 assigned = attributes.readInto("color", mColor);
619
620 if (assigned == true)
621 {
622 if (mColor.empty() == true)
623 {
624 logEmptyString(mColor, level, version, "<SedFill>");
625 }
626 }
627 else
628 {
629 if (log)
630 {
631 std::string message = "Sedml attribute 'color' is missing from the "
632 "<SedFill> element.";
633 log->logError(SedmlFillAllowedAttributes, level, version, message,
634 getLine(), getColumn());
635 }
636 }
637
638 //
639 // secondColor string (use = "optional" )
640 //
641
642 //assigned = attributes.readInto("secondColor", mSecondColor);
643
644 //if (assigned == true)
645 //{
646 // if (mSecondColor.empty() == true)
647 // {
648 // logEmptyString(mSecondColor, level, version, "<SedFill>");
649 // }
650 //}
651 }
652
653 /** @endcond */
654
655
656
657 /** @cond doxygenLibSEDMLInternal */
658
659 /*
660 * Writes the attributes to the stream
661 */
662 void
writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const663 SedFill::writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
664 stream) const
665 {
666 SedBase::writeAttributes(stream);
667
668 if (isSetColor() == true)
669 {
670 stream.writeAttribute("color", getPrefix(), mColor);
671 }
672
673 //if (isSetSecondColor() == true)
674 //{
675 // stream.writeAttribute("secondColor", getPrefix(), mSecondColor);
676 //}
677 }
678
679 /** @endcond */
680
681
682
683
684 #endif /* __cplusplus */
685
686
687 /*
688 * Creates a new SedFill_t using the given SED-ML Level and @ p version values.
689 */
690 LIBSEDML_EXTERN
691 SedFill_t *
SedFill_create(unsigned int level,unsigned int version)692 SedFill_create(unsigned int level, unsigned int version)
693 {
694 return new SedFill(level, version);
695 }
696
697
698 /*
699 * Creates and returns a deep copy of this SedFill_t object.
700 */
701 LIBSEDML_EXTERN
702 SedFill_t*
SedFill_clone(const SedFill_t * sf)703 SedFill_clone(const SedFill_t* sf)
704 {
705 if (sf != NULL)
706 {
707 return static_cast<SedFill_t*>(sf->clone());
708 }
709 else
710 {
711 return NULL;
712 }
713 }
714
715
716 /*
717 * Frees this SedFill_t object.
718 */
719 LIBSEDML_EXTERN
720 void
SedFill_free(SedFill_t * sf)721 SedFill_free(SedFill_t* sf)
722 {
723 if (sf != NULL)
724 {
725 delete sf;
726 }
727 }
728
729
730 /*
731 * Returns the value of the "color" attribute of this SedFill_t.
732 */
733 LIBSEDML_EXTERN
734 char *
SedFill_getColor(const SedFill_t * sf)735 SedFill_getColor(const SedFill_t * sf)
736 {
737 if (sf == NULL)
738 {
739 return NULL;
740 }
741
742 return sf->getColor().empty() ? NULL : safe_strdup(sf->getColor().c_str());
743 }
744
745
746 /*
747 * Returns the value of the "secondColor" attribute of this SedFill_t.
748 */
749 //LIBSEDML_EXTERN
750 //char *
751 //SedFill_getSecondColor(const SedFill_t * sf)
752 //{
753 // if (sf == NULL)
754 // {
755 // return NULL;
756 // }
757 //
758 // return sf->getSecondColor().empty() ? NULL :
759 // safe_strdup(sf->getSecondColor().c_str());
760 //}
761
762
763 /*
764 * Predicate returning @c 1 (true) if this SedFill_t's "color" attribute is
765 * set.
766 */
767 LIBSEDML_EXTERN
768 int
SedFill_isSetColor(const SedFill_t * sf)769 SedFill_isSetColor(const SedFill_t * sf)
770 {
771 return (sf != NULL) ? static_cast<int>(sf->isSetColor()) : 0;
772 }
773
774
775 /*
776 * Predicate returning @c 1 (true) if this SedFill_t's "secondColor" attribute
777 * is set.
778 */
779 //LIBSEDML_EXTERN
780 //int
781 //SedFill_isSetSecondColor(const SedFill_t * sf)
782 //{
783 // return (sf != NULL) ? static_cast<int>(sf->isSetSecondColor()) : 0;
784 //}
785
786
787 /*
788 * Sets the value of the "color" attribute of this SedFill_t.
789 */
790 LIBSEDML_EXTERN
791 int
SedFill_setColor(SedFill_t * sf,const char * color)792 SedFill_setColor(SedFill_t * sf, const char * color)
793 {
794 return (sf != NULL) ? sf->setColor(color) : LIBSEDML_INVALID_OBJECT;
795 }
796
797
798 /*
799 * Sets the value of the "secondColor" attribute of this SedFill_t.
800 */
801 //LIBSEDML_EXTERN
802 //int
803 //SedFill_setSecondColor(SedFill_t * sf, const char * secondColor)
804 //{
805 // return (sf != NULL) ? sf->setSecondColor(secondColor) :
806 // LIBSEDML_INVALID_OBJECT;
807 //}
808
809
810 /*
811 * Unsets the value of the "color" attribute of this SedFill_t.
812 */
813 LIBSEDML_EXTERN
814 int
SedFill_unsetColor(SedFill_t * sf)815 SedFill_unsetColor(SedFill_t * sf)
816 {
817 return (sf != NULL) ? sf->unsetColor() : LIBSEDML_INVALID_OBJECT;
818 }
819
820
821 /*
822 * Unsets the value of the "secondColor" attribute of this SedFill_t.
823 */
824 //LIBSEDML_EXTERN
825 //int
826 //SedFill_unsetSecondColor(SedFill_t * sf)
827 //{
828 // return (sf != NULL) ? sf->unsetSecondColor() : LIBSEDML_INVALID_OBJECT;
829 //}
830
831
832 /*
833 * Predicate returning @c 1 (true) if all the required attributes for this
834 * SedFill_t object have been set.
835 */
836 LIBSEDML_EXTERN
837 int
SedFill_hasRequiredAttributes(const SedFill_t * sf)838 SedFill_hasRequiredAttributes(const SedFill_t * sf)
839 {
840 return (sf != NULL) ? static_cast<int>(sf->hasRequiredAttributes()) : 0;
841 }
842
843
844
845
846 LIBSEDML_CPP_NAMESPACE_END
847
848
849