1 /**
2 * @file ParametricObject.cpp
3 * @brief Implementation of the ParametricObject class.
4 * @author SBMLTeam
5 *
6 * <!--------------------------------------------------------------------------
7 * This file is part of libSBML. Please visit http://sbml.org for more
8 * information about SBML, and the latest version of libSBML.
9 *
10 * Copyright (C) 2020 jointly by the following organizations:
11 * 1. California Institute of Technology, Pasadena, CA, USA
12 * 2. University of Heidelberg, Heidelberg, Germany
13 * 3. University College London, London, UK
14 *
15 * Copyright (C) 2019 jointly by the following organizations:
16 * 1. California Institute of Technology, Pasadena, CA, USA
17 * 2. University of Heidelberg, Heidelberg, Germany
18 *
19 * Copyright (C) 2013-2018 jointly by the following organizations:
20 * 1. California Institute of Technology, Pasadena, CA, USA
21 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
22 * 3. University of Heidelberg, Heidelberg, Germany
23 *
24 * Copyright (C) 2009-2013 jointly by the following organizations:
25 * 1. California Institute of Technology, Pasadena, CA, USA
26 * 2. EMBL European Bioinformatics Institute (EMBL-EBI), Hinxton, UK
27 *
28 * Copyright (C) 2006-2008 by the California Institute of Technology,
29 * Pasadena, CA, USA
30 *
31 * Copyright (C) 2002-2005 jointly by the following organizations:
32 * 1. California Institute of Technology, Pasadena, CA, USA
33 * 2. Japan Science and Technology Agency, Japan
34 *
35 * This library is free software; you can redistribute it and/or modify it
36 * under the terms of the GNU Lesser General Public License as published by the
37 * Free Software Foundation. A copy of the license agreement is provided in the
38 * file named "LICENSE.txt" included with this software distribution and also
39 * available online as http://sbml.org/software/libsbml/license.html
40 * ------------------------------------------------------------------------ -->
41 */
42 #include <sbml/packages/spatial/sbml/ParametricObject.h>
43 #include <sbml/packages/spatial/sbml/ListOfParametricObjects.h>
44 #include <sbml/packages/spatial/validator/SpatialSBMLError.h>
45 #include <sbml/packages/spatial/common/CompressionUtil.h>
46 #include <math.h>
47
48
49 using namespace std;
50
51
52
53 LIBSBML_CPP_NAMESPACE_BEGIN
54
55
56
57
58 #ifdef __cplusplus
59
60
61 /*
62 * Creates a new ParametricObject using the given SBML Level, Version and
63 * “spatial” package version.
64 */
ParametricObject(unsigned int level,unsigned int version,unsigned int pkgVersion)65 ParametricObject::ParametricObject(unsigned int level,
66 unsigned int version,
67 unsigned int pkgVersion)
68 : SBase(level, version)
69 , mPolygonType (SPATIAL_POLYGONKIND_INVALID)
70 , mDomainType ("")
71 , mPointIndex ("")
72 , mPointIndexCompressed (NULL)
73 , mPointIndexUncompressed (NULL)
74 , mPointIndexCompressedLength(0)
75 , mPointIndexUncompressedLength(0)
76 , mPointIndexLength (SBML_INT_MAX)
77 , mIsSetPointIndexLength (false)
78 , mCompression (SPATIAL_COMPRESSIONKIND_INVALID)
79 , mDataType (SPATIAL_DATAKIND_INVALID)
80 {
81 setSBMLNamespacesAndOwn(new SpatialPkgNamespaces(level, version,
82 pkgVersion));
83 }
84
85
86 /*
87 * Creates a new ParametricObject using the given SpatialPkgNamespaces object.
88 */
ParametricObject(SpatialPkgNamespaces * spatialns)89 ParametricObject::ParametricObject(SpatialPkgNamespaces *spatialns)
90 : SBase(spatialns)
91 , mPolygonType (SPATIAL_POLYGONKIND_INVALID)
92 , mDomainType ("")
93 , mPointIndex ("")
94 , mPointIndexCompressed (NULL)
95 , mPointIndexUncompressed (NULL)
96 , mPointIndexCompressedLength(0)
97 , mPointIndexUncompressedLength(0)
98 , mPointIndexLength (SBML_INT_MAX)
99 , mIsSetPointIndexLength (false)
100 , mCompression (SPATIAL_COMPRESSIONKIND_INVALID)
101 , mDataType (SPATIAL_DATAKIND_INVALID)
102 {
103 setElementNamespace(spatialns->getURI());
104 loadPlugins(spatialns);
105 }
106
107
108 /*
109 * Copy constructor for ParametricObject.
110 */
ParametricObject(const ParametricObject & orig)111 ParametricObject::ParametricObject(const ParametricObject& orig)
112 : SBase( orig )
113 , mPolygonType ( orig.mPolygonType )
114 , mDomainType ( orig.mDomainType )
115 , mPointIndex (orig.mPointIndex )
116 , mPointIndexCompressed (NULL)
117 , mPointIndexUncompressed (NULL)
118 , mPointIndexCompressedLength (0)
119 , mPointIndexUncompressedLength (0)
120 , mPointIndexLength ( orig.mPointIndexLength )
121 , mIsSetPointIndexLength ( orig.mIsSetPointIndexLength )
122 , mCompression ( orig.mCompression )
123 , mDataType ( orig.mDataType )
124 {
125
126 }
127
128
129 /*
130 * Assignment operator for ParametricObject.
131 */
132 ParametricObject&
operator =(const ParametricObject & rhs)133 ParametricObject::operator=(const ParametricObject& rhs)
134 {
135 if (&rhs != this)
136 {
137 SBase::operator=(rhs);
138 mPolygonType = rhs.mPolygonType;
139 mDomainType = rhs.mDomainType;
140 mPointIndex = rhs.mPointIndex;
141 mPointIndexLength = rhs.mPointIndexLength;
142 mIsSetPointIndexLength = rhs.mIsSetPointIndexLength;
143 mCompression = rhs.mCompression;
144 mDataType = rhs.mDataType;
145 }
146 freeCompressed();
147 freeUncompressed();
148
149 return *this;
150 }
151
152
153 /*
154 * Creates and returns a deep copy of this ParametricObject object.
155 */
156 ParametricObject*
clone() const157 ParametricObject::clone() const
158 {
159 return new ParametricObject(*this);
160 }
161
162
163 /*
164 * Destructor for ParametricObject.
165 */
~ParametricObject()166 ParametricObject::~ParametricObject()
167 {
168 freeUncompressed();
169 freeCompressed();
170 }
171
172
173 /*
174 * Returns the value of the "id" attribute of this ParametricObject.
175 */
176 const std::string&
getId() const177 ParametricObject::getId() const
178 {
179 return mId;
180 }
181
182
183 /*
184 * Returns the value of the "name" attribute of this ParametricObject.
185 */
186 const std::string&
getName() const187 ParametricObject::getName() const
188 {
189 return mName;
190 }
191
192
193 /*
194 * Returns the value of the "polygonType" attribute of this ParametricObject.
195 */
196 PolygonKind_t
getPolygonType() const197 ParametricObject::getPolygonType() const
198 {
199 return mPolygonType;
200 }
201
202
203 /*
204 * Returns the value of the "polygonType" attribute of this ParametricObject.
205 */
206 std::string
getPolygonTypeAsString() const207 ParametricObject::getPolygonTypeAsString() const
208 {
209 return PolygonKind_toString(mPolygonType);
210 }
211
212
213 /*
214 * Returns the value of the "domainType" attribute of this ParametricObject.
215 */
216 const std::string&
getDomainType() const217 ParametricObject::getDomainType() const
218 {
219 return mDomainType;
220 }
221
222
223 /*
224 * Returns the value of the "pointIndex" attribute of this ParametricObject.
225 */
226 void
getPointIndex(int * outArray) const227 ParametricObject::getPointIndex(int* outArray) const
228 {
229 if (outArray == NULL)
230 {
231 return;
232 }
233
234 store();
235 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED) {
236 if (mPointIndexCompressed == NULL)
237 {
238 return;
239 }
240 memcpy(outArray, mPointIndexCompressed, sizeof(int)*mPointIndexCompressedLength);
241 return;
242 }
243 if (mPointIndexUncompressed == NULL)
244 {
245 return;
246 }
247 memcpy(outArray, mPointIndexUncompressed, sizeof(int)*mPointIndexUncompressedLength);
248 }
249
250
getPointIndex(std::vector<int> & outVector) const251 void ParametricObject::getPointIndex(std::vector<int>& outVector) const
252 {
253 readSamplesFromString<int>(mPointIndex, outVector);
254 }
255
getPointIndex()256 string ParametricObject::getPointIndex()
257 {
258 return mPointIndex;
259 }
260
261 /*
262 * Returns the value of the "pointIndexLength" attribute of this
263 * ParametricObject.
264 */
265 int
getPointIndexLength() const266 ParametricObject::getPointIndexLength() const
267 {
268 return mPointIndexLength;
269 }
270
271
272 size_t
getActualPointIndexLength() const273 ParametricObject::getActualPointIndexLength() const
274 {
275 store();
276 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED) {
277 return mPointIndexCompressedLength;
278 }
279 return mPointIndexUncompressedLength;
280 }
281
282
283 /*
284 * Returns the value of the "compression" attribute of this ParametricObject.
285 */
286 CompressionKind_t
getCompression() const287 ParametricObject::getCompression() const
288 {
289 return mCompression;
290 }
291
292
293 /*
294 * Returns the value of the "compression" attribute of this ParametricObject.
295 */
296 const std::string&
getCompressionAsString() const297 ParametricObject::getCompressionAsString() const
298 {
299 static const std::string code_str = CompressionKind_toString(mCompression);
300 return code_str;
301 }
302
303
304 /*
305 * Returns the value of the "dataType" attribute of this ParametricObject.
306 */
307 DataKind_t
getDataType() const308 ParametricObject::getDataType() const
309 {
310 return mDataType;
311 }
312
313
314 /*
315 * Returns the value of the "dataType" attribute of this ParametricObject.
316 */
317 std::string
getDataTypeAsString() const318 ParametricObject::getDataTypeAsString() const
319 {
320 return DataKind_toString(mDataType);
321 }
322
323
324 /*
325 * Predicate returning @c true if this ParametricObject's "id" attribute is
326 * set.
327 */
328 bool
isSetId() const329 ParametricObject::isSetId() const
330 {
331 return (mId.empty() == false);
332 }
333
334
335 /*
336 * Predicate returning @c true if this ParametricObject's "name" attribute is
337 * set.
338 */
339 bool
isSetName() const340 ParametricObject::isSetName() const
341 {
342 return (mName.empty() == false);
343 }
344
345
346 /*
347 * Predicate returning @c true if this ParametricObject's "polygonType"
348 * attribute is set.
349 */
350 bool
isSetPolygonType() const351 ParametricObject::isSetPolygonType() const
352 {
353 return (mPolygonType != SPATIAL_POLYGONKIND_INVALID);
354 }
355
356
357 /*
358 * Predicate returning @c true if this ParametricObject's "domainType"
359 * attribute is set.
360 */
361 bool
isSetDomainType() const362 ParametricObject::isSetDomainType() const
363 {
364 return (mDomainType.empty() == false);
365 }
366
367
368 /*
369 * Predicate returning @c true if this ParametricObject's "pointIndex"
370 * attribute is set.
371 */
372 bool
isSetPointIndex() const373 ParametricObject::isSetPointIndex() const
374 {
375 return (!mPointIndex.empty());
376 }
377
378
379 /*
380 * Predicate returning @c true if this ParametricObject's "pointIndexLength"
381 * attribute is set.
382 */
383 bool
isSetPointIndexLength() const384 ParametricObject::isSetPointIndexLength() const
385 {
386 return mIsSetPointIndexLength;
387 }
388
389
390 /*
391 * Predicate returning @c true if this ParametricObject's "compression"
392 * attribute is set.
393 */
394 bool
isSetCompression() const395 ParametricObject::isSetCompression() const
396 {
397 return (mCompression != SPATIAL_COMPRESSIONKIND_INVALID);
398 }
399
400
401 /*
402 * Predicate returning @c true if this ParametricObject's "dataType" attribute
403 * is set.
404 */
405 bool
isSetDataType() const406 ParametricObject::isSetDataType() const
407 {
408 return (mDataType != SPATIAL_DATAKIND_INVALID);
409 }
410
411
412 /*
413 * Sets the value of the "id" attribute of this ParametricObject.
414 */
415 int
setId(const std::string & id)416 ParametricObject::setId(const std::string& id)
417 {
418 return SyntaxChecker::checkAndSetSId(id, mId);
419 }
420
421
422 /*
423 * Sets the value of the "name" attribute of this ParametricObject.
424 */
425 int
setName(const std::string & name)426 ParametricObject::setName(const std::string& name)
427 {
428 mName = name;
429 return LIBSBML_OPERATION_SUCCESS;
430 }
431
432
433 /*
434 * Sets the value of the "polygonType" attribute of this ParametricObject.
435 */
436 int
setPolygonType(const PolygonKind_t polygonType)437 ParametricObject::setPolygonType(const PolygonKind_t polygonType)
438 {
439 if (PolygonKind_isValid(polygonType) == 0)
440 {
441 mPolygonType = SPATIAL_POLYGONKIND_INVALID;
442 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
443 }
444 else
445 {
446 mPolygonType = polygonType;
447 return LIBSBML_OPERATION_SUCCESS;
448 }
449 }
450
451
452 /*
453 * Sets the value of the "polygonType" attribute of this ParametricObject.
454 */
455 int
setPolygonType(const std::string & polygonType)456 ParametricObject::setPolygonType(const std::string& polygonType)
457 {
458 if (PolygonKind_isValidString(polygonType.c_str()) == 0)
459 {
460 mPolygonType = SPATIAL_POLYGONKIND_INVALID;
461 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
462 }
463 else
464 {
465 mPolygonType = PolygonKind_fromString(polygonType.c_str());
466 return LIBSBML_OPERATION_SUCCESS;
467 }
468 }
469
470
471 /*
472 * Sets the value of the "domainType" attribute of this ParametricObject.
473 */
474 int
setDomainType(const std::string & domainType)475 ParametricObject::setDomainType(const std::string& domainType)
476 {
477 if (!(SyntaxChecker::isValidInternalSId(domainType)))
478 {
479 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
480 }
481 else
482 {
483 mDomainType = domainType;
484 return LIBSBML_OPERATION_SUCCESS;
485 }
486 }
487
setPointIndex(const std::string & pointIndex)488 int ParametricObject::setPointIndex(const std::string & pointIndex)
489 {
490 mPointIndex = pointIndex;
491 freeCompressed();
492 freeUncompressed();
493 store();
494 return LIBSBML_OPERATION_SUCCESS;
495 }
496
497
498 /*
499 * Sets the value of the "pointIndex" attribute of this ParametricObject.
500 */
501 int
setPointIndex(int * inArray,size_t arrayLength)502 ParametricObject::setPointIndex(int* inArray, size_t arrayLength)
503 {
504 if (inArray == NULL)
505 {
506 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
507 }
508 freeCompressed();
509 freeUncompressed();
510 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
511 {
512 copySampleArrays(mPointIndexCompressed, mPointIndexCompressedLength, inArray, arrayLength);
513 }
514 else {
515 copySampleArrays(mPointIndexUncompressed, mPointIndexUncompressedLength, inArray, arrayLength);
516 }
517 mPointIndex = arrayToString(inArray, arrayLength);
518 setPointIndexLength(arrayLength);
519
520 return LIBSBML_OPERATION_SUCCESS;
521 }
522
523
setPointIndex(const std::vector<int> & inArray)524 int ParametricObject::setPointIndex(const std::vector<int>& inArray)
525 {
526 mPointIndex = vectorToString(inArray);
527 freeCompressed();
528 freeUncompressed();
529 store();
530 return setPointIndexLength(inArray.size());
531 }
532
533 /*
534 * Sets the value of the "pointIndexLength" attribute of this ParametricObject.
535 */
536 int
setPointIndexLength(int pointIndexLength)537 ParametricObject::setPointIndexLength(int pointIndexLength)
538 {
539 mPointIndexLength = pointIndexLength;
540 mIsSetPointIndexLength = true;
541 return LIBSBML_OPERATION_SUCCESS;
542 }
543
544
545 /*
546 * Sets the value of the "compression" attribute of this ParametricObject.
547 */
548 int
setCompression(const CompressionKind_t compression)549 ParametricObject::setCompression(const CompressionKind_t compression)
550 {
551 if (CompressionKind_isValid(compression) == 0)
552 {
553 mCompression = SPATIAL_COMPRESSIONKIND_INVALID;
554 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
555 }
556 if (compression == mCompression)
557 {
558 return LIBSBML_OPERATION_SUCCESS;
559 }
560 mCompression = compression;
561 freeCompressed();
562 freeUncompressed();
563 return LIBSBML_OPERATION_SUCCESS;
564 }
565
566
567 /*
568 * Sets the value of the "compression" attribute of this ParametricObject.
569 */
570 int
setCompression(const std::string & compression)571 ParametricObject::setCompression(const std::string& compression)
572 {
573 return setCompression(CompressionKind_fromString(compression.c_str()));
574 }
575
576
577 /*
578 * Sets the value of the "dataType" attribute of this ParametricObject.
579 */
580 int
setDataType(const DataKind_t dataType)581 ParametricObject::setDataType(const DataKind_t dataType)
582 {
583 if (DataKind_isValid(dataType) == 0)
584 {
585 mDataType = SPATIAL_DATAKIND_INVALID;
586 return LIBSBML_INVALID_ATTRIBUTE_VALUE;
587 }
588 else
589 {
590 mDataType = dataType;
591 return LIBSBML_OPERATION_SUCCESS;
592 }
593 }
594
595
596 /*
597 * Sets the value of the "dataType" attribute of this ParametricObject.
598 */
599 int
setDataType(const std::string & dataType)600 ParametricObject::setDataType(const std::string& dataType)
601 {
602 return setDataType(DataKind_fromString(dataType.c_str()));
603 }
604
605
606 /*
607 * Unsets the value of the "id" attribute of this ParametricObject.
608 */
609 int
unsetId()610 ParametricObject::unsetId()
611 {
612 mId.erase();
613
614 if (mId.empty() == true)
615 {
616 return LIBSBML_OPERATION_SUCCESS;
617 }
618 else
619 {
620 return LIBSBML_OPERATION_FAILED;
621 }
622 }
623
624
625 /*
626 * Unsets the value of the "name" attribute of this ParametricObject.
627 */
628 int
unsetName()629 ParametricObject::unsetName()
630 {
631 mName.erase();
632
633 if (mName.empty() == true)
634 {
635 return LIBSBML_OPERATION_SUCCESS;
636 }
637 else
638 {
639 return LIBSBML_OPERATION_FAILED;
640 }
641 }
642
643
644 /*
645 * Unsets the value of the "polygonType" attribute of this ParametricObject.
646 */
647 int
unsetPolygonType()648 ParametricObject::unsetPolygonType()
649 {
650 mPolygonType = SPATIAL_POLYGONKIND_INVALID;
651 return LIBSBML_OPERATION_SUCCESS;
652 }
653
654
655 /*
656 * Unsets the value of the "domainType" attribute of this ParametricObject.
657 */
658 int
unsetDomainType()659 ParametricObject::unsetDomainType()
660 {
661 mDomainType.erase();
662
663 if (mDomainType.empty() == true)
664 {
665 return LIBSBML_OPERATION_SUCCESS;
666 }
667 else
668 {
669 return LIBSBML_OPERATION_FAILED;
670 }
671 }
672
673
674 /*
675 * Unsets the value of the "pointIndex" attribute of this ParametricObject.
676 */
677 int
unsetPointIndex()678 ParametricObject::unsetPointIndex()
679 {
680 freeUncompressed();
681 freeCompressed();
682 mPointIndex = "";
683
684 return unsetPointIndexLength();
685 }
686
687
688 /*
689 * Unsets the value of the "pointIndexLength" attribute of this
690 * ParametricObject.
691 */
692 int
unsetPointIndexLength()693 ParametricObject::unsetPointIndexLength()
694 {
695 mPointIndexLength = SBML_INT_MAX;
696 mIsSetPointIndexLength = false;
697
698 if (isSetPointIndexLength() == false)
699 {
700 return LIBSBML_OPERATION_SUCCESS;
701 }
702 else
703 {
704 return LIBSBML_OPERATION_FAILED;
705 }
706 }
707
708
709 /*
710 * Unsets the value of the "compression" attribute of this ParametricObject.
711 */
712 int
unsetCompression()713 ParametricObject::unsetCompression()
714 {
715 mCompression = SPATIAL_COMPRESSIONKIND_INVALID;
716 return LIBSBML_OPERATION_SUCCESS;
717 }
718
719
720 /*
721 * Unsets the value of the "dataType" attribute of this ParametricObject.
722 */
723 int
unsetDataType()724 ParametricObject::unsetDataType()
725 {
726 mDataType = SPATIAL_DATAKIND_INVALID;
727 return LIBSBML_OPERATION_SUCCESS;
728 }
729
730
731 /*
732 * @copydoc doc_renamesidref_common
733 */
734 void
renameSIdRefs(const std::string & oldid,const std::string & newid)735 ParametricObject::renameSIdRefs(const std::string& oldid,
736 const std::string& newid)
737 {
738 if (isSetDomainType() && mDomainType == oldid)
739 {
740 setDomainType(newid);
741 }
742 }
743
744
745 /*
746 * Returns the XML element name of this ParametricObject object.
747 */
748 const std::string&
getElementName() const749 ParametricObject::getElementName() const
750 {
751 static const string name = "parametricObject";
752 return name;
753 }
754
755
756 /*
757 * Returns the libSBML type code for this ParametricObject object.
758 */
759 int
getTypeCode() const760 ParametricObject::getTypeCode() const
761 {
762 return SBML_SPATIAL_PARAMETRICOBJECT;
763 }
764
765
766 /*
767 * Predicate returning @c true if all the required attributes for this
768 * ParametricObject object have been set.
769 */
770 bool
hasRequiredAttributes() const771 ParametricObject::hasRequiredAttributes() const
772 {
773 bool allPresent = true;
774
775 if (isSetId() == false)
776 {
777 allPresent = false;
778 }
779
780 if (isSetPolygonType() == false)
781 {
782 allPresent = false;
783 }
784
785 if (isSetDomainType() == false)
786 {
787 allPresent = false;
788 }
789
790 if (isSetPointIndex() == false)
791 {
792 allPresent = false;
793 }
794
795 if (isSetPointIndexLength() == false)
796 {
797 allPresent = false;
798 }
799
800 if (isSetCompression() == false)
801 {
802 allPresent = false;
803 }
804
805 return allPresent;
806 }
807
808
809
810 /** @cond doxygenLibsbmlInternal */
811
812 /*
813 * Write any contained elements
814 */
815 void
writeElements(XMLOutputStream & stream) const816 ParametricObject::writeElements(XMLOutputStream& stream) const
817 {
818 SBase::writeElements(stream);
819
820 SBase::writeExtensionElements(stream);
821 }
822
823 /** @endcond */
824
825
826
827 /** @cond doxygenLibsbmlInternal */
828
829 /*
830 * Accepts the given SBMLVisitor
831 */
832 bool
accept(SBMLVisitor & v) const833 ParametricObject::accept(SBMLVisitor& v) const
834 {
835 return v.visit(*this);
836 }
837
838 /** @endcond */
839
840
841
842 /** @cond doxygenLibsbmlInternal */
843
844 /*
845 * Sets the parent SBMLDocument
846 */
847 void
setSBMLDocument(SBMLDocument * d)848 ParametricObject::setSBMLDocument(SBMLDocument* d)
849 {
850 SBase::setSBMLDocument(d);
851 }
852
853 /** @endcond */
854
855
856
857 /** @cond doxygenLibsbmlInternal */
858
859 /*
860 * used to write arrays
861 */
862 void
write(XMLOutputStream & stream) const863 ParametricObject::write(XMLOutputStream& stream) const
864 {
865 stream.startElement(getElementName(), getPrefix());
866 writeAttributes(stream);
867
868 if (isSetPointIndex())
869 {
870 stream << mPointIndex;
871 }
872
873 stream.endElement(getElementName(), getPrefix());
874 }
875
876 /** @endcond */
877
878
879
880 /** @cond doxygenLibsbmlInternal */
881
882 /*
883 * Enables/disables the given package with this element
884 */
885 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)886 ParametricObject::enablePackageInternal(const std::string& pkgURI,
887 const std::string& pkgPrefix,
888 bool flag)
889 {
890 SBase::enablePackageInternal(pkgURI, pkgPrefix, flag);
891 }
892
893 /** @endcond */
894
895
896
897 /** @cond doxygenLibsbmlInternal */
898
899 /*
900 * Gets the value of the "attributeName" attribute of this ParametricObject.
901 */
902 int
getAttribute(const std::string & attributeName,bool & value) const903 ParametricObject::getAttribute(const std::string& attributeName,
904 bool& value) const
905 {
906 int return_value = SBase::getAttribute(attributeName, value);
907
908 return return_value;
909 }
910
911 /** @endcond */
912
913
914
915 /** @cond doxygenLibsbmlInternal */
916
917 /*
918 * Gets the value of the "attributeName" attribute of this ParametricObject.
919 */
920 int
getAttribute(const std::string & attributeName,int & value) const921 ParametricObject::getAttribute(const std::string& attributeName,
922 int& value) const
923 {
924 int return_value = SBase::getAttribute(attributeName, value);
925
926 if (return_value == LIBSBML_OPERATION_SUCCESS)
927 {
928 return return_value;
929 }
930
931 if (attributeName == "pointIndexLength")
932 {
933 value = getPointIndexLength();
934 return_value = LIBSBML_OPERATION_SUCCESS;
935 }
936
937 return return_value;
938 }
939
940 /** @endcond */
941
942
943
944 /** @cond doxygenLibsbmlInternal */
945
946 /*
947 * Gets the value of the "attributeName" attribute of this ParametricObject.
948 */
949 int
getAttribute(const std::string & attributeName,double & value) const950 ParametricObject::getAttribute(const std::string& attributeName,
951 double& value) const
952 {
953 int return_value = SBase::getAttribute(attributeName, value);
954
955 return return_value;
956 }
957
958 /** @endcond */
959
960
961
962 /** @cond doxygenLibsbmlInternal */
963
964 /*
965 * Gets the value of the "attributeName" attribute of this ParametricObject.
966 */
967 int
getAttribute(const std::string & attributeName,unsigned int & value) const968 ParametricObject::getAttribute(const std::string& attributeName,
969 unsigned int& value) const
970 {
971 int return_value = SBase::getAttribute(attributeName, value);
972
973 return return_value;
974 }
975
976 /** @endcond */
977
978
979
980 /** @cond doxygenLibsbmlInternal */
981
982 /*
983 * Gets the value of the "attributeName" attribute of this ParametricObject.
984 */
985 int
getAttribute(const std::string & attributeName,std::string & value) const986 ParametricObject::getAttribute(const std::string& attributeName,
987 std::string& value) const
988 {
989 int return_value = SBase::getAttribute(attributeName, value);
990
991 if (return_value == LIBSBML_OPERATION_SUCCESS)
992 {
993 return return_value;
994 }
995
996 if (attributeName == "id")
997 {
998 value = getId();
999 return_value = LIBSBML_OPERATION_SUCCESS;
1000 }
1001 else if (attributeName == "name")
1002 {
1003 value = getName();
1004 return_value = LIBSBML_OPERATION_SUCCESS;
1005 }
1006 else if (attributeName == "polygonType")
1007 {
1008 value = getPolygonTypeAsString();
1009 return_value = LIBSBML_OPERATION_SUCCESS;
1010 }
1011 else if (attributeName == "domainType")
1012 {
1013 value = getDomainType();
1014 return_value = LIBSBML_OPERATION_SUCCESS;
1015 }
1016 else if (attributeName == "compression")
1017 {
1018 value = getCompressionAsString();
1019 return_value = LIBSBML_OPERATION_SUCCESS;
1020 }
1021 else if (attributeName == "dataType")
1022 {
1023 value = getDataTypeAsString();
1024 return_value = LIBSBML_OPERATION_SUCCESS;
1025 }
1026
1027 return return_value;
1028 }
1029
1030 /** @endcond */
1031
1032
1033
1034 /** @cond doxygenLibsbmlInternal */
1035
1036 /*
1037 * Predicate returning @c true if this ParametricObject's attribute
1038 * "attributeName" is set.
1039 */
1040 bool
isSetAttribute(const std::string & attributeName) const1041 ParametricObject::isSetAttribute(const std::string& attributeName) const
1042 {
1043 bool value = SBase::isSetAttribute(attributeName);
1044
1045 if (attributeName == "id")
1046 {
1047 value = isSetId();
1048 }
1049 else if (attributeName == "name")
1050 {
1051 value = isSetName();
1052 }
1053 else if (attributeName == "polygonType")
1054 {
1055 value = isSetPolygonType();
1056 }
1057 else if (attributeName == "domainType")
1058 {
1059 value = isSetDomainType();
1060 }
1061 else if (attributeName == "pointIndex")
1062 {
1063 value = isSetPointIndex();
1064 }
1065 else if (attributeName == "pointIndexLength")
1066 {
1067 value = isSetPointIndexLength();
1068 }
1069 else if (attributeName == "compression")
1070 {
1071 value = isSetCompression();
1072 }
1073 else if (attributeName == "dataType")
1074 {
1075 value = isSetDataType();
1076 }
1077
1078 return value;
1079 }
1080
1081 /** @endcond */
1082
1083
1084
1085 /** @cond doxygenLibsbmlInternal */
1086
1087 /*
1088 * Sets the value of the "attributeName" attribute of this ParametricObject.
1089 */
1090 int
setAttribute(const std::string & attributeName,bool value)1091 ParametricObject::setAttribute(const std::string& attributeName, bool value)
1092 {
1093 int return_value = SBase::setAttribute(attributeName, value);
1094
1095 return return_value;
1096 }
1097
1098 /** @endcond */
1099
1100
1101
1102 /** @cond doxygenLibsbmlInternal */
1103
1104 /*
1105 * Sets the value of the "attributeName" attribute of this ParametricObject.
1106 */
1107 int
setAttribute(const std::string & attributeName,int value)1108 ParametricObject::setAttribute(const std::string& attributeName, int value)
1109 {
1110 int return_value = SBase::setAttribute(attributeName, value);
1111
1112 if (attributeName == "pointIndexLength")
1113 {
1114 return_value = setPointIndexLength(value);
1115 }
1116
1117 return return_value;
1118 }
1119
1120 /** @endcond */
1121
1122
1123
1124 /** @cond doxygenLibsbmlInternal */
1125
1126 /*
1127 * Sets the value of the "attributeName" attribute of this ParametricObject.
1128 */
1129 int
setAttribute(const std::string & attributeName,double value)1130 ParametricObject::setAttribute(const std::string& attributeName, double value)
1131 {
1132 int return_value = SBase::setAttribute(attributeName, value);
1133
1134 return return_value;
1135 }
1136
1137 /** @endcond */
1138
1139
1140
1141 /** @cond doxygenLibsbmlInternal */
1142
1143 /*
1144 * Sets the value of the "attributeName" attribute of this ParametricObject.
1145 */
1146 int
setAttribute(const std::string & attributeName,unsigned int value)1147 ParametricObject::setAttribute(const std::string& attributeName,
1148 unsigned int value)
1149 {
1150 int return_value = SBase::setAttribute(attributeName, value);
1151
1152 return return_value;
1153 }
1154
1155 /** @endcond */
1156
1157
1158
1159 /** @cond doxygenLibsbmlInternal */
1160
1161 /*
1162 * Sets the value of the "attributeName" attribute of this ParametricObject.
1163 */
1164 int
setAttribute(const std::string & attributeName,const std::string & value)1165 ParametricObject::setAttribute(const std::string& attributeName,
1166 const std::string& value)
1167 {
1168 int return_value = SBase::setAttribute(attributeName, value);
1169
1170 if (attributeName == "id")
1171 {
1172 return_value = setId(value);
1173 }
1174 else if (attributeName == "name")
1175 {
1176 return_value = setName(value);
1177 }
1178 else if (attributeName == "polygonType")
1179 {
1180 return_value = setPolygonType(value);
1181 }
1182 else if (attributeName == "domainType")
1183 {
1184 return_value = setDomainType(value);
1185 }
1186 else if (attributeName == "compression")
1187 {
1188 return_value = setCompression(value);
1189 }
1190 else if (attributeName == "dataType")
1191 {
1192 return_value = setDataType(value);
1193 }
1194
1195 return return_value;
1196 }
1197
1198 /** @endcond */
1199
1200
1201
1202 /** @cond doxygenLibsbmlInternal */
1203
1204 /*
1205 * Unsets the value of the "attributeName" attribute of this ParametricObject.
1206 */
1207 int
unsetAttribute(const std::string & attributeName)1208 ParametricObject::unsetAttribute(const std::string& attributeName)
1209 {
1210 int value = SBase::unsetAttribute(attributeName);
1211
1212 if (attributeName == "id")
1213 {
1214 value = unsetId();
1215 }
1216 else if (attributeName == "name")
1217 {
1218 value = unsetName();
1219 }
1220 else if (attributeName == "polygonType")
1221 {
1222 value = unsetPolygonType();
1223 }
1224 else if (attributeName == "domainType")
1225 {
1226 value = unsetDomainType();
1227 }
1228 else if (attributeName == "pointIndex")
1229 {
1230 value = unsetPointIndex();
1231 }
1232 else if (attributeName == "pointIndexLength")
1233 {
1234 value = unsetPointIndexLength();
1235 }
1236 else if (attributeName == "compression")
1237 {
1238 value = unsetCompression();
1239 }
1240 else if (attributeName == "dataType")
1241 {
1242 value = unsetDataType();
1243 }
1244
1245 return value;
1246 }
1247
1248 /** @endcond */
1249
1250
1251
1252 /** @cond doxygenLibsbmlInternal */
1253
1254 /*
1255 * Adds the expected attributes for this element
1256 */
1257 void
addExpectedAttributes(ExpectedAttributes & attributes)1258 ParametricObject::addExpectedAttributes(ExpectedAttributes& attributes)
1259 {
1260 SBase::addExpectedAttributes(attributes);
1261
1262 attributes.add("id");
1263
1264 attributes.add("name");
1265
1266 attributes.add("polygonType");
1267
1268 attributes.add("domainType");
1269
1270 attributes.add("pointIndexLength");
1271
1272 attributes.add("compression");
1273
1274 attributes.add("dataType");
1275 }
1276
1277 /** @endcond */
1278
1279
1280
1281 /** @cond doxygenLibsbmlInternal */
1282
1283 /*
1284 * Reads the expected attributes into the member data variables
1285 */
1286 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1287 ParametricObject::readAttributes(const XMLAttributes& attributes,
1288 const ExpectedAttributes& expectedAttributes)
1289 {
1290 unsigned int level = getLevel();
1291 unsigned int version = getVersion();
1292 unsigned int pkgVersion = getPackageVersion();
1293 unsigned int numErrs;
1294 bool assigned = false;
1295 SBMLErrorLog* log = getErrorLog();
1296
1297 if (log && getParentSBMLObject() &&
1298 static_cast<ListOfParametricObjects*>(getParentSBMLObject())->size() < 2)
1299 {
1300 numErrs = log->getNumErrors();
1301 for (int n = numErrs-1; n >= 0; n--)
1302 {
1303 if (log->getError(n)->getErrorId() == UnknownPackageAttribute)
1304 {
1305 const std::string details = log->getError(n)->getMessage();
1306 log->remove(UnknownPackageAttribute);
1307 log->logPackageError("spatial",
1308 SpatialParametricObjectAllowedAttributes, pkgVersion, level, version,
1309 details);
1310 }
1311 else if (log->getError(n)->getErrorId() == UnknownCoreAttribute)
1312 {
1313 const std::string details = log->getError(n)->getMessage();
1314 log->remove(UnknownCoreAttribute);
1315 log->logPackageError("spatial",
1316 SpatialParametricGeometryLOParametricObjectsAllowedCoreAttributes,
1317 pkgVersion, level, version, details);
1318 }
1319 }
1320 }
1321
1322 SBase::readAttributes(attributes, expectedAttributes);
1323
1324 if (log)
1325 {
1326 numErrs = log->getNumErrors();
1327
1328 for (int n = numErrs-1; n >= 0; n--)
1329 {
1330 if (log->getError(n)->getErrorId() == UnknownPackageAttribute)
1331 {
1332 const std::string details = log->getError(n)->getMessage();
1333 log->remove(UnknownPackageAttribute);
1334 log->logPackageError("spatial",
1335 SpatialParametricObjectAllowedAttributes, pkgVersion, level, version,
1336 details);
1337 }
1338 else if (log->getError(n)->getErrorId() == UnknownCoreAttribute)
1339 {
1340 const std::string details = log->getError(n)->getMessage();
1341 log->remove(UnknownCoreAttribute);
1342 log->logPackageError("spatial",
1343 SpatialParametricObjectAllowedCoreAttributes, pkgVersion, level,
1344 version, details);
1345 }
1346 }
1347 }
1348
1349 //
1350 // id SId (use = "required" )
1351 //
1352
1353 assigned = attributes.readInto("id", mId);
1354
1355 if (assigned == true)
1356 {
1357 if (mId.empty() == true)
1358 {
1359 logEmptyString(mId, level, version, "<ParametricObject>");
1360 }
1361 else if (SyntaxChecker::isValidSBMLSId(mId) == false)
1362 {
1363 log->logPackageError("spatial", SpatialIdSyntaxRule, pkgVersion, level,
1364 version, "The id on the <" + getElementName() + "> is '" + mId + "', "
1365 "which does not conform to the syntax.", getLine(), getColumn());
1366 }
1367 }
1368 else
1369 {
1370 std::string message = "Spatial attribute 'id' is missing from the "
1371 "<ParametricObject> element.";
1372 log->logPackageError("spatial", SpatialParametricObjectAllowedAttributes,
1373 pkgVersion, level, version, message);
1374 }
1375
1376 //
1377 // name string (use = "optional" )
1378 //
1379
1380 assigned = attributes.readInto("name", mName);
1381
1382 if (assigned == true)
1383 {
1384 if (mName.empty() == true)
1385 {
1386 logEmptyString(mName, level, version, "<ParametricObject>");
1387 }
1388 }
1389
1390 //
1391 // polygonType enum (use = "required" )
1392 //
1393
1394 std::string polygonType;
1395 assigned = attributes.readInto("polygonType", polygonType);
1396
1397 if (assigned == true)
1398 {
1399 if (polygonType.empty() == true)
1400 {
1401 logEmptyString(polygonType, level, version, "<ParametricObject>");
1402 }
1403 else
1404 {
1405 mPolygonType = PolygonKind_fromString(polygonType.c_str());
1406
1407 if (PolygonKind_isValid(mPolygonType) == 0)
1408 {
1409 std::string msg = "The polygonType on the <ParametricObject> ";
1410
1411 if (isSetId())
1412 {
1413 msg += "with id '" + getId() + "'";
1414 }
1415
1416 msg += "is '" + polygonType + "', which is not a valid option.";
1417
1418 log->logPackageError("spatial",
1419 SpatialParametricObjectPolygonTypeMustBePolygonKindEnum, pkgVersion,
1420 level, version, msg);
1421 }
1422 }
1423 }
1424 else
1425 {
1426 std::string message = "Spatial attribute 'polygonType' is missing.";
1427 log->logPackageError("spatial", SpatialParametricObjectAllowedAttributes,
1428 pkgVersion, level, version, message);
1429 }
1430
1431 //
1432 // domainType SIdRef (use = "required" )
1433 //
1434
1435 assigned = attributes.readInto("domainType", mDomainType);
1436
1437 if (assigned == true)
1438 {
1439 if (mDomainType.empty() == true)
1440 {
1441 logEmptyString(mDomainType, level, version, "<ParametricObject>");
1442 }
1443 else if (SyntaxChecker::isValidSBMLSId(mDomainType) == false)
1444 {
1445 std::string msg = "The domainType attribute on the <" + getElementName()
1446 + ">";
1447 if (isSetId())
1448 {
1449 msg += " with id '" + getId() + "'";
1450 }
1451
1452 msg += " is '" + mDomainType + "', which does not conform to the "
1453 "syntax.";
1454 log->logPackageError("spatial",
1455 SpatialParametricObjectDomainTypeMustBeDomainType, pkgVersion, level,
1456 version, msg, getLine(), getColumn());
1457 }
1458 }
1459 else
1460 {
1461 std::string message = "Spatial attribute 'domainType' is missing from the "
1462 "<ParametricObject> element.";
1463 log->logPackageError("spatial", SpatialParametricObjectAllowedAttributes,
1464 pkgVersion, level, version, message);
1465 }
1466
1467 //
1468 // pointIndexLength int (use = "required" )
1469 //
1470
1471 numErrs = log->getNumErrors();
1472 mIsSetPointIndexLength = attributes.readInto("pointIndexLength",
1473 mPointIndexLength);
1474
1475 if ( mIsSetPointIndexLength == false)
1476 {
1477 if (log->getNumErrors() == numErrs + 1 &&
1478 log->contains(XMLAttributeTypeMismatch))
1479 {
1480 log->remove(XMLAttributeTypeMismatch);
1481 std::string message = "Spatial attribute 'pointIndexLength' from the "
1482 "<ParametricObject> element must be an integer.";
1483 log->logPackageError("spatial",
1484 SpatialParametricObjectPointIndexLengthMustBeInteger, pkgVersion, level,
1485 version, message);
1486 }
1487 else
1488 {
1489 std::string message = "Spatial attribute 'pointIndexLength' is missing "
1490 "from the <ParametricObject> element.";
1491 log->logPackageError("spatial", SpatialParametricObjectAllowedAttributes,
1492 pkgVersion, level, version, message);
1493 }
1494 }
1495
1496 //
1497 // compression enum (use = "required" )
1498 //
1499
1500 std::string compression;
1501 assigned = attributes.readInto("compression", compression);
1502
1503 if (assigned == true)
1504 {
1505 if (compression.empty() == true)
1506 {
1507 logEmptyString(compression, level, version, "<ParametricObject>");
1508 }
1509 else
1510 {
1511 mCompression = CompressionKind_fromString(compression.c_str());
1512
1513 if (CompressionKind_isValid(mCompression) == 0)
1514 {
1515 std::string msg = "The compression on the <ParametricObject> ";
1516
1517 if (isSetId())
1518 {
1519 msg += "with id '" + getId() + "'";
1520 }
1521
1522 msg += "is '" + compression + "', which is not a valid option.";
1523
1524 log->logPackageError("spatial",
1525 SpatialParametricObjectCompressionMustBeCompressionKindEnum,
1526 pkgVersion, level, version, msg);
1527 }
1528 }
1529 }
1530 else
1531 {
1532 std::string message = "Spatial attribute 'compression' is missing.";
1533 log->logPackageError("spatial", SpatialParametricObjectAllowedAttributes,
1534 pkgVersion, level, version, message);
1535 }
1536
1537 //
1538 // dataType enum (use = "optional" )
1539 //
1540
1541 std::string dataType;
1542 assigned = attributes.readInto("dataType", dataType);
1543
1544 if (assigned == true)
1545 {
1546 if (dataType.empty() == true)
1547 {
1548 logEmptyString(dataType, level, version, "<ParametricObject>");
1549 }
1550 else
1551 {
1552 mDataType = DataKind_fromString(dataType.c_str());
1553
1554 if (DataKind_isValid(mDataType) == 0 || mDataType == SPATIAL_DATAKIND_INT || mDataType == SPATIAL_DATAKIND_DOUBLE || mDataType == SPATIAL_DATAKIND_FLOAT)
1555 {
1556 std::string msg = "The dataType on the <ParametricObject> ";
1557
1558 if (isSetId())
1559 {
1560 msg += "with id '" + getId() + "'";
1561 }
1562
1563 msg += "is '" + dataType + "', which is not a valid option.";
1564
1565 log->logPackageError("spatial",
1566 SpatialParametricObjectDataTypeMustBeDataKindEnum, pkgVersion, level,
1567 version, msg);
1568 }
1569 }
1570 }
1571 }
1572
1573 /** @endcond */
1574
1575
1576
1577 /** @cond doxygenLibsbmlInternal */
1578
1579 /*
1580 * Writes the attributes to the stream
1581 */
1582 void
writeAttributes(XMLOutputStream & stream) const1583 ParametricObject::writeAttributes(XMLOutputStream& stream) const
1584 {
1585 SBase::writeAttributes(stream);
1586
1587 if (isSetId() == true)
1588 {
1589 stream.writeAttribute("id", getPrefix(), mId);
1590 }
1591
1592 if (isSetName() == true)
1593 {
1594 stream.writeAttribute("name", getPrefix(), mName);
1595 }
1596
1597 if (isSetPolygonType() == true)
1598 {
1599 stream.writeAttribute("polygonType", getPrefix(),
1600 PolygonKind_toString(mPolygonType));
1601 }
1602
1603 if (isSetDomainType() == true)
1604 {
1605 stream.writeAttribute("domainType", getPrefix(), mDomainType);
1606 }
1607
1608 if (isSetPointIndexLength() == true)
1609 {
1610 stream.writeAttribute("pointIndexLength", getPrefix(), mPointIndexLength);
1611 }
1612
1613 if (isSetCompression() == true)
1614 {
1615 stream.writeAttribute("compression", getPrefix(),
1616 CompressionKind_toString(mCompression));
1617 }
1618
1619 if (isSetDataType() == true)
1620 {
1621 stream.writeAttribute("dataType", getPrefix(),
1622 DataKind_toString(mDataType));
1623 }
1624
1625 SBase::writeExtensionAttributes(stream);
1626 }
1627
1628 /** @endcond */
1629
1630
1631
1632 /** @cond doxygenLibsbmlInternal */
1633
1634 /*
1635 * Writes the array data as a text element
1636 */
1637 void
setElementText(const std::string & text)1638 ParametricObject::setElementText(const std::string& text)
1639 {
1640 mPointIndex = text;
1641 SBMLErrorLog* log = getErrorLog();
1642 if (log && mCompression == SPATIAL_COMPRESSIONKIND_UNCOMPRESSED)
1643 {
1644 size_t doubleslen;
1645 double ival;
1646 double* doublesVector = readSamplesFromString<double>(mPointIndex, doubleslen);
1647 for (size_t i = 0; i < doubleslen; i++)
1648 {
1649 if (doublesVector[i] < 0 || modf(doublesVector[i], &ival) != 0)
1650 {
1651 stringstream ss_msg;
1652 ss_msg << "A <parametricObject>";
1653 if (isSetId())
1654 {
1655 ss_msg << " with id '" << getId() << "'";
1656 }
1657 ss_msg << " has an entry with the value '" << doublesVector[i];
1658 ss_msg << "', which is not a non-negative integer.";
1659
1660 log->logPackageError("spatial",
1661 SpatialParametricObjectIndexesMustBePositiveIntegers,
1662 getPackageVersion(), getLevel(), getVersion(), ss_msg.str());
1663 }
1664 }
1665 free(doublesVector);
1666 }
1667 }
1668
store() const1669 void ParametricObject::store() const
1670 {
1671 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
1672 {
1673 if (mPointIndexCompressed == NULL) {
1674 mPointIndexCompressed = readSamplesFromString<int>(mPointIndex, mPointIndexCompressedLength);
1675 }
1676 }
1677 else
1678 {
1679 if (mPointIndexUncompressed == NULL) {
1680 mPointIndexUncompressed = readSamplesFromString<int>(mPointIndex, mPointIndexUncompressedLength);
1681 }
1682 }
1683 }
1684
uncompressInternal(string & sampleString,size_t & length) const1685 void ParametricObject::uncompressInternal(string& sampleString, size_t& length) const
1686 {
1687 freeUncompressed();
1688 store();
1689
1690 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
1691 {
1692 if (mPointIndexCompressed == NULL)
1693 {
1694 sampleString = "";
1695 length = 0;
1696 return;
1697 }
1698 char* csamples = (char*)malloc(sizeof(char) * mPointIndexCompressedLength);
1699 int* result;
1700 for (unsigned int i = 0; i < mPointIndexCompressedLength; ++i)
1701 {
1702 csamples[i] = (char)mPointIndexCompressed[i];
1703 }
1704 uncompress_data(csamples, mPointIndexCompressedLength, result, length);
1705 free(csamples);
1706
1707 if (result == NULL)
1708 {
1709 sampleString = "";
1710 length = 0;
1711 return;
1712 }
1713
1714 sampleString = charIntsToString(result, length);
1715 free(result);
1716 return;
1717 }
1718 else
1719 {
1720 sampleString = mPointIndex;
1721 length = mPointIndexUncompressedLength;
1722 }
1723 }
1724
1725 void
getUncompressedData(int * & data,size_t & length)1726 ParametricObject::getUncompressedData(int*& data, size_t& length)
1727 {
1728 store();
1729 length = getUncompressedLength();
1730 if (length == 0)
1731 {
1732 return;
1733 }
1734 copySampleArrays(data, length, mPointIndexUncompressed, mPointIndexUncompressedLength);
1735 return;
1736 }
1737
1738 int
uncompress()1739 ParametricObject::uncompress()
1740 {
1741 if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
1742 {
1743 uncompressInternal(mPointIndex, mPointIndexUncompressedLength);
1744 mCompression = SPATIAL_COMPRESSIONKIND_UNCOMPRESSED;
1745 store();
1746 setPointIndexLength(mPointIndexUncompressedLength);
1747 }
1748
1749 return setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
1750 }
1751
compress(int level)1752 int ParametricObject::compress(int level)
1753 {
1754 freeCompressed();
1755 unsigned char* result; int length;
1756 int ret = compress_data(const_cast<char*>(mPointIndex.c_str()), mPointIndex.length(), level, result, length);
1757
1758 if (ret == LIBSBML_OPERATION_SUCCESS)
1759 {
1760 mPointIndex = arrayToString(result, length);
1761 copySampleArrays(mPointIndexCompressed, mPointIndexCompressedLength, result, length);
1762
1763 free(result);
1764
1765 mCompression = SPATIAL_COMPRESSIONKIND_DEFLATED;
1766 mPointIndexLength = mPointIndexCompressedLength;
1767 }
1768 return ret;
1769 }
1770
1771 unsigned int
getUncompressedLength() const1772 ParametricObject::getUncompressedLength() const
1773 {
1774 store();
1775 if (mPointIndexUncompressed == NULL) {
1776 string uncompressedString;
1777 uncompressInternal(uncompressedString, mPointIndexUncompressedLength);
1778 mPointIndexUncompressed = readSamplesFromString<int>(uncompressedString, mPointIndexUncompressedLength);
1779 }
1780 return mPointIndexUncompressedLength;
1781 }
1782
1783 void
getUncompressed(int * outputPoints) const1784 ParametricObject::getUncompressed(int* outputPoints) const
1785 {
1786 store();
1787 if (outputPoints == NULL) return;
1788 if (mPointIndexUncompressed == NULL) {
1789 string uncompressedString;
1790 uncompressInternal(uncompressedString, mPointIndexUncompressedLength);
1791 mPointIndexUncompressed = readSamplesFromString<int>(uncompressedString, mPointIndexUncompressedLength);
1792 }
1793 if (mPointIndexUncompressed == NULL) return;
1794 memcpy(outputPoints, mPointIndexUncompressed, sizeof(int) * mPointIndexUncompressedLength);
1795 }
1796
getUncompressed(std::vector<int> & outputPoints) const1797 void ParametricObject::getUncompressed(std::vector<int>& outputPoints) const
1798 {
1799 store();
1800 if (mPointIndexUncompressed == NULL) {
1801 string uncompressedString;
1802 uncompressInternal(uncompressedString, mPointIndexUncompressedLength);
1803 mPointIndexUncompressed = readSamplesFromString<int>(uncompressedString, mPointIndexUncompressedLength);
1804 }
1805 if (mPointIndexUncompressed == NULL) return;
1806 outputPoints.assign(mPointIndexUncompressed, mPointIndexUncompressed + mPointIndexUncompressedLength);
1807 }
1808
1809 void
freeUncompressed() const1810 ParametricObject::freeUncompressed() const
1811 {
1812 if (mPointIndexUncompressed != NULL)
1813 {
1814 free(mPointIndexUncompressed);
1815 }
1816 mPointIndexUncompressed = NULL;
1817 mPointIndexUncompressedLength = 0;
1818 }
1819
1820 void
freeCompressed() const1821 ParametricObject::freeCompressed() const
1822 {
1823 if (mPointIndexCompressed != NULL)
1824 {
1825 free(mPointIndexCompressed);
1826 }
1827 mPointIndexCompressed = NULL;
1828 mPointIndexCompressedLength = 0;
1829 }
1830
1831 /** @endcond */
1832
1833
1834
1835
1836 #endif /* __cplusplus */
1837
1838
1839 /*
1840 * Creates a new ParametricObject_t using the given SBML Level, Version and
1841 * “spatial” package version.
1842 */
1843 LIBSBML_EXTERN
1844 ParametricObject_t *
ParametricObject_create(unsigned int level,unsigned int version,unsigned int pkgVersion)1845 ParametricObject_create(unsigned int level,
1846 unsigned int version,
1847 unsigned int pkgVersion)
1848 {
1849 return new ParametricObject(level, version, pkgVersion);
1850 }
1851
1852
1853 /*
1854 * Creates and returns a deep copy of this ParametricObject_t object.
1855 */
1856 LIBSBML_EXTERN
1857 ParametricObject_t*
ParametricObject_clone(const ParametricObject_t * po)1858 ParametricObject_clone(const ParametricObject_t* po)
1859 {
1860 if (po != NULL)
1861 {
1862 return static_cast<ParametricObject_t*>(po->clone());
1863 }
1864 else
1865 {
1866 return NULL;
1867 }
1868 }
1869
1870
1871 /*
1872 * Frees this ParametricObject_t object.
1873 */
1874 LIBSBML_EXTERN
1875 void
ParametricObject_free(ParametricObject_t * po)1876 ParametricObject_free(ParametricObject_t* po)
1877 {
1878 if (po != NULL)
1879 {
1880 delete po;
1881 }
1882 }
1883
1884
1885 /*
1886 * Returns the value of the "id" attribute of this ParametricObject_t.
1887 */
1888 LIBSBML_EXTERN
1889 char *
ParametricObject_getId(const ParametricObject_t * po)1890 ParametricObject_getId(const ParametricObject_t * po)
1891 {
1892 if (po == NULL)
1893 {
1894 return NULL;
1895 }
1896
1897 return po->getId().empty() ? NULL : safe_strdup(po->getId().c_str());
1898 }
1899
1900
1901 /*
1902 * Returns the value of the "name" attribute of this ParametricObject_t.
1903 */
1904 LIBSBML_EXTERN
1905 char *
ParametricObject_getName(const ParametricObject_t * po)1906 ParametricObject_getName(const ParametricObject_t * po)
1907 {
1908 if (po == NULL)
1909 {
1910 return NULL;
1911 }
1912
1913 return po->getName().empty() ? NULL : safe_strdup(po->getName().c_str());
1914 }
1915
1916
1917 /*
1918 * Returns the value of the "polygonType" attribute of this ParametricObject_t.
1919 */
1920 LIBSBML_EXTERN
1921 PolygonKind_t
ParametricObject_getPolygonType(const ParametricObject_t * po)1922 ParametricObject_getPolygonType(const ParametricObject_t * po)
1923 {
1924 if (po == NULL)
1925 {
1926 return SPATIAL_POLYGONKIND_INVALID;
1927 }
1928
1929 return po->getPolygonType();
1930 }
1931
1932
1933 /*
1934 * Returns the value of the "polygonType" attribute of this ParametricObject_t.
1935 */
1936 LIBSBML_EXTERN
1937 char *
ParametricObject_getPolygonTypeAsString(const ParametricObject_t * po)1938 ParametricObject_getPolygonTypeAsString(const ParametricObject_t * po)
1939 {
1940 return (char*)(PolygonKind_toString(po->getPolygonType()));
1941 }
1942
1943
1944 /*
1945 * Returns the value of the "domainType" attribute of this ParametricObject_t.
1946 */
1947 LIBSBML_EXTERN
1948 char *
ParametricObject_getDomainType(const ParametricObject_t * po)1949 ParametricObject_getDomainType(const ParametricObject_t * po)
1950 {
1951 if (po == NULL)
1952 {
1953 return NULL;
1954 }
1955
1956 return po->getDomainType().empty() ? NULL :
1957 safe_strdup(po->getDomainType().c_str());
1958 }
1959
1960
1961 /*
1962 * Returns the value of the "pointIndexLength" attribute of this
1963 * ParametricObject_t.
1964 */
1965 LIBSBML_EXTERN
1966 int
ParametricObject_getPointIndexLength(const ParametricObject_t * po)1967 ParametricObject_getPointIndexLength(const ParametricObject_t * po)
1968 {
1969 return (po != NULL) ? po->getPointIndexLength() : SBML_INT_MAX;
1970 }
1971
1972
1973 /*
1974 * Returns the value of the "compression" attribute of this ParametricObject_t.
1975 */
1976 LIBSBML_EXTERN
1977 CompressionKind_t
ParametricObject_getCompression(const ParametricObject_t * po)1978 ParametricObject_getCompression(const ParametricObject_t * po)
1979 {
1980 if (po == NULL)
1981 {
1982 return SPATIAL_COMPRESSIONKIND_INVALID;
1983 }
1984
1985 return po->getCompression();
1986 }
1987
1988
1989 /*
1990 * Returns the value of the "compression" attribute of this ParametricObject_t.
1991 */
1992 LIBSBML_EXTERN
1993 char *
ParametricObject_getCompressionAsString(const ParametricObject_t * po)1994 ParametricObject_getCompressionAsString(const ParametricObject_t * po)
1995 {
1996 return (char*)(CompressionKind_toString(po->getCompression()));
1997 }
1998
1999
2000 /*
2001 * Returns the value of the "dataType" attribute of this ParametricObject_t.
2002 */
2003 LIBSBML_EXTERN
2004 DataKind_t
ParametricObject_getDataType(const ParametricObject_t * po)2005 ParametricObject_getDataType(const ParametricObject_t * po)
2006 {
2007 if (po == NULL)
2008 {
2009 return SPATIAL_DATAKIND_INVALID;
2010 }
2011
2012 return po->getDataType();
2013 }
2014
2015
2016 /*
2017 * Returns the value of the "dataType" attribute of this ParametricObject_t.
2018 */
2019 LIBSBML_EXTERN
2020 char *
ParametricObject_getDataTypeAsString(const ParametricObject_t * po)2021 ParametricObject_getDataTypeAsString(const ParametricObject_t * po)
2022 {
2023 return (char*)(DataKind_toString(po->getDataType()));
2024 }
2025
2026
2027 /*
2028 * Predicate returning @c 1 (true) if this ParametricObject_t's "id" attribute
2029 * is set.
2030 */
2031 LIBSBML_EXTERN
2032 int
ParametricObject_isSetId(const ParametricObject_t * po)2033 ParametricObject_isSetId(const ParametricObject_t * po)
2034 {
2035 return (po != NULL) ? static_cast<int>(po->isSetId()) : 0;
2036 }
2037
2038
2039 /*
2040 * Predicate returning @c 1 (true) if this ParametricObject_t's "name"
2041 * attribute is set.
2042 */
2043 LIBSBML_EXTERN
2044 int
ParametricObject_isSetName(const ParametricObject_t * po)2045 ParametricObject_isSetName(const ParametricObject_t * po)
2046 {
2047 return (po != NULL) ? static_cast<int>(po->isSetName()) : 0;
2048 }
2049
2050
2051 /*
2052 * Predicate returning @c 1 (true) if this ParametricObject_t's "polygonType"
2053 * attribute is set.
2054 */
2055 LIBSBML_EXTERN
2056 int
ParametricObject_isSetPolygonType(const ParametricObject_t * po)2057 ParametricObject_isSetPolygonType(const ParametricObject_t * po)
2058 {
2059 return (po != NULL) ? static_cast<int>(po->isSetPolygonType()) : 0;
2060 }
2061
2062
2063 /*
2064 * Predicate returning @c 1 (true) if this ParametricObject_t's "domainType"
2065 * attribute is set.
2066 */
2067 LIBSBML_EXTERN
2068 int
ParametricObject_isSetDomainType(const ParametricObject_t * po)2069 ParametricObject_isSetDomainType(const ParametricObject_t * po)
2070 {
2071 return (po != NULL) ? static_cast<int>(po->isSetDomainType()) : 0;
2072 }
2073
2074
2075 /*
2076 * Predicate returning @c 1 (true) if this ParametricObject_t's "pointIndex"
2077 * attribute is set.
2078 */
2079 LIBSBML_EXTERN
2080 int
ParametricObject_isSetPointIndex(const ParametricObject_t * po)2081 ParametricObject_isSetPointIndex(const ParametricObject_t * po)
2082 {
2083 return (po != NULL) ? static_cast<int>(po->isSetPointIndex()) : 0;
2084 }
2085
2086
2087 /*
2088 * Predicate returning @c 1 (true) if this ParametricObject_t's
2089 * "pointIndexLength" attribute is set.
2090 */
2091 LIBSBML_EXTERN
2092 int
ParametricObject_isSetPointIndexLength(const ParametricObject_t * po)2093 ParametricObject_isSetPointIndexLength(const ParametricObject_t * po)
2094 {
2095 return (po != NULL) ? static_cast<int>(po->isSetPointIndexLength()) : 0;
2096 }
2097
2098
2099 /*
2100 * Predicate returning @c 1 (true) if this ParametricObject_t's "compression"
2101 * attribute is set.
2102 */
2103 LIBSBML_EXTERN
2104 int
ParametricObject_isSetCompression(const ParametricObject_t * po)2105 ParametricObject_isSetCompression(const ParametricObject_t * po)
2106 {
2107 return (po != NULL) ? static_cast<int>(po->isSetCompression()) : 0;
2108 }
2109
2110
2111 /*
2112 * Predicate returning @c 1 (true) if this ParametricObject_t's "dataType"
2113 * attribute is set.
2114 */
2115 LIBSBML_EXTERN
2116 int
ParametricObject_isSetDataType(const ParametricObject_t * po)2117 ParametricObject_isSetDataType(const ParametricObject_t * po)
2118 {
2119 return (po != NULL) ? static_cast<int>(po->isSetDataType()) : 0;
2120 }
2121
2122
2123 /*
2124 * Sets the value of the "id" attribute of this ParametricObject_t.
2125 */
2126 LIBSBML_EXTERN
2127 int
ParametricObject_setId(ParametricObject_t * po,const char * id)2128 ParametricObject_setId(ParametricObject_t * po, const char * id)
2129 {
2130 return (po != NULL) ? po->setId(id) : LIBSBML_INVALID_OBJECT;
2131 }
2132
2133
2134 /*
2135 * Sets the value of the "name" attribute of this ParametricObject_t.
2136 */
2137 LIBSBML_EXTERN
2138 int
ParametricObject_setName(ParametricObject_t * po,const char * name)2139 ParametricObject_setName(ParametricObject_t * po, const char * name)
2140 {
2141 return (po != NULL) ? po->setName(name) : LIBSBML_INVALID_OBJECT;
2142 }
2143
2144
2145 /*
2146 * Sets the value of the "polygonType" attribute of this ParametricObject_t.
2147 */
2148 LIBSBML_EXTERN
2149 int
ParametricObject_setPolygonType(ParametricObject_t * po,PolygonKind_t polygonType)2150 ParametricObject_setPolygonType(ParametricObject_t * po,
2151 PolygonKind_t polygonType)
2152 {
2153 return (po != NULL) ? po->setPolygonType(polygonType) :
2154 LIBSBML_INVALID_OBJECT;
2155 }
2156
2157
2158 /*
2159 * Sets the value of the "polygonType" attribute of this ParametricObject_t.
2160 */
2161 LIBSBML_EXTERN
2162 int
ParametricObject_setPolygonTypeAsString(ParametricObject_t * po,const char * polygonType)2163 ParametricObject_setPolygonTypeAsString(ParametricObject_t * po,
2164 const char * polygonType)
2165 {
2166 return (po != NULL) ? po->setPolygonType(polygonType):
2167 LIBSBML_INVALID_OBJECT;
2168 }
2169
2170
2171 /*
2172 * Sets the value of the "domainType" attribute of this ParametricObject_t.
2173 */
2174 LIBSBML_EXTERN
2175 int
ParametricObject_setDomainType(ParametricObject_t * po,const char * domainType)2176 ParametricObject_setDomainType(ParametricObject_t * po,
2177 const char * domainType)
2178 {
2179 return (po != NULL) ? po->setDomainType(domainType) : LIBSBML_INVALID_OBJECT;
2180 }
2181
2182
2183 /*
2184 * Sets the value of the "pointIndex" attribute of this ParametricObject_t.
2185 */
2186 LIBSBML_EXTERN
2187 int
ParametricObject_setPointIndex(ParametricObject_t * po,int * pointIndex,int arrayLength)2188 ParametricObject_setPointIndex(ParametricObject_t* po,
2189 int* pointIndex,
2190 int arrayLength)
2191 {
2192 return (po != NULL) ? po->setPointIndex(pointIndex, arrayLength) :
2193 LIBSBML_INVALID_OBJECT;
2194 }
2195
2196
2197 /*
2198 * Sets the value of the "pointIndexLength" attribute of this
2199 * ParametricObject_t.
2200 */
2201 LIBSBML_EXTERN
2202 int
ParametricObject_setPointIndexLength(ParametricObject_t * po,int pointIndexLength)2203 ParametricObject_setPointIndexLength(ParametricObject_t * po,
2204 int pointIndexLength)
2205 {
2206 return (po != NULL) ? po->setPointIndexLength(pointIndexLength) :
2207 LIBSBML_INVALID_OBJECT;
2208 }
2209
2210
2211 /*
2212 * Sets the value of the "compression" attribute of this ParametricObject_t.
2213 */
2214 LIBSBML_EXTERN
2215 int
ParametricObject_setCompression(ParametricObject_t * po,CompressionKind_t compression)2216 ParametricObject_setCompression(ParametricObject_t * po,
2217 CompressionKind_t compression)
2218 {
2219 return (po != NULL) ? po->setCompression(compression) :
2220 LIBSBML_INVALID_OBJECT;
2221 }
2222
2223
2224 /*
2225 * Sets the value of the "compression" attribute of this ParametricObject_t.
2226 */
2227 LIBSBML_EXTERN
2228 int
ParametricObject_setCompressionAsString(ParametricObject_t * po,const char * compression)2229 ParametricObject_setCompressionAsString(ParametricObject_t * po,
2230 const char * compression)
2231 {
2232 return (po != NULL) ? po->setCompression(compression):
2233 LIBSBML_INVALID_OBJECT;
2234 }
2235
2236
2237 /*
2238 * Sets the value of the "dataType" attribute of this ParametricObject_t.
2239 */
2240 LIBSBML_EXTERN
2241 int
ParametricObject_setDataType(ParametricObject_t * po,DataKind_t dataType)2242 ParametricObject_setDataType(ParametricObject_t * po, DataKind_t dataType)
2243 {
2244 return (po != NULL) ? po->setDataType(dataType) : LIBSBML_INVALID_OBJECT;
2245 }
2246
2247
2248 /*
2249 * Sets the value of the "dataType" attribute of this ParametricObject_t.
2250 */
2251 LIBSBML_EXTERN
2252 int
ParametricObject_setDataTypeAsString(ParametricObject_t * po,const char * dataType)2253 ParametricObject_setDataTypeAsString(ParametricObject_t * po,
2254 const char * dataType)
2255 {
2256 return (po != NULL) ? po->setDataType(dataType): LIBSBML_INVALID_OBJECT;
2257 }
2258
2259
2260 /*
2261 * Unsets the value of the "id" attribute of this ParametricObject_t.
2262 */
2263 LIBSBML_EXTERN
2264 int
ParametricObject_unsetId(ParametricObject_t * po)2265 ParametricObject_unsetId(ParametricObject_t * po)
2266 {
2267 return (po != NULL) ? po->unsetId() : LIBSBML_INVALID_OBJECT;
2268 }
2269
2270
2271 /*
2272 * Unsets the value of the "name" attribute of this ParametricObject_t.
2273 */
2274 LIBSBML_EXTERN
2275 int
ParametricObject_unsetName(ParametricObject_t * po)2276 ParametricObject_unsetName(ParametricObject_t * po)
2277 {
2278 return (po != NULL) ? po->unsetName() : LIBSBML_INVALID_OBJECT;
2279 }
2280
2281
2282 /*
2283 * Unsets the value of the "polygonType" attribute of this ParametricObject_t.
2284 */
2285 LIBSBML_EXTERN
2286 int
ParametricObject_unsetPolygonType(ParametricObject_t * po)2287 ParametricObject_unsetPolygonType(ParametricObject_t * po)
2288 {
2289 return (po != NULL) ? po->unsetPolygonType() : LIBSBML_INVALID_OBJECT;
2290 }
2291
2292
2293 /*
2294 * Unsets the value of the "domainType" attribute of this ParametricObject_t.
2295 */
2296 LIBSBML_EXTERN
2297 int
ParametricObject_unsetDomainType(ParametricObject_t * po)2298 ParametricObject_unsetDomainType(ParametricObject_t * po)
2299 {
2300 return (po != NULL) ? po->unsetDomainType() : LIBSBML_INVALID_OBJECT;
2301 }
2302
2303
2304 /*
2305 * Unsets the value of the "pointIndex" attribute of this ParametricObject_t.
2306 */
2307 LIBSBML_EXTERN
2308 int
ParametricObject_unsetPointIndex(ParametricObject_t * po)2309 ParametricObject_unsetPointIndex(ParametricObject_t * po)
2310 {
2311 return (po != NULL) ? po->unsetPointIndex() : LIBSBML_INVALID_OBJECT;
2312 }
2313
2314
2315 /*
2316 * Unsets the value of the "pointIndexLength" attribute of this
2317 * ParametricObject_t.
2318 */
2319 LIBSBML_EXTERN
2320 int
ParametricObject_unsetPointIndexLength(ParametricObject_t * po)2321 ParametricObject_unsetPointIndexLength(ParametricObject_t * po)
2322 {
2323 return (po != NULL) ? po->unsetPointIndexLength() : LIBSBML_INVALID_OBJECT;
2324 }
2325
2326
2327 /*
2328 * Unsets the value of the "compression" attribute of this ParametricObject_t.
2329 */
2330 LIBSBML_EXTERN
2331 int
ParametricObject_unsetCompression(ParametricObject_t * po)2332 ParametricObject_unsetCompression(ParametricObject_t * po)
2333 {
2334 return (po != NULL) ? po->unsetCompression() : LIBSBML_INVALID_OBJECT;
2335 }
2336
2337
2338 /*
2339 * Unsets the value of the "dataType" attribute of this ParametricObject_t.
2340 */
2341 LIBSBML_EXTERN
2342 int
ParametricObject_unsetDataType(ParametricObject_t * po)2343 ParametricObject_unsetDataType(ParametricObject_t * po)
2344 {
2345 return (po != NULL) ? po->unsetDataType() : LIBSBML_INVALID_OBJECT;
2346 }
2347
2348
2349 /*
2350 * Predicate returning @c 1 (true) if all the required attributes for this
2351 * ParametricObject_t object have been set.
2352 */
2353 LIBSBML_EXTERN
2354 int
ParametricObject_hasRequiredAttributes(const ParametricObject_t * po)2355 ParametricObject_hasRequiredAttributes(const ParametricObject_t * po)
2356 {
2357 return (po != NULL) ? static_cast<int>(po->hasRequiredAttributes()) : 0;
2358 }
2359
2360
2361
2362
2363 LIBSBML_CPP_NAMESPACE_END
2364
2365
2366