1 /**
2 * @file SedStyle.cpp
3 * @brief Implementation of the SedStyle 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/SedStyle.h>
35 #include <sedml/SedListOfStyles.h>
36 #include <sbml/xml/XMLInputStream.h>
37
38
39 using namespace std;
40
41
42
43 LIBSEDML_CPP_NAMESPACE_BEGIN
44
45
46
47
48 #ifdef __cplusplus
49
50
51 /*
52 * Creates a new SedStyle using the given SED-ML Level and @ p version values.
53 */
SedStyle(unsigned int level,unsigned int version)54 SedStyle::SedStyle(unsigned int level, unsigned int version)
55 : SedBase(level, version)
56 , mBaseStyle ("")
57 , mLineStyle (NULL)
58 , mMarkerStyle (NULL)
59 , mFillStyle (NULL)
60 {
61 setSedNamespacesAndOwn(new SedNamespaces(level, version));
62 connectToChild();
63 }
64
65
66 /*
67 * Creates a new SedStyle using the given SedNamespaces object @p sedmlns.
68 */
SedStyle(SedNamespaces * sedmlns)69 SedStyle::SedStyle(SedNamespaces *sedmlns)
70 : SedBase(sedmlns)
71 , mBaseStyle ("")
72 , mLineStyle (NULL)
73 , mMarkerStyle (NULL)
74 , mFillStyle (NULL)
75 {
76 setElementNamespace(sedmlns->getURI());
77 connectToChild();
78 }
79
80
81 /*
82 * Copy constructor for SedStyle.
83 */
SedStyle(const SedStyle & orig)84 SedStyle::SedStyle(const SedStyle& orig)
85 : SedBase( orig )
86 , mBaseStyle ( orig.mBaseStyle )
87 , mLineStyle ( NULL )
88 , mMarkerStyle ( NULL )
89 , mFillStyle ( NULL )
90 {
91 if (orig.mLineStyle != NULL)
92 {
93 mLineStyle = orig.mLineStyle->clone();
94 }
95
96 if (orig.mMarkerStyle != NULL)
97 {
98 mMarkerStyle = orig.mMarkerStyle->clone();
99 }
100
101 if (orig.mFillStyle != NULL)
102 {
103 mFillStyle = orig.mFillStyle->clone();
104 }
105
106 connectToChild();
107 }
108
109
110 /*
111 * Assignment operator for SedStyle.
112 */
113 SedStyle&
operator =(const SedStyle & rhs)114 SedStyle::operator=(const SedStyle& rhs)
115 {
116 if (&rhs != this)
117 {
118 SedBase::operator=(rhs);
119 mBaseStyle = rhs.mBaseStyle;
120 delete mLineStyle;
121 if (rhs.mLineStyle != NULL)
122 {
123 mLineStyle = rhs.mLineStyle->clone();
124 }
125 else
126 {
127 mLineStyle = NULL;
128 }
129
130 delete mMarkerStyle;
131 if (rhs.mMarkerStyle != NULL)
132 {
133 mMarkerStyle = rhs.mMarkerStyle->clone();
134 }
135 else
136 {
137 mMarkerStyle = NULL;
138 }
139
140 delete mFillStyle;
141 if (rhs.mFillStyle != NULL)
142 {
143 mFillStyle = rhs.mFillStyle->clone();
144 }
145 else
146 {
147 mFillStyle = NULL;
148 }
149
150 connectToChild();
151 }
152
153 return *this;
154 }
155
156
157 /*
158 * Creates and returns a deep copy of this SedStyle object.
159 */
160 SedStyle*
clone() const161 SedStyle::clone() const
162 {
163 return new SedStyle(*this);
164 }
165
166
167 /*
168 * Destructor for SedStyle.
169 */
~SedStyle()170 SedStyle::~SedStyle()
171 {
172 delete mLineStyle;
173 mLineStyle = NULL;
174 delete mMarkerStyle;
175 mMarkerStyle = NULL;
176 delete mFillStyle;
177 mFillStyle = NULL;
178 }
179
180
181 /*
182 * Returns the value of the "baseStyle" attribute of this SedStyle.
183 */
184 const std::string&
getBaseStyle() const185 SedStyle::getBaseStyle() const
186 {
187 return mBaseStyle;
188 }
189
190
191 /*
192 * Predicate returning @c true if this SedStyle's "baseStyle" attribute is set.
193 */
194 bool
isSetBaseStyle() const195 SedStyle::isSetBaseStyle() const
196 {
197 return (mBaseStyle.empty() == false);
198 }
199
200
201 /*
202 * Sets the value of the "baseStyle" attribute of this SedStyle.
203 */
204 int
setBaseStyle(const std::string & baseStyle)205 SedStyle::setBaseStyle(const std::string& baseStyle)
206 {
207 if (!(SyntaxChecker::isValidInternalSId(baseStyle)))
208 {
209 return LIBSEDML_INVALID_ATTRIBUTE_VALUE;
210 }
211 else
212 {
213 mBaseStyle = baseStyle;
214 return LIBSEDML_OPERATION_SUCCESS;
215 }
216 }
217
218
219 /*
220 * Unsets the value of the "baseStyle" attribute of this SedStyle.
221 */
222 int
unsetBaseStyle()223 SedStyle::unsetBaseStyle()
224 {
225 mBaseStyle.erase();
226
227 if (mBaseStyle.empty() == true)
228 {
229 return LIBSEDML_OPERATION_SUCCESS;
230 }
231 else
232 {
233 return LIBSEDML_OPERATION_FAILED;
234 }
235 }
236
237
238 /*
239 * Returns the value of the "line" element of this SedStyle.
240 */
241 const SedLine*
getLineStyle() const242 SedStyle::getLineStyle() const
243 {
244 return mLineStyle;
245 }
246
247
248 /*
249 * Returns the value of the "line" element of this SedStyle.
250 */
251 SedLine*
getLineStyle()252 SedStyle::getLineStyle()
253 {
254 return mLineStyle;
255 }
256
257
258 /*
259 * Returns the value of the "marker" element of this SedStyle.
260 */
261 const SedMarker*
getMarkerStyle() const262 SedStyle::getMarkerStyle() const
263 {
264 return mMarkerStyle;
265 }
266
267
268 /*
269 * Returns the value of the "marker" element of this SedStyle.
270 */
271 SedMarker*
getMarkerStyle()272 SedStyle::getMarkerStyle()
273 {
274 return mMarkerStyle;
275 }
276
277
278 /*
279 * Returns the value of the "fill" element of this SedStyle.
280 */
281 const SedFill*
getFillStyle() const282 SedStyle::getFillStyle() const
283 {
284 return mFillStyle;
285 }
286
287
288 /*
289 * Returns the value of the "fill" element of this SedStyle.
290 */
291 SedFill*
getFillStyle()292 SedStyle::getFillStyle()
293 {
294 return mFillStyle;
295 }
296
297
298 /*
299 * Predicate returning @c true if this SedStyle's "line" element is set.
300 */
301 bool
isSetLineStyle() const302 SedStyle::isSetLineStyle() const
303 {
304 return (mLineStyle != NULL);
305 }
306
307
308 /*
309 * Predicate returning @c true if this SedStyle's "marker" element is set.
310 */
311 bool
isSetMarkerStyle() const312 SedStyle::isSetMarkerStyle() const
313 {
314 return (mMarkerStyle != NULL);
315 }
316
317
318 /*
319 * Predicate returning @c true if this SedStyle's "fill" element is set.
320 */
321 bool
isSetFillStyle() const322 SedStyle::isSetFillStyle() const
323 {
324 return (mFillStyle != NULL);
325 }
326
327
328 /*
329 * Sets the value of the "line" element of this SedStyle.
330 */
331 int
setLineStyle(const SedLine * lineStyle)332 SedStyle::setLineStyle(const SedLine* lineStyle)
333 {
334 if (mLineStyle == lineStyle)
335 {
336 return LIBSEDML_OPERATION_SUCCESS;
337 }
338 else if (lineStyle == NULL)
339 {
340 delete mLineStyle;
341 mLineStyle = NULL;
342 return LIBSEDML_OPERATION_SUCCESS;
343 }
344 else
345 {
346 delete mLineStyle;
347 mLineStyle = (lineStyle != NULL) ? lineStyle->clone() : NULL;
348 if (mLineStyle != NULL)
349 {
350 mLineStyle->connectToParent(this);
351 }
352
353 return LIBSEDML_OPERATION_SUCCESS;
354 }
355 }
356
357
358 /*
359 * Sets the value of the "marker" element of this SedStyle.
360 */
361 int
setMarkerStyle(const SedMarker * markerStyle)362 SedStyle::setMarkerStyle(const SedMarker* markerStyle)
363 {
364 if (mMarkerStyle == markerStyle)
365 {
366 return LIBSEDML_OPERATION_SUCCESS;
367 }
368 else if (markerStyle == NULL)
369 {
370 delete mMarkerStyle;
371 mMarkerStyle = NULL;
372 return LIBSEDML_OPERATION_SUCCESS;
373 }
374 else
375 {
376 delete mMarkerStyle;
377 mMarkerStyle = (markerStyle != NULL) ? markerStyle->clone() : NULL;
378 if (mMarkerStyle != NULL)
379 {
380 mMarkerStyle->connectToParent(this);
381 }
382
383 return LIBSEDML_OPERATION_SUCCESS;
384 }
385 }
386
387
388 /*
389 * Sets the value of the "fill" element of this SedStyle.
390 */
391 int
setFillStyle(const SedFill * fillStyle)392 SedStyle::setFillStyle(const SedFill* fillStyle)
393 {
394 if (mFillStyle == fillStyle)
395 {
396 return LIBSEDML_OPERATION_SUCCESS;
397 }
398 else if (fillStyle == NULL)
399 {
400 delete mFillStyle;
401 mFillStyle = NULL;
402 return LIBSEDML_OPERATION_SUCCESS;
403 }
404 else
405 {
406 delete mFillStyle;
407 mFillStyle = (fillStyle != NULL) ? fillStyle->clone() : NULL;
408 if (mFillStyle != NULL)
409 {
410 mFillStyle->connectToParent(this);
411 }
412
413 return LIBSEDML_OPERATION_SUCCESS;
414 }
415 }
416
417
418 /*
419 * Creates a new SedLine object, adds it to this SedStyle object and returns
420 * the SedLine object created.
421 */
422 SedLine*
createLineStyle()423 SedStyle::createLineStyle()
424 {
425 if (mLineStyle != NULL)
426 {
427 delete mLineStyle;
428 }
429
430 mLineStyle = new SedLine(getSedNamespaces());
431
432
433 connectToChild();
434
435 return mLineStyle;
436 }
437
438
439 /*
440 * Creates a new SedMarker object, adds it to this SedStyle object and returns
441 * the SedMarker object created.
442 */
443 SedMarker*
createMarkerStyle()444 SedStyle::createMarkerStyle()
445 {
446 if (mMarkerStyle != NULL)
447 {
448 delete mMarkerStyle;
449 }
450
451 mMarkerStyle = new SedMarker(getSedNamespaces());
452
453
454 connectToChild();
455
456 return mMarkerStyle;
457 }
458
459
460 /*
461 * Creates a new SedFill object, adds it to this SedStyle object and returns
462 * the SedFill object created.
463 */
464 SedFill*
createFillStyle()465 SedStyle::createFillStyle()
466 {
467 if (mFillStyle != NULL)
468 {
469 delete mFillStyle;
470 }
471
472 mFillStyle = new SedFill(getSedNamespaces());
473
474
475 connectToChild();
476
477 return mFillStyle;
478 }
479
480
481 /*
482 * Unsets the value of the "line" element of this SedStyle.
483 */
484 int
unsetLineStyle()485 SedStyle::unsetLineStyle()
486 {
487 delete mLineStyle;
488 mLineStyle = NULL;
489 return LIBSEDML_OPERATION_SUCCESS;
490 }
491
492
493 /*
494 * Unsets the value of the "marker" element of this SedStyle.
495 */
496 int
unsetMarkerStyle()497 SedStyle::unsetMarkerStyle()
498 {
499 delete mMarkerStyle;
500 mMarkerStyle = NULL;
501 return LIBSEDML_OPERATION_SUCCESS;
502 }
503
504
505 /*
506 * Unsets the value of the "fill" element of this SedStyle.
507 */
508 int
unsetFillStyle()509 SedStyle::unsetFillStyle()
510 {
511 delete mFillStyle;
512 mFillStyle = NULL;
513 return LIBSEDML_OPERATION_SUCCESS;
514 }
515
516
517 /*
518 * @copydoc doc_renamesidref_common
519 */
520 void
renameSIdRefs(const std::string & oldid,const std::string & newid)521 SedStyle::renameSIdRefs(const std::string& oldid, const std::string& newid)
522 {
523 if (isSetBaseStyle() && mBaseStyle == oldid)
524 {
525 setBaseStyle(newid);
526 }
527 }
528
529
530 /*
531 * Returns the XML element name of this SedStyle object.
532 */
533 const std::string&
getElementName() const534 SedStyle::getElementName() const
535 {
536 static const string name = "style";
537 return name;
538 }
539
540
541 /*
542 * Returns the libSEDML type code for this SedStyle object.
543 */
544 int
getTypeCode() const545 SedStyle::getTypeCode() const
546 {
547 return SEDML_STYLE;
548 }
549
550
551 /*
552 * Predicate returning @c true if all the required attributes for this SedStyle
553 * object have been set.
554 */
555 bool
hasRequiredAttributes() const556 SedStyle::hasRequiredAttributes() const
557 {
558 bool allPresent = true;
559
560 if (isSetId() == false)
561 {
562 allPresent = false;
563 }
564
565 return allPresent;
566 }
567
568
569
570 /** @cond doxygenLibSEDMLInternal */
571
572 /*
573 * Write any contained elements
574 */
575 void
writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const576 SedStyle::writeElements(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
577 stream) const
578 {
579 SedBase::writeElements(stream);
580
581 if (isSetLineStyle() == true)
582 {
583 mLineStyle->write(stream);
584 }
585
586 if (isSetMarkerStyle() == true)
587 {
588 mMarkerStyle->write(stream);
589 }
590
591 if (isSetFillStyle() == true)
592 {
593 mFillStyle->write(stream);
594 }
595 }
596
597 /** @endcond */
598
599
600
601 /** @cond doxygenLibSEDMLInternal */
602
603 /*
604 * Accepts the given SedVisitor
605 */
606 bool
accept(SedVisitor & v) const607 SedStyle::accept(SedVisitor& v) const
608 {
609 return false;
610 }
611
612 /** @endcond */
613
614
615
616 /** @cond doxygenLibSEDMLInternal */
617
618 /*
619 * Sets the parent SedDocument
620 */
621 void
setSedDocument(SedDocument * d)622 SedStyle::setSedDocument(SedDocument* d)
623 {
624 SedBase::setSedDocument(d);
625
626 if (mLineStyle != NULL)
627 {
628 mLineStyle->setSedDocument(d);
629 }
630
631 if (mMarkerStyle != NULL)
632 {
633 mMarkerStyle->setSedDocument(d);
634 }
635
636 if (mFillStyle != NULL)
637 {
638 mFillStyle->setSedDocument(d);
639 }
640 }
641
642 /** @endcond */
643
644
645
646 /** @cond doxygenLibSEDMLInternal */
647
648 /*
649 * Connects to child elements
650 */
651 void
connectToChild()652 SedStyle::connectToChild()
653 {
654 SedBase::connectToChild();
655
656 if (mLineStyle != NULL)
657 {
658 mLineStyle->connectToParent(this);
659 }
660
661 if (mMarkerStyle != NULL)
662 {
663 mMarkerStyle->connectToParent(this);
664 }
665
666 if (mFillStyle != NULL)
667 {
668 mFillStyle->connectToParent(this);
669 }
670 }
671
672 /** @endcond */
673
674
675
676 /** @cond doxygenLibSEDMLInternal */
677
678 /*
679 * Gets the value of the "attributeName" attribute of this SedStyle.
680 */
681 int
getAttribute(const std::string & attributeName,bool & value) const682 SedStyle::getAttribute(const std::string& attributeName, bool& value) const
683 {
684 int return_value = SedBase::getAttribute(attributeName, value);
685
686 return return_value;
687 }
688
689 /** @endcond */
690
691
692
693 /** @cond doxygenLibSEDMLInternal */
694
695 /*
696 * Gets the value of the "attributeName" attribute of this SedStyle.
697 */
698 int
getAttribute(const std::string & attributeName,int & value) const699 SedStyle::getAttribute(const std::string& attributeName, int& value) const
700 {
701 int return_value = SedBase::getAttribute(attributeName, value);
702
703 return return_value;
704 }
705
706 /** @endcond */
707
708
709
710 /** @cond doxygenLibSEDMLInternal */
711
712 /*
713 * Gets the value of the "attributeName" attribute of this SedStyle.
714 */
715 int
getAttribute(const std::string & attributeName,double & value) const716 SedStyle::getAttribute(const std::string& attributeName, double& value) const
717 {
718 int return_value = SedBase::getAttribute(attributeName, value);
719
720 return return_value;
721 }
722
723 /** @endcond */
724
725
726
727 /** @cond doxygenLibSEDMLInternal */
728
729 /*
730 * Gets the value of the "attributeName" attribute of this SedStyle.
731 */
732 int
getAttribute(const std::string & attributeName,unsigned int & value) const733 SedStyle::getAttribute(const std::string& attributeName,
734 unsigned int& value) const
735 {
736 int return_value = SedBase::getAttribute(attributeName, value);
737
738 return return_value;
739 }
740
741 /** @endcond */
742
743
744
745 /** @cond doxygenLibSEDMLInternal */
746
747 /*
748 * Gets the value of the "attributeName" attribute of this SedStyle.
749 */
750 int
getAttribute(const std::string & attributeName,std::string & value) const751 SedStyle::getAttribute(const std::string& attributeName,
752 std::string& value) const
753 {
754 int return_value = SedBase::getAttribute(attributeName, value);
755
756 if (return_value == LIBSEDML_OPERATION_SUCCESS)
757 {
758 return return_value;
759 }
760
761 if (attributeName == "id")
762 {
763 value = getId();
764 return_value = LIBSEDML_OPERATION_SUCCESS;
765 }
766 else if (attributeName == "baseStyle")
767 {
768 value = getBaseStyle();
769 return_value = LIBSEDML_OPERATION_SUCCESS;
770 }
771
772 return return_value;
773 }
774
775 /** @endcond */
776
777
778
779 /** @cond doxygenLibSEDMLInternal */
780
781 /*
782 * Predicate returning @c true if this SedStyle's attribute "attributeName" is
783 * set.
784 */
785 bool
isSetAttribute(const std::string & attributeName) const786 SedStyle::isSetAttribute(const std::string& attributeName) const
787 {
788 bool value = SedBase::isSetAttribute(attributeName);
789
790 if (attributeName == "id")
791 {
792 value = isSetId();
793 }
794 else if (attributeName == "baseStyle")
795 {
796 value = isSetBaseStyle();
797 }
798
799 return value;
800 }
801
802 /** @endcond */
803
804
805
806 /** @cond doxygenLibSEDMLInternal */
807
808 /*
809 * Sets the value of the "attributeName" attribute of this SedStyle.
810 */
811 int
setAttribute(const std::string & attributeName,bool value)812 SedStyle::setAttribute(const std::string& attributeName, bool value)
813 {
814 int return_value = SedBase::setAttribute(attributeName, value);
815
816 return return_value;
817 }
818
819 /** @endcond */
820
821
822
823 /** @cond doxygenLibSEDMLInternal */
824
825 /*
826 * Sets the value of the "attributeName" attribute of this SedStyle.
827 */
828 int
setAttribute(const std::string & attributeName,int value)829 SedStyle::setAttribute(const std::string& attributeName, int value)
830 {
831 int return_value = SedBase::setAttribute(attributeName, value);
832
833 return return_value;
834 }
835
836 /** @endcond */
837
838
839
840 /** @cond doxygenLibSEDMLInternal */
841
842 /*
843 * Sets the value of the "attributeName" attribute of this SedStyle.
844 */
845 int
setAttribute(const std::string & attributeName,double value)846 SedStyle::setAttribute(const std::string& attributeName, double value)
847 {
848 int return_value = SedBase::setAttribute(attributeName, value);
849
850 return return_value;
851 }
852
853 /** @endcond */
854
855
856
857 /** @cond doxygenLibSEDMLInternal */
858
859 /*
860 * Sets the value of the "attributeName" attribute of this SedStyle.
861 */
862 int
setAttribute(const std::string & attributeName,unsigned int value)863 SedStyle::setAttribute(const std::string& attributeName, unsigned int value)
864 {
865 int return_value = SedBase::setAttribute(attributeName, value);
866
867 return return_value;
868 }
869
870 /** @endcond */
871
872
873
874 /** @cond doxygenLibSEDMLInternal */
875
876 /*
877 * Sets the value of the "attributeName" attribute of this SedStyle.
878 */
879 int
setAttribute(const std::string & attributeName,const std::string & value)880 SedStyle::setAttribute(const std::string& attributeName,
881 const std::string& value)
882 {
883 int return_value = SedBase::setAttribute(attributeName, value);
884
885 if (attributeName == "id")
886 {
887 return_value = setId(value);
888 }
889 else if (attributeName == "baseStyle")
890 {
891 return_value = setBaseStyle(value);
892 }
893
894 return return_value;
895 }
896
897 /** @endcond */
898
899
900
901 /** @cond doxygenLibSEDMLInternal */
902
903 /*
904 * Unsets the value of the "attributeName" attribute of this SedStyle.
905 */
906 int
unsetAttribute(const std::string & attributeName)907 SedStyle::unsetAttribute(const std::string& attributeName)
908 {
909 int value = SedBase::unsetAttribute(attributeName);
910
911 if (attributeName == "id")
912 {
913 value = unsetId();
914 }
915 else if (attributeName == "baseStyle")
916 {
917 value = unsetBaseStyle();
918 }
919
920 return value;
921 }
922
923 /** @endcond */
924
925
926
927 /** @cond doxygenLibSEDMLInternal */
928
929 /*
930 * Creates and returns an new "elementName" object in this SedStyle.
931 */
932 SedBase*
createChildObject(const std::string & elementName)933 SedStyle::createChildObject(const std::string& elementName)
934 {
935 SedBase* obj = NULL;
936
937 if (elementName == "line")
938 {
939 return createLineStyle();
940 }
941 else if (elementName == "marker")
942 {
943 return createMarkerStyle();
944 }
945 else if (elementName == "fill")
946 {
947 return createFillStyle();
948 }
949
950 return obj;
951 }
952
953 /** @endcond */
954
955
956
957 /** @cond doxygenLibSEDMLInternal */
958
959 /*
960 * Adds a new "elementName" object to this SedStyle.
961 */
962 int
addChildObject(const std::string & elementName,const SedBase * element)963 SedStyle::addChildObject(const std::string& elementName,
964 const SedBase* element)
965 {
966 if (elementName == "line" && element->getTypeCode() == SEDML_LINE)
967 {
968 return setLineStyle((const SedLine*)(element));
969 }
970 else if (elementName == "marker" && element->getTypeCode() == SEDML_MARKER)
971 {
972 return setMarkerStyle((const SedMarker*)(element));
973 }
974 else if (elementName == "fill" && element->getTypeCode() == SEDML_FILL)
975 {
976 return setFillStyle((const SedFill*)(element));
977 }
978
979 return LIBSBML_OPERATION_FAILED;
980 }
981
982 /** @endcond */
983
984
985
986 /** @cond doxygenLibSEDMLInternal */
987
988 /*
989 * Removes and returns the new "elementName" object with the given id in this
990 * SedStyle.
991 */
992 SedBase*
removeChildObject(const std::string & elementName,const std::string & id)993 SedStyle::removeChildObject(const std::string& elementName,
994 const std::string& id)
995 {
996 if (elementName == "line")
997 {
998 SedLine * obj = mLineStyle;
999 mLineStyle = NULL; return obj;
1000 }
1001 else if (elementName == "marker")
1002 {
1003 SedMarker * obj = mMarkerStyle;
1004 mMarkerStyle = NULL; return obj;
1005 }
1006 else if (elementName == "fill")
1007 {
1008 SedFill * obj = mFillStyle;
1009 mFillStyle = NULL; return obj;
1010 }
1011
1012 return NULL;
1013 }
1014
1015 /** @endcond */
1016
1017
1018
1019 /** @cond doxygenLibSEDMLInternal */
1020
1021 /*
1022 * Returns the number of "elementName" in this SedStyle.
1023 */
1024 unsigned int
getNumObjects(const std::string & elementName)1025 SedStyle::getNumObjects(const std::string& elementName)
1026 {
1027 unsigned int n = 0;
1028
1029 if (elementName == "line")
1030 {
1031 if (isSetLineStyle())
1032 {
1033 return 1;
1034 }
1035 }
1036 else if (elementName == "marker")
1037 {
1038 if (isSetMarkerStyle())
1039 {
1040 return 1;
1041 }
1042 }
1043 else if (elementName == "fill")
1044 {
1045 if (isSetFillStyle())
1046 {
1047 return 1;
1048 }
1049 }
1050
1051 return n;
1052 }
1053
1054 /** @endcond */
1055
1056
1057
1058 /** @cond doxygenLibSEDMLInternal */
1059
1060 /*
1061 * Returns the nth object of "objectName" in this SedStyle.
1062 */
1063 SedBase*
getObject(const std::string & elementName,unsigned int index)1064 SedStyle::getObject(const std::string& elementName, unsigned int index)
1065 {
1066 SedBase* obj = NULL;
1067
1068 if (elementName == "line")
1069 {
1070 return getLineStyle();
1071 }
1072 else if (elementName == "marker")
1073 {
1074 return getMarkerStyle();
1075 }
1076 else if (elementName == "fill")
1077 {
1078 return getFillStyle();
1079 }
1080
1081 return obj;
1082 }
1083
1084 /** @endcond */
1085
1086
1087 /*
1088 * Returns the first child element that has the given @p id in the model-wide
1089 * SId namespace, or @c NULL if no such object is found.
1090 */
1091 SedBase*
getElementBySId(const std::string & id)1092 SedStyle::getElementBySId(const std::string& id)
1093 {
1094 if (id.empty())
1095 {
1096 return NULL;
1097 }
1098
1099 SedBase* obj = NULL;
1100
1101 if (mLineStyle != NULL)
1102 {
1103 if (mLineStyle->getId() == id)
1104 {
1105 return mLineStyle;
1106 }
1107
1108 obj = mLineStyle->getElementBySId(id);
1109 if (obj != NULL)
1110 {
1111 return obj;
1112 }
1113 }
1114
1115 if (mMarkerStyle != NULL)
1116 {
1117 if (mMarkerStyle->getId() == id)
1118 {
1119 return mMarkerStyle;
1120 }
1121
1122 obj = mMarkerStyle->getElementBySId(id);
1123 if (obj != NULL)
1124 {
1125 return obj;
1126 }
1127 }
1128
1129 if (mFillStyle != NULL)
1130 {
1131 if (mFillStyle->getId() == id)
1132 {
1133 return mFillStyle;
1134 }
1135
1136 obj = mFillStyle->getElementBySId(id);
1137 if (obj != NULL)
1138 {
1139 return obj;
1140 }
1141 }
1142
1143 return obj;
1144 }
1145
1146
1147 /*
1148 * Returns a List of all child SedBase objects, including those nested to an
1149 * arbitrary depth.
1150 */
1151 List*
getAllElements(SedElementFilter * filter)1152 SedStyle::getAllElements(SedElementFilter* filter)
1153 {
1154 List* ret = new List();
1155 List* sublist = NULL;
1156 SED_ADD_FILTERED_POINTER(ret, sublist, mLineStyle, filter);
1157 SED_ADD_FILTERED_POINTER(ret, sublist, mMarkerStyle, filter);
1158 SED_ADD_FILTERED_POINTER(ret, sublist, mFillStyle, filter);
1159
1160
1161 return ret;
1162 }
1163
1164
1165
1166 /** @cond doxygenLibSEDMLInternal */
1167
1168 /*
1169 * Creates a new object from the next XMLToken on the XMLInputStream
1170 */
1171 SedBase*
createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream & stream)1172 SedStyle::createObject(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLInputStream& stream)
1173 {
1174 SedBase* obj = NULL;
1175
1176 const std::string& name = stream.peek().getName();
1177
1178 if (name == "line")
1179 {
1180 if (getErrorLog() && isSetLineStyle())
1181 {
1182 getErrorLog()->logError(SedmlStyleAllowedElements, getLevel(),
1183 getVersion(), "", getLine(), getColumn());
1184 }
1185
1186 delete mLineStyle;
1187 mLineStyle = new SedLine(getSedNamespaces());
1188
1189 obj = mLineStyle;
1190 }
1191 else if (name == "marker")
1192 {
1193 if (getErrorLog() && isSetMarkerStyle())
1194 {
1195 getErrorLog()->logError(SedmlStyleAllowedElements, getLevel(),
1196 getVersion(), "", getLine(), getColumn());
1197 }
1198
1199 delete mMarkerStyle;
1200 mMarkerStyle = new SedMarker(getSedNamespaces());
1201
1202 obj = mMarkerStyle;
1203 }
1204 else if (name == "fill")
1205 {
1206 if (getErrorLog() && isSetFillStyle())
1207 {
1208 getErrorLog()->logError(SedmlStyleAllowedElements, getLevel(),
1209 getVersion(), "", getLine(), getColumn());
1210 }
1211
1212 delete mFillStyle;
1213 mFillStyle = new SedFill(getSedNamespaces());
1214
1215 obj = mFillStyle;
1216 }
1217
1218 connectToChild();
1219
1220 return obj;
1221 }
1222
1223 /** @endcond */
1224
1225
1226
1227 /** @cond doxygenLibSEDMLInternal */
1228
1229 /*
1230 * Adds the expected attributes for this element
1231 */
1232 void
addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & attributes)1233 SedStyle::addExpectedAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER
1234 ExpectedAttributes& attributes)
1235 {
1236 SedBase::addExpectedAttributes(attributes);
1237
1238 attributes.add("id");
1239
1240 attributes.add("baseStyle");
1241 }
1242
1243 /** @endcond */
1244
1245
1246
1247 /** @cond doxygenLibSEDMLInternal */
1248
1249 /*
1250 * Reads the expected attributes into the member data variables
1251 */
1252 void
readAttributes(const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes & attributes,const LIBSBML_CPP_NAMESPACE_QUALIFIER ExpectedAttributes & expectedAttributes)1253 SedStyle::readAttributes(
1254 const LIBSBML_CPP_NAMESPACE_QUALIFIER XMLAttributes&
1255 attributes,
1256 const LIBSBML_CPP_NAMESPACE_QUALIFIER
1257 ExpectedAttributes& expectedAttributes)
1258 {
1259 unsigned int level = getLevel();
1260 unsigned int version = getVersion();
1261 unsigned int numErrs;
1262 bool assigned = false;
1263 SedErrorLog* log = getErrorLog();
1264
1265 if (log && getParentSedObject() &&
1266 static_cast<SedListOfStyles*>(getParentSedObject())->size() < 2)
1267 {
1268 numErrs = log->getNumErrors();
1269 for (int n = numErrs-1; n >= 0; n--)
1270 {
1271 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
1272 {
1273 const std::string details = log->getError(n)->getMessage();
1274 log->remove(SedUnknownCoreAttribute);
1275 log->logError(SedmlDocumentLOStylesAllowedCoreAttributes, level,
1276 version, details, getLine(), getColumn());
1277 }
1278 }
1279 }
1280
1281 SedBase::readAttributes(attributes, expectedAttributes);
1282
1283 if (log)
1284 {
1285 numErrs = log->getNumErrors();
1286
1287 for (int n = numErrs-1; n >= 0; n--)
1288 {
1289 if (log->getError(n)->getErrorId() == SedUnknownCoreAttribute)
1290 {
1291 const std::string details = log->getError(n)->getMessage();
1292 log->remove(SedUnknownCoreAttribute);
1293 log->logError(SedmlStyleAllowedAttributes, level, version, details,
1294 getLine(), getColumn());
1295 }
1296 }
1297 }
1298
1299 if(!isSetId())
1300 {
1301 if (log)
1302 {
1303 std::string message = "Sedml attribute 'id' is missing from the "
1304 "<SedStyle> element.";
1305 log->logError(SedmlStyleAllowedAttributes, level, version, message,
1306 getLine(), getColumn());
1307 }
1308 }
1309
1310 //
1311 // baseStyle SIdRef (use = "optional" )
1312 //
1313
1314 assigned = attributes.readInto("baseStyle", mBaseStyle);
1315
1316 if (assigned == true)
1317 {
1318 if (mBaseStyle.empty() == true)
1319 {
1320 logEmptyString(mBaseStyle, level, version, "<SedStyle>");
1321 }
1322 else if (SyntaxChecker::isValidSBMLSId(mBaseStyle) == false)
1323 {
1324 std::string msg = "The baseStyle attribute on the <" + getElementName() +
1325 ">";
1326 if (isSetId())
1327 {
1328 msg += " with id '" + getId() + "'";
1329 }
1330
1331 msg += " is '" + mBaseStyle + "', which does not conform to the syntax.";
1332 logError(SedmlStyleBaseStyleMustBeStyle, level, version, msg, getLine(),
1333 getColumn());
1334 }
1335 }
1336 }
1337
1338 /** @endcond */
1339
1340
1341
1342 /** @cond doxygenLibSEDMLInternal */
1343
1344 /*
1345 * Writes the attributes to the stream
1346 */
1347 void
writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream & stream) const1348 SedStyle::writeAttributes(LIBSBML_CPP_NAMESPACE_QUALIFIER XMLOutputStream&
1349 stream) const
1350 {
1351 SedBase::writeAttributes(stream);
1352
1353 if (isSetBaseStyle() == true)
1354 {
1355 stream.writeAttribute("baseStyle", getPrefix(), mBaseStyle);
1356 }
1357 }
1358
1359 /** @endcond */
1360
1361
1362
1363
1364 #endif /* __cplusplus */
1365
1366
1367 /*
1368 * Creates a new SedStyle_t using the given SED-ML Level and @ p version values.
1369 */
1370 LIBSEDML_EXTERN
1371 SedStyle_t *
SedStyle_create(unsigned int level,unsigned int version)1372 SedStyle_create(unsigned int level, unsigned int version)
1373 {
1374 return new SedStyle(level, version);
1375 }
1376
1377
1378 /*
1379 * Creates and returns a deep copy of this SedStyle_t object.
1380 */
1381 LIBSEDML_EXTERN
1382 SedStyle_t*
SedStyle_clone(const SedStyle_t * ss)1383 SedStyle_clone(const SedStyle_t* ss)
1384 {
1385 if (ss != NULL)
1386 {
1387 return static_cast<SedStyle_t*>(ss->clone());
1388 }
1389 else
1390 {
1391 return NULL;
1392 }
1393 }
1394
1395
1396 /*
1397 * Frees this SedStyle_t object.
1398 */
1399 LIBSEDML_EXTERN
1400 void
SedStyle_free(SedStyle_t * ss)1401 SedStyle_free(SedStyle_t* ss)
1402 {
1403 if (ss != NULL)
1404 {
1405 delete ss;
1406 }
1407 }
1408
1409
1410 /*
1411 * Returns the value of the "id" attribute of this SedStyle_t.
1412 */
1413 LIBSEDML_EXTERN
1414 char *
SedStyle_getId(const SedStyle_t * ss)1415 SedStyle_getId(const SedStyle_t * ss)
1416 {
1417 if (ss == NULL)
1418 {
1419 return NULL;
1420 }
1421
1422 return ss->getId().empty() ? NULL : safe_strdup(ss->getId().c_str());
1423 }
1424
1425
1426 /*
1427 * Returns the value of the "baseStyle" attribute of this SedStyle_t.
1428 */
1429 LIBSEDML_EXTERN
1430 char *
SedStyle_getBaseStyle(const SedStyle_t * ss)1431 SedStyle_getBaseStyle(const SedStyle_t * ss)
1432 {
1433 if (ss == NULL)
1434 {
1435 return NULL;
1436 }
1437
1438 return ss->getBaseStyle().empty() ? NULL :
1439 safe_strdup(ss->getBaseStyle().c_str());
1440 }
1441
1442
1443 /*
1444 * Predicate returning @c 1 (true) if this SedStyle_t's "id" attribute is set.
1445 */
1446 LIBSEDML_EXTERN
1447 int
SedStyle_isSetId(const SedStyle_t * ss)1448 SedStyle_isSetId(const SedStyle_t * ss)
1449 {
1450 return (ss != NULL) ? static_cast<int>(ss->isSetId()) : 0;
1451 }
1452
1453
1454 /*
1455 * Predicate returning @c 1 (true) if this SedStyle_t's "baseStyle" attribute
1456 * is set.
1457 */
1458 LIBSEDML_EXTERN
1459 int
SedStyle_isSetBaseStyle(const SedStyle_t * ss)1460 SedStyle_isSetBaseStyle(const SedStyle_t * ss)
1461 {
1462 return (ss != NULL) ? static_cast<int>(ss->isSetBaseStyle()) : 0;
1463 }
1464
1465
1466 /*
1467 * Sets the value of the "id" attribute of this SedStyle_t.
1468 */
1469 LIBSEDML_EXTERN
1470 int
SedStyle_setId(SedStyle_t * ss,const char * id)1471 SedStyle_setId(SedStyle_t * ss, const char * id)
1472 {
1473 return (ss != NULL) ? ss->setId(id) : LIBSEDML_INVALID_OBJECT;
1474 }
1475
1476
1477 /*
1478 * Sets the value of the "baseStyle" attribute of this SedStyle_t.
1479 */
1480 LIBSEDML_EXTERN
1481 int
SedStyle_setBaseStyle(SedStyle_t * ss,const char * baseStyle)1482 SedStyle_setBaseStyle(SedStyle_t * ss, const char * baseStyle)
1483 {
1484 return (ss != NULL) ? ss->setBaseStyle(baseStyle) : LIBSEDML_INVALID_OBJECT;
1485 }
1486
1487
1488 /*
1489 * Unsets the value of the "id" attribute of this SedStyle_t.
1490 */
1491 LIBSEDML_EXTERN
1492 int
SedStyle_unsetId(SedStyle_t * ss)1493 SedStyle_unsetId(SedStyle_t * ss)
1494 {
1495 return (ss != NULL) ? ss->unsetId() : LIBSEDML_INVALID_OBJECT;
1496 }
1497
1498
1499 /*
1500 * Unsets the value of the "baseStyle" attribute of this SedStyle_t.
1501 */
1502 LIBSEDML_EXTERN
1503 int
SedStyle_unsetBaseStyle(SedStyle_t * ss)1504 SedStyle_unsetBaseStyle(SedStyle_t * ss)
1505 {
1506 return (ss != NULL) ? ss->unsetBaseStyle() : LIBSEDML_INVALID_OBJECT;
1507 }
1508
1509
1510 /*
1511 * Returns the value of the "line" element of this SedStyle_t.
1512 */
1513 LIBSEDML_EXTERN
1514 const SedLine_t*
SedStyle_getLineStyle(const SedStyle_t * ss)1515 SedStyle_getLineStyle(const SedStyle_t * ss)
1516 {
1517 if (ss == NULL)
1518 {
1519 return NULL;
1520 }
1521
1522 return (SedLine_t*)(ss->getLineStyle());
1523 }
1524
1525
1526 /*
1527 * Returns the value of the "marker" element of this SedStyle_t.
1528 */
1529 LIBSEDML_EXTERN
1530 const SedMarker_t*
SedStyle_getMarkerStyle(const SedStyle_t * ss)1531 SedStyle_getMarkerStyle(const SedStyle_t * ss)
1532 {
1533 if (ss == NULL)
1534 {
1535 return NULL;
1536 }
1537
1538 return (SedMarker_t*)(ss->getMarkerStyle());
1539 }
1540
1541
1542 /*
1543 * Returns the value of the "fill" element of this SedStyle_t.
1544 */
1545 LIBSEDML_EXTERN
1546 const SedFill_t*
SedStyle_getFillStyle(const SedStyle_t * ss)1547 SedStyle_getFillStyle(const SedStyle_t * ss)
1548 {
1549 if (ss == NULL)
1550 {
1551 return NULL;
1552 }
1553
1554 return (SedFill_t*)(ss->getFillStyle());
1555 }
1556
1557
1558 /*
1559 * Predicate returning @c 1 (true) if this SedStyle_t's "line" element is set.
1560 */
1561 LIBSEDML_EXTERN
1562 int
SedStyle_isSetLineStyle(const SedStyle_t * ss)1563 SedStyle_isSetLineStyle(const SedStyle_t * ss)
1564 {
1565 return (ss != NULL) ? static_cast<int>(ss->isSetLineStyle()) : 0;
1566 }
1567
1568
1569 /*
1570 * Predicate returning @c 1 (true) if this SedStyle_t's "marker" element is
1571 * set.
1572 */
1573 LIBSEDML_EXTERN
1574 int
SedStyle_isSetMarkerStyle(const SedStyle_t * ss)1575 SedStyle_isSetMarkerStyle(const SedStyle_t * ss)
1576 {
1577 return (ss != NULL) ? static_cast<int>(ss->isSetMarkerStyle()) : 0;
1578 }
1579
1580
1581 /*
1582 * Predicate returning @c 1 (true) if this SedStyle_t's "fill" element is set.
1583 */
1584 LIBSEDML_EXTERN
1585 int
SedStyle_isSetFillStyle(const SedStyle_t * ss)1586 SedStyle_isSetFillStyle(const SedStyle_t * ss)
1587 {
1588 return (ss != NULL) ? static_cast<int>(ss->isSetFillStyle()) : 0;
1589 }
1590
1591
1592 /*
1593 * Sets the value of the "line" element of this SedStyle_t.
1594 */
1595 LIBSEDML_EXTERN
1596 int
SedStyle_setLineStyle(SedStyle_t * ss,const SedLine_t * lineStyle)1597 SedStyle_setLineStyle(SedStyle_t * ss, const SedLine_t* lineStyle)
1598 {
1599 return (ss != NULL) ? ss->setLineStyle(lineStyle) : LIBSEDML_INVALID_OBJECT;
1600 }
1601
1602
1603 /*
1604 * Sets the value of the "marker" element of this SedStyle_t.
1605 */
1606 LIBSEDML_EXTERN
1607 int
SedStyle_setMarkerStyle(SedStyle_t * ss,const SedMarker_t * markerStyle)1608 SedStyle_setMarkerStyle(SedStyle_t * ss, const SedMarker_t* markerStyle)
1609 {
1610 return (ss != NULL) ? ss->setMarkerStyle(markerStyle) :
1611 LIBSEDML_INVALID_OBJECT;
1612 }
1613
1614
1615 /*
1616 * Sets the value of the "fill" element of this SedStyle_t.
1617 */
1618 LIBSEDML_EXTERN
1619 int
SedStyle_setFillStyle(SedStyle_t * ss,const SedFill_t * fillStyle)1620 SedStyle_setFillStyle(SedStyle_t * ss, const SedFill_t* fillStyle)
1621 {
1622 return (ss != NULL) ? ss->setFillStyle(fillStyle) : LIBSEDML_INVALID_OBJECT;
1623 }
1624
1625
1626 /*
1627 * Creates a new SedLine_t object, adds it to this SedStyle_t object and
1628 * returns the SedLine_t object created.
1629 */
1630 LIBSEDML_EXTERN
1631 SedLine_t*
SedStyle_createLineStyle(SedStyle_t * ss)1632 SedStyle_createLineStyle(SedStyle_t* ss)
1633 {
1634 if (ss == NULL)
1635 {
1636 return NULL;
1637 }
1638
1639 return (SedLine_t*)(ss->createLineStyle());
1640 }
1641
1642
1643 /*
1644 * Creates a new SedMarker_t object, adds it to this SedStyle_t object and
1645 * returns the SedMarker_t object created.
1646 */
1647 LIBSEDML_EXTERN
1648 SedMarker_t*
SedStyle_createMarkerStyle(SedStyle_t * ss)1649 SedStyle_createMarkerStyle(SedStyle_t* ss)
1650 {
1651 if (ss == NULL)
1652 {
1653 return NULL;
1654 }
1655
1656 return (SedMarker_t*)(ss->createMarkerStyle());
1657 }
1658
1659
1660 /*
1661 * Creates a new SedFill_t object, adds it to this SedStyle_t object and
1662 * returns the SedFill_t object created.
1663 */
1664 LIBSEDML_EXTERN
1665 SedFill_t*
SedStyle_createFillStyle(SedStyle_t * ss)1666 SedStyle_createFillStyle(SedStyle_t* ss)
1667 {
1668 if (ss == NULL)
1669 {
1670 return NULL;
1671 }
1672
1673 return (SedFill_t*)(ss->createFillStyle());
1674 }
1675
1676
1677 /*
1678 * Unsets the value of the "line" element of this SedStyle_t.
1679 */
1680 LIBSEDML_EXTERN
1681 int
SedStyle_unsetLineStyle(SedStyle_t * ss)1682 SedStyle_unsetLineStyle(SedStyle_t * ss)
1683 {
1684 return (ss != NULL) ? ss->unsetLineStyle() : LIBSEDML_INVALID_OBJECT;
1685 }
1686
1687
1688 /*
1689 * Unsets the value of the "marker" element of this SedStyle_t.
1690 */
1691 LIBSEDML_EXTERN
1692 int
SedStyle_unsetMarkerStyle(SedStyle_t * ss)1693 SedStyle_unsetMarkerStyle(SedStyle_t * ss)
1694 {
1695 return (ss != NULL) ? ss->unsetMarkerStyle() : LIBSEDML_INVALID_OBJECT;
1696 }
1697
1698
1699 /*
1700 * Unsets the value of the "fill" element of this SedStyle_t.
1701 */
1702 LIBSEDML_EXTERN
1703 int
SedStyle_unsetFillStyle(SedStyle_t * ss)1704 SedStyle_unsetFillStyle(SedStyle_t * ss)
1705 {
1706 return (ss != NULL) ? ss->unsetFillStyle() : LIBSEDML_INVALID_OBJECT;
1707 }
1708
1709
1710 /*
1711 * Predicate returning @c 1 (true) if all the required attributes for this
1712 * SedStyle_t object have been set.
1713 */
1714 LIBSEDML_EXTERN
1715 int
SedStyle_hasRequiredAttributes(const SedStyle_t * ss)1716 SedStyle_hasRequiredAttributes(const SedStyle_t * ss)
1717 {
1718 return (ss != NULL) ? static_cast<int>(ss->hasRequiredAttributes()) : 0;
1719 }
1720
1721
1722
1723
1724 LIBSEDML_CPP_NAMESPACE_END
1725
1726
1727