1 /**
2  * @file SampledField.cpp
3  * @brief Implementation of the SampledField 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/SampledField.h>
43 #include <sbml/packages/spatial/sbml/ListOfSampledFields.h>
44 #include <sbml/packages/spatial/validator/SpatialSBMLError.h>
45 #include <sbml/packages/spatial/common/CompressionUtil.h>
46 
47 
48 using namespace std;
49 
50 
51 
52 LIBSBML_CPP_NAMESPACE_BEGIN
53 
54 
55 
56 
57 #ifdef __cplusplus
58 
59 /*
60  * Creates a new SampledField using the given SBML Level, Version and
61  * &ldquo;spatial&rdquo; package version.
62  */
SampledField(unsigned int level,unsigned int version,unsigned int pkgVersion)63 SampledField::SampledField(unsigned int level,
64   unsigned int version,
65   unsigned int pkgVersion)
66   : SBase(level, version)
67   , mDataType(SPATIAL_DATAKIND_INVALID)
68   , mNumSamples1(0)
69   , mIsSetNumSamples1(false)
70   , mNumSamples2(0)
71   , mIsSetNumSamples2(false)
72   , mNumSamples3(0)
73   , mIsSetNumSamples3(false)
74   , mInterpolationType(SPATIAL_INTERPOLATIONKIND_INVALID)
75   , mCompression(SPATIAL_COMPRESSIONKIND_INVALID)
76   , mSamples()
77   , mSamplesLength(SBML_INT_MAX)
78   , mIsSetSamplesLength(false)
79   , mSamplesCompressed(NULL)
80   , mSamplesUncompressed(NULL)
81   , mSamplesUncompressedInt(NULL)
82   , mSamplesCompressedLength(0)
83   , mSamplesUncompressedLength(0)
84 {
85   setSBMLNamespacesAndOwn(new SpatialPkgNamespaces(level, version,
86     pkgVersion));
87 }
88 
89 
90 /*
91  * Creates a new SampledField using the given SpatialPkgNamespaces object.
92  */
SampledField(SpatialPkgNamespaces * spatialns)93 SampledField::SampledField(SpatialPkgNamespaces* spatialns)
94   : SBase(spatialns)
95   , mDataType(SPATIAL_DATAKIND_INVALID)
96   , mNumSamples1(0)
97   , mIsSetNumSamples1(false)
98   , mNumSamples2(0)
99   , mIsSetNumSamples2(false)
100   , mNumSamples3(0)
101   , mIsSetNumSamples3(false)
102   , mInterpolationType(SPATIAL_INTERPOLATIONKIND_INVALID)
103   , mCompression(SPATIAL_COMPRESSIONKIND_INVALID)
104   , mSamples()
105   , mSamplesLength(SBML_INT_MAX)
106   , mIsSetSamplesLength(false)
107   , mSamplesCompressed(NULL)
108   , mSamplesUncompressed(NULL)
109   , mSamplesUncompressedInt(NULL)
110   , mSamplesCompressedLength(0)
111   , mSamplesUncompressedLength(0)
112 {
113   setElementNamespace(spatialns->getURI());
114   // connect to child objects
115   connectToChild();
116 
117   loadPlugins(spatialns);
118 }
119 
120 
121 /*
122  * Copy constructor for SampledField.
123  */
SampledField(const SampledField & orig)124 SampledField::SampledField(const SampledField& orig)
125   : SBase(orig)
126   , mDataType(orig.mDataType)
127   , mNumSamples1(orig.mNumSamples1)
128   , mIsSetNumSamples1(orig.mIsSetNumSamples1)
129   , mNumSamples2(orig.mNumSamples2)
130   , mIsSetNumSamples2(orig.mIsSetNumSamples2)
131   , mNumSamples3(orig.mNumSamples3)
132   , mIsSetNumSamples3(orig.mIsSetNumSamples3)
133   , mInterpolationType(orig.mInterpolationType)
134   , mCompression(orig.mCompression)
135   , mSamples(orig.mSamples)
136   , mSamplesLength(orig.mSamplesLength)
137   , mIsSetSamplesLength(orig.mIsSetSamplesLength)
138   , mSamplesCompressed(NULL)
139   , mSamplesUncompressed(NULL)
140   , mSamplesUncompressedInt(NULL)
141   , mSamplesCompressedLength(0)
142   , mSamplesUncompressedLength(0)
143 {
144   // connect to child objects
145   connectToChild();
146 }
147 
148 
149 /*
150  * Assignment operator for SampledField.
151  */
152 SampledField&
operator =(const SampledField & rhs)153 SampledField::operator=(const SampledField& rhs)
154 {
155   if (&rhs != this)
156   {
157     SBase::operator=(rhs);
158     mDataType = rhs.mDataType;
159     mNumSamples1 = rhs.mNumSamples1;
160     mIsSetNumSamples1 = rhs.mIsSetNumSamples1;
161     mNumSamples2 = rhs.mNumSamples2;
162     mIsSetNumSamples2 = rhs.mIsSetNumSamples2;
163     mNumSamples3 = rhs.mNumSamples3;
164     mIsSetNumSamples3 = rhs.mIsSetNumSamples3;
165     mInterpolationType = rhs.mInterpolationType;
166     mCompression = rhs.mCompression;
167     mSamples = rhs.mSamples;
168     mSamplesLength = rhs.mSamplesLength;
169     mIsSetSamplesLength = rhs.mIsSetSamplesLength;
170 
171     freeCompressed();
172     freeUncompressed();
173     // connect to child objects
174     connectToChild();
175   }
176 
177   return *this;
178 }
179 
180 
181 /*
182  * Creates and returns a deep copy of this SampledField object.
183  */
184 SampledField*
clone() const185 SampledField::clone() const
186 {
187   return new SampledField(*this);
188 }
189 
190 
191 /*
192  * Destructor for SampledField.
193  */
~SampledField()194 SampledField::~SampledField()
195 {
196   freeCompressed();
197   freeUncompressed();
198 }
199 
200 
201 /*
202  * Returns the value of the "id" attribute of this SampledField.
203  */
204 const std::string&
getId() const205 SampledField::getId() const
206 {
207   return mId;
208 }
209 
210 
211 /*
212  * Returns the value of the "name" attribute of this SampledField.
213  */
214 const std::string&
getName() const215 SampledField::getName() const
216 {
217   return mName;
218 }
219 
220 
221 /*
222  * Returns the value of the "dataType" attribute of this SampledField.
223  */
224 DataKind_t
getDataType() const225 SampledField::getDataType() const
226 {
227   return mDataType;
228 }
229 
230 
231 /*
232  * Returns the value of the "dataType" attribute of this SampledField.
233  */
234 std::string
getDataTypeAsString() const235 SampledField::getDataTypeAsString() const
236 {
237   return DataKind_toString(mDataType);
238 }
239 
240 
241 /*
242  * Returns the value of the "numSamples1" attribute of this SampledField.
243  */
244 int
getNumSamples1() const245 SampledField::getNumSamples1() const
246 {
247   return mNumSamples1;
248 }
249 
250 
251 /*
252  * Returns the value of the "numSamples2" attribute of this SampledField.
253  */
254 int
getNumSamples2() const255 SampledField::getNumSamples2() const
256 {
257   return mNumSamples2;
258 }
259 
260 
261 /*
262  * Returns the value of the "numSamples3" attribute of this SampledField.
263  */
264 int
getNumSamples3() const265 SampledField::getNumSamples3() const
266 {
267   return mNumSamples3;
268 }
269 
270 
271 /*
272  * Returns the value of the "interpolationType" attribute of this SampledField.
273  */
274 InterpolationKind_t
getInterpolationType() const275 SampledField::getInterpolationType() const
276 {
277   return mInterpolationType;
278 }
279 
280 
281 /*
282  * Returns the value of the "interpolationType" attribute of this SampledField.
283  */
284 std::string
getInterpolationTypeAsString() const285 SampledField::getInterpolationTypeAsString() const
286 {
287   return InterpolationKind_toString(mInterpolationType);
288 }
289 
290 
291 /*
292  * Returns the value of the "compression" attribute of this SampledField.
293  */
294 CompressionKind_t
getCompression() const295 SampledField::getCompression() const
296 {
297   return mCompression;
298 }
299 
300 
301 /*
302  * Returns the value of the "compression" attribute of this SampledField.
303  */
304 std::string
getCompressionAsString() const305 SampledField::getCompressionAsString() const
306 {
307   std::string code_str = CompressionKind_toString(mCompression);
308   return code_str;
309 }
310 
311 
getSamples(std::vector<int> & outVector) const312 void SampledField::getSamples(std::vector<int>& outVector) const
313 {
314   readSamplesFromString<int>(mSamples, outVector);
315   if (outVector.size() != getActualSamplesLength()) {
316     outVector.clear();
317   }
318 }
319 
getSamples(std::vector<float> & outVector) const320 void SampledField::getSamples(std::vector<float>& outVector) const
321 {
322   store();
323   string uncompressedString;
324   uncompressInternal(uncompressedString, mSamplesUncompressedLength);
325   readSamplesFromString<float>(uncompressedString, outVector);
326 }
327 
getSamples(std::vector<double> & outVector) const328 void SampledField::getSamples(std::vector<double>& outVector) const
329 {
330   store();
331   string uncompressedString;
332   uncompressInternal(uncompressedString, mSamplesUncompressedLength);
333   readSamplesFromString<double>(uncompressedString, outVector);
334 }
335 
getSamples() const336 std::string SampledField::getSamples() const
337 {
338   return mSamples;
339 }
340 
341 int
getSamples(int * outArray) const342 SampledField::getSamples(int* outArray) const
343 {
344   if (outArray == NULL)
345   {
346     return LIBSBML_OPERATION_FAILED;
347   }
348   store();
349   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
350   {
351     if (mSamplesCompressed == NULL)
352     {
353       return LIBSBML_OPERATION_FAILED;
354     }
355     memcpy(outArray, mSamplesCompressed, sizeof(int)*mSamplesCompressedLength);
356   }
357   else
358   {
359     if (mSamplesUncompressedInt == NULL)
360     {
361       return LIBSBML_OPERATION_FAILED;
362     }
363     memcpy(outArray, mSamplesUncompressedInt, sizeof(int)*mSamplesUncompressedLength);
364   }
365   return LIBSBML_OPERATION_SUCCESS;
366 }
367 
368 int
getSamples(double * outArray) const369 SampledField::getSamples(double* outArray) const
370 {
371   if (outArray == NULL)
372   {
373     return LIBSBML_OPERATION_FAILED;
374   }
375   //This function will uncompres and store the data if need be:
376   size_t len = getUncompressedLength();
377 
378   if (mSamplesUncompressed == NULL)
379   {
380     return LIBSBML_OPERATION_FAILED;
381   }
382 
383   memcpy(outArray, mSamplesUncompressed, sizeof(double)*mSamplesUncompressedLength);
384   return LIBSBML_OPERATION_SUCCESS;
385 }
386 
387 
388 int
getSamples(float * outArray) const389 SampledField::getSamples(float* outArray) const
390 {
391   if (outArray == NULL)
392   {
393     return LIBSBML_OPERATION_FAILED;
394   }
395 
396   store();
397   float* samples = NULL;
398   size_t length;
399   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
400   {
401     string uncompressedString;
402     uncompressInternal(uncompressedString, length);
403     samples = readSamplesFromString<float>(uncompressedString, length);
404   }
405   else {
406     samples = readSamplesFromString<float>(mSamples, length);
407   }
408 
409   if (samples == NULL || length==0)
410   {
411     return LIBSBML_OPERATION_FAILED;
412   }
413   memcpy(outArray, samples, sizeof(float) * length);
414   free(samples);
415   return LIBSBML_OPERATION_SUCCESS;
416 }
417 
418 int
getSamplesLength() const419 SampledField::getSamplesLength() const
420 {
421   return mSamplesLength;
422 }
423 
getActualSamplesLength() const424 size_t SampledField::getActualSamplesLength() const
425 {
426   store();
427   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED) {
428     return mSamplesCompressedLength;
429   }
430   return mSamplesUncompressedLength;
431 }
432 
433 
434 /*
435  * Predicate returning @c true if this SampledField's "id" attribute is set.
436  */
437 bool
isSetId() const438 SampledField::isSetId() const
439 {
440   return (mId.empty() == false);
441 }
442 
443 
444 /*
445  * Predicate returning @c true if this SampledField's "name" attribute is set.
446  */
447 bool
isSetName() const448 SampledField::isSetName() const
449 {
450   return (mName.empty() == false);
451 }
452 
453 
454 /*
455  * Predicate returning @c true if this SampledField's "dataType" attribute is
456  * set.
457  */
458 bool
isSetDataType() const459 SampledField::isSetDataType() const
460 {
461   return (mDataType != SPATIAL_DATAKIND_INVALID);
462 }
463 
464 
465 /*
466  * Predicate returning @c true if this SampledField's "numSamples1" attribute
467  * is set.
468  */
469 bool
isSetNumSamples1() const470 SampledField::isSetNumSamples1() const
471 {
472   return mIsSetNumSamples1;
473 }
474 
475 
476 /*
477  * Predicate returning @c true if this SampledField's "numSamples2" attribute
478  * is set.
479  */
480 bool
isSetNumSamples2() const481 SampledField::isSetNumSamples2() const
482 {
483   return mIsSetNumSamples2;
484 }
485 
486 
487 /*
488  * Predicate returning @c true if this SampledField's "numSamples3" attribute
489  * is set.
490  */
491 bool
isSetNumSamples3() const492 SampledField::isSetNumSamples3() const
493 {
494   return mIsSetNumSamples3;
495 }
496 
497 
498 /*
499  * Predicate returning @c true if this SampledField's "interpolationType"
500  * attribute is set.
501  */
502 bool
isSetInterpolationType() const503 SampledField::isSetInterpolationType() const
504 {
505   return (mInterpolationType != SPATIAL_INTERPOLATIONKIND_INVALID);
506 }
507 
508 
509 /*
510  * Predicate returning @c true if this SampledField's "compression" attribute
511  * is set.
512  */
513 bool
isSetCompression() const514 SampledField::isSetCompression() const
515 {
516   return (mCompression != SPATIAL_COMPRESSIONKIND_INVALID);
517 }
518 
519 
520 /*
521  * Predicate returning @c true if this SampledField's "samples" attribute is
522  * set.
523  */
524 bool
isSetSamples() const525 SampledField::isSetSamples() const
526 {
527   return (!mSamples.empty());
528 }
529 
530 
531 /*
532  * Predicate returning @c true if this SampledField's "samplesLength" attribute
533  * is set.
534  */
535 bool
isSetSamplesLength() const536 SampledField::isSetSamplesLength() const
537 {
538   return mIsSetSamplesLength;
539 }
540 
541 
542 /*
543  * Sets the value of the "id" attribute of this SampledField.
544  */
545 int
setId(const std::string & id)546 SampledField::setId(const std::string& id)
547 {
548   return SyntaxChecker::checkAndSetSId(id, mId);
549 }
550 
551 
552 /*
553  * Sets the value of the "name" attribute of this SampledField.
554  */
555 int
setName(const std::string & name)556 SampledField::setName(const std::string& name)
557 {
558   mName = name;
559   return LIBSBML_OPERATION_SUCCESS;
560 }
561 
562 
563 /*
564  * Sets the value of the "dataType" attribute of this SampledField.
565  */
566 int
setDataType(const DataKind_t dataType)567 SampledField::setDataType(const DataKind_t dataType)
568 {
569   if (DataKind_isValid(dataType) == 0)
570   {
571     mDataType = SPATIAL_DATAKIND_INVALID;
572     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
573   }
574   else
575   {
576     mDataType = dataType;
577     return LIBSBML_OPERATION_SUCCESS;
578   }
579 }
580 
581 
582 /*
583  * Sets the value of the "dataType" attribute of this SampledField.
584  */
585 int
setDataType(const std::string & dataType)586 SampledField::setDataType(const std::string& dataType)
587 {
588   mDataType = DataKind_fromString(dataType.c_str());
589 
590   if (mDataType == SPATIAL_DATAKIND_INVALID)
591   {
592     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
593   }
594 
595   return LIBSBML_OPERATION_SUCCESS;
596 }
597 
598 
599 /*
600  * Sets the value of the "numSamples1" attribute of this SampledField.
601  */
602 int
setNumSamples1(int numSamples1)603 SampledField::setNumSamples1(int numSamples1)
604 {
605   if (numSamples1 < 1) {
606     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
607   }
608   mNumSamples1 = numSamples1;
609   mIsSetNumSamples1 = true;
610   return LIBSBML_OPERATION_SUCCESS;
611 }
612 
613 
614 /*
615  * Sets the value of the "numSamples2" attribute of this SampledField.
616  */
617 int
setNumSamples2(int numSamples2)618 SampledField::setNumSamples2(int numSamples2)
619 {
620   if (numSamples2 < 1) {
621     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
622   }
623   mNumSamples2 = numSamples2;
624   mIsSetNumSamples2 = true;
625   return LIBSBML_OPERATION_SUCCESS;
626 }
627 
628 
629 /*
630  * Sets the value of the "numSamples3" attribute of this SampledField.
631  */
632 int
setNumSamples3(int numSamples3)633 SampledField::setNumSamples3(int numSamples3)
634 {
635   if (numSamples3 < 1) {
636     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
637   }
638   mNumSamples3 = numSamples3;
639   mIsSetNumSamples3 = true;
640   return LIBSBML_OPERATION_SUCCESS;
641 }
642 
643 
644 /*
645  * Sets the value of the "interpolationType" attribute of this SampledField.
646  */
647 int
setInterpolationType(const InterpolationKind_t interpolationType)648 SampledField::setInterpolationType(const InterpolationKind_t interpolationType)
649 {
650   if (InterpolationKind_isValid(interpolationType) == 0)
651   {
652     mInterpolationType = SPATIAL_INTERPOLATIONKIND_INVALID;
653     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
654   }
655   else
656   {
657     mInterpolationType = interpolationType;
658     return LIBSBML_OPERATION_SUCCESS;
659   }
660 }
661 
662 
663 /*
664  * Sets the value of the "interpolationType" attribute of this SampledField.
665  */
666 int
setInterpolationType(const std::string & interpolationType)667 SampledField::setInterpolationType(const std::string& interpolationType)
668 {
669   mInterpolationType = InterpolationKind_fromString(interpolationType.c_str());
670 
671   if (mInterpolationType == SPATIAL_INTERPOLATIONKIND_INVALID)
672   {
673     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
674   }
675 
676   return LIBSBML_OPERATION_SUCCESS;
677 }
678 
679 
680 /*
681  * Sets the value of the "compression" attribute of this SampledField.
682  */
683 int
setCompression(const CompressionKind_t compression)684 SampledField::setCompression(const CompressionKind_t compression)
685 {
686   if (CompressionKind_isValid(compression) == 0)
687   {
688     mCompression = SPATIAL_COMPRESSIONKIND_INVALID;
689     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
690   }
691   else
692   {
693     mCompression = compression;
694     return LIBSBML_OPERATION_SUCCESS;
695   }
696 }
697 
698 
699 /*
700  * Sets the value of the "compression" attribute of this SampledField.
701  */
702 int
setCompression(const std::string & compression)703 SampledField::setCompression(const std::string& compression)
704 {
705   if (CompressionKind_isValidString(compression.c_str()) == 0)
706   {
707     mCompression = SPATIAL_COMPRESSIONKIND_INVALID;
708     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
709   }
710   else
711   {
712     mCompression = CompressionKind_fromString(compression.c_str());
713     return LIBSBML_OPERATION_SUCCESS;
714   }
715   //bgoli22
716   mCompression = CompressionKind_fromString(compression.c_str());
717   if (mCompression == SPATIAL_COMPRESSIONKIND_INVALID)
718   {
719     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
720   }
721   return LIBSBML_OPERATION_SUCCESS;
722 }
723 
724 
725 int
setSamples(double * inArray,size_t arrayLength)726 SampledField::setSamples(double* inArray, size_t arrayLength)
727 {
728   if (inArray == NULL)
729   {
730     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
731   }
732   setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
733 
734   freeCompressed();
735   freeUncompressed();
736   copySampleArrays(mSamplesUncompressed, mSamplesUncompressedLength, inArray, arrayLength);
737   mSamples = arrayToString(inArray, arrayLength);
738   return setSamplesLength(arrayLength);
739 }
740 
741 
742 int
setSamples(int * inArray,size_t arrayLength)743 SampledField::setSamples(int* inArray, size_t arrayLength)
744 {
745   if (inArray == NULL)
746   {
747     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
748   }
749   freeCompressed();
750   freeUncompressed();
751   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
752   {
753     copySampleArrays(mSamplesCompressed, mSamplesCompressedLength, inArray, arrayLength);
754     mSamples = arrayToString(inArray, arrayLength);
755     setSamplesLength(arrayLength);
756   }
757   else {
758     copySampleArrays(mSamplesUncompressedInt, mSamplesUncompressedLength, inArray, arrayLength);
759     mSamples = arrayToString(inArray, arrayLength);
760     setSamplesLength(arrayLength);
761   }
762 
763   return LIBSBML_OPERATION_SUCCESS;
764 }
765 
766 
setSamples(unsigned int * inArray,size_t arrayLength)767 int SampledField::setSamples(unsigned int* inArray, size_t arrayLength)
768 {
769   if (inArray == NULL)
770   {
771     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
772   }
773 
774   mSamples = arrayToString(inArray, arrayLength);
775 
776   return setSamplesLength(arrayLength);
777 }
778 
setSamples(unsigned char * inArray,size_t arrayLength)779 int SampledField::setSamples(unsigned char* inArray, size_t arrayLength)
780 {
781   if (inArray == NULL)
782   {
783     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
784   }
785 
786   mSamples = arrayToString(inArray, arrayLength);
787 
788   return setSamplesLength(arrayLength);
789 }
790 
791 
792 int
setSamples(float * inArray,size_t arrayLength)793 SampledField::setSamples(float* inArray, size_t arrayLength)
794 {
795   if (inArray == NULL)
796   {
797     return LIBSBML_INVALID_ATTRIBUTE_VALUE;
798   }
799   setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
800 
801   mSamples = arrayToString(inArray, arrayLength);
802 
803   return setSamplesLength(arrayLength);
804 }
805 
setSamples(const std::string & samples)806 int SampledField::setSamples(const std::string& samples)
807 {
808   mSamples = samples;
809   return LIBSBML_OPERATION_SUCCESS;
810 }
811 
setSamples(const std::vector<double> & samples)812 int SampledField::setSamples(const std::vector<double>& samples)
813 {
814   mSamples = vectorToString(samples);
815   setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
816   return setSamplesLength(samples.size());
817 }
818 
setSamples(const std::vector<int> & samples)819 int SampledField::setSamples(const std::vector<int>& samples)
820 {
821   mSamples = vectorToString(samples);
822   return setSamplesLength(samples.size());
823 }
824 
setSamples(const std::vector<float> & samples)825 int SampledField::setSamples(const std::vector<float>& samples)
826 {
827   mSamples = vectorToString(samples);
828   setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
829   return setSamplesLength(samples.size());
830 }
831 
832 /*
833  * Sets the value of the "samplesLength" attribute of this SampledField.
834  */
835 int
setSamplesLength(int samplesLength)836 SampledField::setSamplesLength(int samplesLength)
837 {
838   mSamplesLength = samplesLength;
839   mIsSetSamplesLength = true;
840   return LIBSBML_OPERATION_SUCCESS;
841 }
842 
843 
844 /*
845  * Unsets the value of the "id" attribute of this SampledField.
846  */
847 int
unsetId()848 SampledField::unsetId()
849 {
850   mId.erase();
851 
852   if (mId.empty() == true)
853   {
854     return LIBSBML_OPERATION_SUCCESS;
855   }
856   else
857   {
858     return LIBSBML_OPERATION_FAILED;
859   }
860 }
861 
862 
863 /*
864  * Unsets the value of the "name" attribute of this SampledField.
865  */
866 int
unsetName()867 SampledField::unsetName()
868 {
869   mName.erase();
870 
871   if (mName.empty() == true)
872   {
873     return LIBSBML_OPERATION_SUCCESS;
874   }
875   else
876   {
877     return LIBSBML_OPERATION_FAILED;
878   }
879 }
880 
881 
882 /*
883  * Unsets the value of the "dataType" attribute of this SampledField.
884  */
885 int
unsetDataType()886 SampledField::unsetDataType()
887 {
888   mDataType = SPATIAL_DATAKIND_INVALID;
889   return LIBSBML_OPERATION_SUCCESS;
890 }
891 
892 
893 /*
894  * Unsets the value of the "numSamples1" attribute of this SampledField.
895  */
896 int
unsetNumSamples1()897 SampledField::unsetNumSamples1()
898 {
899   mNumSamples1 = SBML_INT_MAX;
900   mIsSetNumSamples1 = false;
901 
902   if (isSetNumSamples1() == false)
903   {
904     return LIBSBML_OPERATION_SUCCESS;
905   }
906   else
907   {
908     return LIBSBML_OPERATION_FAILED;
909   }
910 }
911 
912 
913 /*
914  * Unsets the value of the "numSamples2" attribute of this SampledField.
915  */
916 int
unsetNumSamples2()917 SampledField::unsetNumSamples2()
918 {
919   mNumSamples2 = SBML_INT_MAX;
920   mIsSetNumSamples2 = false;
921 
922   if (isSetNumSamples2() == false)
923   {
924     return LIBSBML_OPERATION_SUCCESS;
925   }
926   else
927   {
928     return LIBSBML_OPERATION_FAILED;
929   }
930 }
931 
932 
933 /*
934  * Unsets the value of the "numSamples3" attribute of this SampledField.
935  */
936 int
unsetNumSamples3()937 SampledField::unsetNumSamples3()
938 {
939   mNumSamples3 = SBML_INT_MAX;
940   mIsSetNumSamples3 = false;
941 
942   if (isSetNumSamples3() == false)
943   {
944     return LIBSBML_OPERATION_SUCCESS;
945   }
946   else
947   {
948     return LIBSBML_OPERATION_FAILED;
949   }
950 }
951 
952 
953 /*
954  * Unsets the value of the "interpolationType" attribute of this SampledField.
955  */
956 int
unsetInterpolationType()957 SampledField::unsetInterpolationType()
958 {
959   mInterpolationType = SPATIAL_INTERPOLATIONKIND_INVALID;
960   return LIBSBML_OPERATION_SUCCESS;
961 }
962 
963 
964 /*
965  * Unsets the value of the "compression" attribute of this SampledField.
966  */
967 int
unsetCompression()968 SampledField::unsetCompression()
969 {
970   mCompression = SPATIAL_COMPRESSIONKIND_INVALID;
971   return LIBSBML_OPERATION_SUCCESS;
972 }
973 
974 
975 /*
976  * Unsets the value of the "samples" attribute of this SampledField.
977  */
978 int
unsetSamples()979 SampledField::unsetSamples()
980 {
981   mSamples.clear();
982   freeCompressed();
983   freeUncompressed();
984 
985   return unsetSamplesLength();
986 }
987 
988 
989 /*
990  * Unsets the value of the "samplesLength" attribute of this SampledField.
991  */
992 int
unsetSamplesLength()993 SampledField::unsetSamplesLength()
994 {
995   mSamplesLength = SBML_INT_MAX;
996   mIsSetSamplesLength = false;
997 
998   if (isSetSamplesLength() == false)
999   {
1000     return LIBSBML_OPERATION_SUCCESS;
1001   }
1002   else
1003   {
1004     return LIBSBML_OPERATION_FAILED;
1005   }
1006 }
1007 
1008 
1009 /*
1010  * Returns the XML element name of this SampledField object.
1011  */
1012 const std::string&
getElementName() const1013 SampledField::getElementName() const
1014 {
1015   static const string name = "sampledField";
1016   return name;
1017 }
1018 
1019 
1020 /*
1021  * Returns the libSBML type code for this SampledField object.
1022  */
1023 int
getTypeCode() const1024 SampledField::getTypeCode() const
1025 {
1026   return SBML_SPATIAL_SAMPLEDFIELD;
1027 }
1028 
1029 
1030 /*
1031  * Predicate returning @c true if all the required attributes for this
1032  * SampledField object have been set.
1033  */
1034 bool
hasRequiredAttributes() const1035 SampledField::hasRequiredAttributes() const
1036 {
1037   bool allPresent = true;
1038 
1039   if (isSetId() == false)
1040   {
1041     allPresent = false;
1042   }
1043 
1044   if (isSetDataType() == false)
1045   {
1046     allPresent = false;
1047   }
1048 
1049   if (isSetNumSamples1() == false)
1050   {
1051     allPresent = false;
1052   }
1053 
1054   if (isSetInterpolationType() == false)
1055   {
1056     allPresent = false;
1057   }
1058 
1059   if (isSetCompression() == false)
1060   {
1061     allPresent = false;
1062   }
1063 
1064   if (isSetSamples() == false)
1065   {
1066     allPresent = false;
1067   }
1068 
1069   if (isSetSamplesLength() == false)
1070   {
1071     allPresent = false;
1072   }
1073 
1074   return allPresent;
1075 }
1076 
1077 
1078 
1079 /** @cond doxygenLibsbmlInternal */
1080 
1081 /*
1082  * Write any contained elements
1083  */
1084 void
writeElements(XMLOutputStream & stream) const1085 SampledField::writeElements(XMLOutputStream& stream) const
1086 {
1087   SBase::writeElements(stream);
1088 
1089   SBase::writeExtensionElements(stream);
1090 }
1091 
1092 /** @endcond */
1093 
1094 
1095 
1096 /** @cond doxygenLibsbmlInternal */
1097 
1098 /*
1099  * Accepts the given SBMLVisitor
1100  */
1101 bool
accept(SBMLVisitor & v) const1102 SampledField::accept(SBMLVisitor& v) const
1103 {
1104   return v.visit(*this);
1105 }
1106 
1107 /** @endcond */
1108 
1109 
1110 
1111 /** @cond doxygenLibsbmlInternal */
1112 
1113 /*
1114  * Sets the parent SBMLDocument
1115  */
1116 void
setSBMLDocument(SBMLDocument * d)1117 SampledField::setSBMLDocument(SBMLDocument* d)
1118 {
1119   SBase::setSBMLDocument(d);
1120 }
1121 
1122 /** @endcond */
1123 
1124 
1125 
1126 /** @cond doxygenLibsbmlInternal */
1127 
1128 /*
1129  * used to write arrays
1130  */
1131 void
write(XMLOutputStream & stream) const1132 SampledField::write(XMLOutputStream& stream) const
1133 {
1134   stream.startElement(getElementName(), getPrefix());
1135   writeAttributes(stream);
1136 
1137   if (isSetSamples())
1138   {
1139     //for (int i = 0; i < mSamplesLength; ++i)
1140     //{
1141     //  stream << (long)mSamples[i] << " ";
1142     //}
1143 
1144     stream << mSamples;
1145   }
1146 
1147   stream.endElement(getElementName(), getPrefix());
1148 }
1149 
1150 /** @endcond */
1151 
1152 
1153 
1154 /** @cond doxygenLibsbmlInternal */
1155 
1156 /*
1157  * Enables/disables the given package with this element
1158  */
1159 void
enablePackageInternal(const std::string & pkgURI,const std::string & pkgPrefix,bool flag)1160 SampledField::enablePackageInternal(const std::string& pkgURI,
1161   const std::string& pkgPrefix,
1162   bool flag)
1163 {
1164   SBase::enablePackageInternal(pkgURI, pkgPrefix, flag);
1165 }
1166 
1167 /** @endcond */
1168 
1169 
1170 
1171 /** @cond doxygenLibsbmlInternal */
1172 
1173 /*
1174  * Gets the value of the "attributeName" attribute of this SampledField.
1175  */
1176 int
getAttribute(const std::string & attributeName,bool & value) const1177 SampledField::getAttribute(const std::string& attributeName,
1178   bool& value) const
1179 {
1180   int return_value = SBase::getAttribute(attributeName, value);
1181 
1182   return return_value;
1183 }
1184 
1185 /** @endcond */
1186 
1187 
1188 
1189 /** @cond doxygenLibsbmlInternal */
1190 
1191 /*
1192  * Gets the value of the "attributeName" attribute of this SampledField.
1193  */
1194 int
getAttribute(const std::string & attributeName,int & value) const1195 SampledField::getAttribute(const std::string& attributeName, int& value) const
1196 {
1197   int return_value = SBase::getAttribute(attributeName, value);
1198 
1199   if (return_value == LIBSBML_OPERATION_SUCCESS)
1200   {
1201     return return_value;
1202   }
1203 
1204   if (attributeName == "numSamples1")
1205   {
1206     value = getNumSamples1();
1207     return_value = LIBSBML_OPERATION_SUCCESS;
1208   }
1209   else if (attributeName == "numSamples2")
1210   {
1211     value = getNumSamples2();
1212     return_value = LIBSBML_OPERATION_SUCCESS;
1213   }
1214   else if (attributeName == "numSamples3")
1215   {
1216     value = getNumSamples3();
1217     return_value = LIBSBML_OPERATION_SUCCESS;
1218   }
1219   else if (attributeName == "samplesLength")
1220   {
1221     value = getSamplesLength();
1222     return_value = LIBSBML_OPERATION_SUCCESS;
1223   }
1224 
1225   return return_value;
1226 }
1227 
1228 /** @endcond */
1229 
1230 
1231 
1232 /** @cond doxygenLibsbmlInternal */
1233 
1234 /*
1235  * Gets the value of the "attributeName" attribute of this SampledField.
1236  */
1237 int
getAttribute(const std::string & attributeName,double & value) const1238 SampledField::getAttribute(const std::string& attributeName,
1239   double& value) const
1240 {
1241   int return_value = SBase::getAttribute(attributeName, value);
1242 
1243   return return_value;
1244 }
1245 
1246 /** @endcond */
1247 
1248 
1249 
1250 /** @cond doxygenLibsbmlInternal */
1251 
1252 /*
1253  * Gets the value of the "attributeName" attribute of this SampledField.
1254  */
1255 int
getAttribute(const std::string & attributeName,unsigned int & value) const1256 SampledField::getAttribute(const std::string& attributeName,
1257   unsigned int& value) const
1258 {
1259   int return_value = SBase::getAttribute(attributeName, value);
1260 
1261   return return_value;
1262 }
1263 
1264 /** @endcond */
1265 
1266 
1267 
1268 /** @cond doxygenLibsbmlInternal */
1269 
1270 /*
1271  * Gets the value of the "attributeName" attribute of this SampledField.
1272  */
1273 int
getAttribute(const std::string & attributeName,std::string & value) const1274 SampledField::getAttribute(const std::string& attributeName,
1275   std::string& value) const
1276 {
1277   int return_value = SBase::getAttribute(attributeName, value);
1278 
1279   if (return_value == LIBSBML_OPERATION_SUCCESS)
1280   {
1281     return return_value;
1282   }
1283 
1284   if (attributeName == "id")
1285   {
1286     value = getId();
1287     return_value = LIBSBML_OPERATION_SUCCESS;
1288   }
1289   else if (attributeName == "name")
1290   {
1291     value = getName();
1292     return_value = LIBSBML_OPERATION_SUCCESS;
1293   }
1294   else if (attributeName == "dataType")
1295   {
1296     value = getDataTypeAsString();
1297     return_value = LIBSBML_OPERATION_SUCCESS;
1298   }
1299   else if (attributeName == "interpolationType")
1300   {
1301     value = getInterpolationTypeAsString();
1302     return_value = LIBSBML_OPERATION_SUCCESS;
1303   }
1304   else if (attributeName == "compression")
1305   {
1306     value = getCompressionAsString();
1307     return_value = LIBSBML_OPERATION_SUCCESS;
1308   }
1309 
1310   return return_value;
1311 }
1312 
1313 /** @endcond */
1314 
1315 
1316 
1317 /** @cond doxygenLibsbmlInternal */
1318 
1319 /*
1320  * Predicate returning @c true if this SampledField's attribute "attributeName"
1321  * is set.
1322  */
1323 bool
isSetAttribute(const std::string & attributeName) const1324 SampledField::isSetAttribute(const std::string& attributeName) const
1325 {
1326   bool value = SBase::isSetAttribute(attributeName);
1327 
1328   if (attributeName == "id")
1329   {
1330     value = isSetId();
1331   }
1332   else if (attributeName == "name")
1333   {
1334     value = isSetName();
1335   }
1336   else if (attributeName == "dataType")
1337   {
1338     value = isSetDataType();
1339   }
1340   else if (attributeName == "numSamples1")
1341   {
1342     value = isSetNumSamples1();
1343   }
1344   else if (attributeName == "numSamples2")
1345   {
1346     value = isSetNumSamples2();
1347   }
1348   else if (attributeName == "numSamples3")
1349   {
1350     value = isSetNumSamples3();
1351   }
1352   else if (attributeName == "interpolationType")
1353   {
1354     value = isSetInterpolationType();
1355   }
1356   else if (attributeName == "compression")
1357   {
1358     value = isSetCompression();
1359   }
1360   else if (attributeName == "samples")
1361   {
1362     value = isSetSamples();
1363   }
1364   else if (attributeName == "samplesLength")
1365   {
1366     value = isSetSamplesLength();
1367   }
1368 
1369   return value;
1370 }
1371 
1372 /** @endcond */
1373 
1374 
1375 
1376 /** @cond doxygenLibsbmlInternal */
1377 
1378 /*
1379  * Sets the value of the "attributeName" attribute of this SampledField.
1380  */
1381 int
setAttribute(const std::string & attributeName,bool value)1382 SampledField::setAttribute(const std::string& attributeName, bool value)
1383 {
1384   int return_value = SBase::setAttribute(attributeName, value);
1385 
1386   return return_value;
1387 }
1388 
1389 /** @endcond */
1390 
1391 
1392 
1393 /** @cond doxygenLibsbmlInternal */
1394 
1395 /*
1396  * Sets the value of the "attributeName" attribute of this SampledField.
1397  */
1398 int
setAttribute(const std::string & attributeName,int value)1399 SampledField::setAttribute(const std::string& attributeName, int value)
1400 {
1401   int return_value = SBase::setAttribute(attributeName, value);
1402 
1403   if (attributeName == "numSamples1")
1404   {
1405     return_value = setNumSamples1(value);
1406   }
1407   else if (attributeName == "numSamples2")
1408   {
1409     return_value = setNumSamples2(value);
1410   }
1411   else if (attributeName == "numSamples3")
1412   {
1413     return_value = setNumSamples3(value);
1414   }
1415   else if (attributeName == "samplesLength")
1416   {
1417     return_value = setSamplesLength(value);
1418   }
1419 
1420   return return_value;
1421 }
1422 
1423 /** @endcond */
1424 
1425 
1426 
1427 /** @cond doxygenLibsbmlInternal */
1428 
1429 /*
1430  * Sets the value of the "attributeName" attribute of this SampledField.
1431  */
1432 int
setAttribute(const std::string & attributeName,double value)1433 SampledField::setAttribute(const std::string& attributeName, double value)
1434 {
1435   int return_value = SBase::setAttribute(attributeName, value);
1436 
1437   return return_value;
1438 }
1439 
1440 /** @endcond */
1441 
1442 
1443 
1444 /** @cond doxygenLibsbmlInternal */
1445 
1446 /*
1447  * Sets the value of the "attributeName" attribute of this SampledField.
1448  */
1449 int
setAttribute(const std::string & attributeName,unsigned int value)1450 SampledField::setAttribute(const std::string& attributeName,
1451   unsigned int value)
1452 {
1453   int return_value = SBase::setAttribute(attributeName, value);
1454 
1455   return return_value;
1456 }
1457 
1458 /** @endcond */
1459 
1460 
1461 
1462 /** @cond doxygenLibsbmlInternal */
1463 
1464 /*
1465  * Sets the value of the "attributeName" attribute of this SampledField.
1466  */
1467 int
setAttribute(const std::string & attributeName,const std::string & value)1468 SampledField::setAttribute(const std::string& attributeName,
1469   const std::string& value)
1470 {
1471   int return_value = SBase::setAttribute(attributeName, value);
1472 
1473   if (attributeName == "id")
1474   {
1475     return_value = setId(value);
1476   }
1477   else if (attributeName == "name")
1478   {
1479     return_value = setName(value);
1480   }
1481   else if (attributeName == "dataType")
1482   {
1483     return_value = setDataType(value);
1484   }
1485   else if (attributeName == "interpolationType")
1486   {
1487     return_value = setInterpolationType(value);
1488   }
1489   else if (attributeName == "compression")
1490   {
1491     return_value = setCompression(value);
1492   }
1493 
1494   return return_value;
1495 }
1496 
1497 /** @endcond */
1498 
1499 
1500 
1501 /** @cond doxygenLibsbmlInternal */
1502 
1503 /*
1504  * Unsets the value of the "attributeName" attribute of this SampledField.
1505  */
1506 int
unsetAttribute(const std::string & attributeName)1507 SampledField::unsetAttribute(const std::string& attributeName)
1508 {
1509   int value = SBase::unsetAttribute(attributeName);
1510 
1511   if (attributeName == "id")
1512   {
1513     value = unsetId();
1514   }
1515   else if (attributeName == "name")
1516   {
1517     value = unsetName();
1518   }
1519   else if (attributeName == "dataType")
1520   {
1521     value = unsetDataType();
1522   }
1523   else if (attributeName == "numSamples1")
1524   {
1525     value = unsetNumSamples1();
1526   }
1527   else if (attributeName == "numSamples2")
1528   {
1529     value = unsetNumSamples2();
1530   }
1531   else if (attributeName == "numSamples3")
1532   {
1533     value = unsetNumSamples3();
1534   }
1535   else if (attributeName == "interpolationType")
1536   {
1537     value = unsetInterpolationType();
1538   }
1539   else if (attributeName == "compression")
1540   {
1541     value = unsetCompression();
1542   }
1543   else if (attributeName == "samples")
1544   {
1545     value = unsetSamples();
1546   }
1547   else if (attributeName == "samplesLength")
1548   {
1549     value = unsetSamplesLength();
1550   }
1551 
1552   return value;
1553 }
1554 
1555 /** @endcond */
1556 
1557 
1558 
1559 /** @cond doxygenLibsbmlInternal */
1560 
1561 /*
1562  * Adds the expected attributes for this element
1563  */
1564 void
addExpectedAttributes(ExpectedAttributes & attributes)1565 SampledField::addExpectedAttributes(ExpectedAttributes& attributes)
1566 {
1567   SBase::addExpectedAttributes(attributes);
1568 
1569   attributes.add("id");
1570 
1571   attributes.add("name");
1572 
1573   attributes.add("dataType");
1574 
1575   attributes.add("numSamples1");
1576 
1577   attributes.add("numSamples2");
1578 
1579   attributes.add("numSamples3");
1580 
1581   attributes.add("interpolationType");
1582 
1583   attributes.add("compression");
1584 
1585   attributes.add("samplesLength");
1586 }
1587 
1588 /** @endcond */
1589 
1590 
1591 
1592 /** @cond doxygenLibsbmlInternal */
1593 
1594 /*
1595  * Reads the expected attributes into the member data variables
1596  */
1597 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)1598 SampledField::readAttributes(const XMLAttributes& attributes,
1599   const ExpectedAttributes& expectedAttributes)
1600 {
1601   unsigned int level = getLevel();
1602   unsigned int version = getVersion();
1603   unsigned int pkgVersion = getPackageVersion();
1604   unsigned int numErrs;
1605   bool assigned = false;
1606   SBMLErrorLog* log = getErrorLog();
1607 
1608   if (log && getParentSBMLObject() &&
1609     static_cast<ListOfSampledFields*>(getParentSBMLObject())->size() < 2)
1610   {
1611     numErrs = log->getNumErrors();
1612     for (int n = numErrs - 1; n >= 0; n--)
1613     {
1614       if (log->getError(n)->getErrorId() == UnknownPackageAttribute)
1615       {
1616         const std::string details = log->getError(n)->getMessage();
1617         log->remove(UnknownPackageAttribute);
1618         log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1619           pkgVersion, level, version, details);
1620       }
1621       else if (log->getError(n)->getErrorId() == UnknownCoreAttribute)
1622       {
1623         const std::string details = log->getError(n)->getMessage();
1624         log->remove(UnknownCoreAttribute);
1625         log->logPackageError("spatial",
1626           SpatialGeometryLOSampledFieldsAllowedCoreAttributes, pkgVersion, level,
1627           version, details);
1628       }
1629     }
1630   }
1631 
1632   SBase::readAttributes(attributes, expectedAttributes);
1633 
1634   if (log)
1635   {
1636     numErrs = log->getNumErrors();
1637 
1638     for (int n = numErrs - 1; n >= 0; n--)
1639     {
1640       if (log->getError(n)->getErrorId() == UnknownPackageAttribute)
1641       {
1642         const std::string details = log->getError(n)->getMessage();
1643         log->remove(UnknownPackageAttribute);
1644         log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1645           pkgVersion, level, version, details);
1646       }
1647       else if (log->getError(n)->getErrorId() == UnknownCoreAttribute)
1648       {
1649         const std::string details = log->getError(n)->getMessage();
1650         log->remove(UnknownCoreAttribute);
1651         log->logPackageError("spatial",
1652           SpatialSampledFieldAllowedCoreAttributes, pkgVersion, level, version,
1653           details);
1654       }
1655     }
1656   }
1657 
1658   //
1659   // id SId (use = "required" )
1660   //
1661 
1662   assigned = attributes.readInto("id", mId);
1663 
1664   if (assigned == true && log)
1665   {
1666     if (mId.empty() == true)
1667     {
1668       logEmptyString(mId, level, version, "<sampledField>");
1669     }
1670     else if (SyntaxChecker::isValidSBMLSId(mId) == false)
1671     {
1672       log->logPackageError("spatial", SpatialIdSyntaxRule, pkgVersion, level,
1673         version, "The id on the <" + getElementName() + "> is '" + mId + "', "
1674         "which does not conform to the syntax.", getLine(), getColumn());
1675     }
1676   }
1677   else if (log)
1678   {
1679     std::string message = "Spatial attribute 'id' is missing from the "
1680       "<sampledField> element.";
1681     log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1682       pkgVersion, level, version, message);
1683   }
1684 
1685   //
1686   // name string (use = "optional" )
1687   //
1688 
1689   assigned = attributes.readInto("name", mName);
1690 
1691   if (assigned == true && log)
1692   {
1693     if (mName.empty() == true)
1694     {
1695       logEmptyString(mName, level, version, "<sampledField>");
1696     }
1697   }
1698 
1699   //
1700   // dataType enum (use = "required" )
1701   //
1702 
1703   std::string dataType;
1704   assigned = attributes.readInto("dataType", dataType);
1705 
1706   if (assigned == true && log)
1707   {
1708     if (dataType.empty() == true)
1709     {
1710       logEmptyString(dataType, level, version, "<sampledField>");
1711     }
1712     else
1713     {
1714       mDataType = DataKind_fromString(dataType.c_str());
1715 
1716       if (DataKind_isValid(mDataType) == 0)
1717       {
1718         std::string msg = "The dataType on the <sampledField> ";
1719 
1720         if (isSetId())
1721         {
1722           msg += "with id '" + getId() + "'";
1723         }
1724 
1725         msg += "is '" + dataType + "', which is not a valid option.";
1726 
1727         log->logPackageError("spatial",
1728           SpatialSampledFieldDataTypeMustBeDataKindEnum, pkgVersion, level,
1729           version, msg);
1730       }
1731     }
1732   }
1733   else if (log)
1734   {
1735     std::string message = "Spatial attribute 'dataType' is missing.";
1736     log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1737       pkgVersion, level, version, message);
1738   }
1739 
1740   //
1741   // numSamples1 int (use = "required" )
1742   //
1743 
1744   numErrs = log == NULL ? 0 : log->getNumErrors();
1745   mIsSetNumSamples1 = attributes.readInto("numSamples1", mNumSamples1);
1746 
1747   if (mIsSetNumSamples1 == false && log)
1748   {
1749     if (log->getNumErrors() == numErrs + 1 &&
1750       log->contains(XMLAttributeTypeMismatch))
1751     {
1752       log->remove(XMLAttributeTypeMismatch);
1753       std::string message = "Spatial attribute 'numSamples1' from the "
1754         "<sampledField> element must be an integer.";
1755       log->logPackageError("spatial",
1756         SpatialSampledFieldNumSamples1MustBeInteger, pkgVersion, level, version,
1757         message);
1758     }
1759     else
1760     {
1761       std::string message = "Spatial attribute 'numSamples1' is missing from "
1762         "the <SampledField> element.";
1763       log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1764         pkgVersion, level, version, message);
1765     }
1766   }
1767 
1768   //
1769   // numSamples2 int (use = "optional" )
1770   //
1771 
1772   numErrs = log == NULL ? 0 : log->getNumErrors();
1773   mIsSetNumSamples2 = attributes.readInto("numSamples2", mNumSamples2);
1774 
1775   if (mIsSetNumSamples2 == false && log)
1776   {
1777     if (log->getNumErrors() == numErrs + 1 &&
1778       log->contains(XMLAttributeTypeMismatch))
1779     {
1780       log->remove(XMLAttributeTypeMismatch);
1781       std::string message = "Spatial attribute 'numSamples2' from the "
1782         "<sampledField> element must be an integer.";
1783       log->logPackageError("spatial",
1784         SpatialSampledFieldNumSamples2MustBeInteger, pkgVersion, level, version,
1785         message);
1786     }
1787   }
1788 
1789   //
1790   // numSamples3 int (use = "optional" )
1791   //
1792 
1793   numErrs = log == NULL ? 0 : log->getNumErrors();
1794   mIsSetNumSamples3 = attributes.readInto("numSamples3", mNumSamples3);
1795 
1796   if (mIsSetNumSamples3 == false && log)
1797   {
1798     if (log->getNumErrors() == numErrs + 1 &&
1799       log->contains(XMLAttributeTypeMismatch))
1800     {
1801       log->remove(XMLAttributeTypeMismatch);
1802       std::string message = "Spatial attribute 'numSamples3' from the "
1803         "<sampledField> element must be an integer.";
1804       log->logPackageError("spatial",
1805         SpatialSampledFieldNumSamples3MustBeInteger, pkgVersion, level, version,
1806         message);
1807     }
1808   }
1809 
1810   //
1811   // interpolationType enum (use = "required" )
1812   //
1813 
1814   std::string interpolationType;
1815   assigned = attributes.readInto("interpolationType", interpolationType);
1816 
1817   if (assigned == true && log)
1818   {
1819     if (interpolationType.empty() == true)
1820     {
1821       logEmptyString(interpolationType, level, version, "<sampledField>");
1822     }
1823     else
1824     {
1825       mInterpolationType =
1826         InterpolationKind_fromString(interpolationType.c_str());
1827 
1828       if (InterpolationKind_isValid(mInterpolationType) == 0)
1829       {
1830         std::string msg = "The interpolationType on the <SampledField> ";
1831 
1832         if (isSetId())
1833         {
1834           msg += "with id '" + getId() + "'";
1835         }
1836 
1837         msg += "is '" + interpolationType + "', which is not a valid option.";
1838 
1839         log->logPackageError("spatial",
1840           SpatialSampledFieldInterpolationTypeMustBeInterpolationKindEnum,
1841           pkgVersion, level, version, msg);
1842       }
1843     }
1844   }
1845   else if (log)
1846   {
1847     std::string message = "Spatial attribute 'interpolationType' is missing.";
1848     log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1849       pkgVersion, level, version, message);
1850   }
1851 
1852   //
1853   // compression enum (use = "required" )
1854   //
1855 
1856   std::string compression;
1857   assigned = attributes.readInto("compression", compression);
1858 
1859   if (assigned == true && log)
1860   {
1861     if (compression.empty() == true)
1862     {
1863       logEmptyString(compression, level, version, "<sampledField>");
1864     }
1865     else
1866     {
1867       mCompression = CompressionKind_fromString(compression.c_str());
1868 
1869       if (CompressionKind_isValid(mCompression) == 0)
1870       {
1871         std::string msg = "The compression on the <SampledField> ";
1872 
1873         if (isSetId())
1874         {
1875           msg += "with id '" + getId() + "'";
1876         }
1877 
1878         msg += "is '" + compression + "', which is not a valid option.";
1879 
1880         log->logPackageError("spatial",
1881           SpatialSampledFieldCompressionMustBeCompressionKindEnum, pkgVersion,
1882           level, version, msg);
1883       }
1884     }
1885   }
1886   else if (log)
1887   {
1888     std::string message = "Spatial attribute 'compression' is missing.";
1889     log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1890       pkgVersion, level, version, message);
1891   }
1892 
1893   //
1894   // samplesLength int (use = "required" )
1895   //
1896 
1897   numErrs = log == NULL ? 0 : log->getNumErrors();
1898   mIsSetSamplesLength = attributes.readInto("samplesLength", mSamplesLength);
1899 
1900   if (mIsSetSamplesLength == false && log)
1901   {
1902     if (log->getNumErrors() == numErrs + 1 &&
1903       log->contains(XMLAttributeTypeMismatch))
1904     {
1905       log->remove(XMLAttributeTypeMismatch);
1906       std::string message = "Spatial attribute 'samplesLength' from the "
1907         "<sampledField> element must be an integer.";
1908       log->logPackageError("spatial",
1909         SpatialSampledFieldSamplesLengthMustBeInteger, pkgVersion, level,
1910         version, message);
1911     }
1912     else
1913     {
1914       std::string message = "Spatial attribute 'samplesLength' is missing from "
1915         "the <SampledField> element.";
1916       log->logPackageError("spatial", SpatialSampledFieldAllowedAttributes,
1917         pkgVersion, level, version, message);
1918     }
1919   }
1920 }
1921 
1922 /** @endcond */
1923 
1924 
1925 
1926 /** @cond doxygenLibsbmlInternal */
1927 
1928 /*
1929  * Writes the attributes to the stream
1930  */
1931 void
writeAttributes(XMLOutputStream & stream) const1932 SampledField::writeAttributes(XMLOutputStream& stream) const
1933 {
1934   SBase::writeAttributes(stream);
1935 
1936   if (isSetId() == true)
1937   {
1938     stream.writeAttribute("id", getPrefix(), mId);
1939   }
1940 
1941   if (isSetName() == true)
1942   {
1943     stream.writeAttribute("name", getPrefix(), mName);
1944   }
1945 
1946   if (isSetDataType() == true)
1947   {
1948     stream.writeAttribute("dataType", getPrefix(),
1949       DataKind_toString(mDataType));
1950   }
1951 
1952   if (isSetNumSamples1() == true)
1953   {
1954     stream.writeAttribute("numSamples1", getPrefix(), mNumSamples1);
1955   }
1956 
1957   if (isSetNumSamples2() == true)
1958   {
1959     stream.writeAttribute("numSamples2", getPrefix(), mNumSamples2);
1960   }
1961 
1962   if (isSetNumSamples3() == true)
1963   {
1964     stream.writeAttribute("numSamples3", getPrefix(), mNumSamples3);
1965   }
1966 
1967   if (isSetInterpolationType() == true)
1968   {
1969     stream.writeAttribute("interpolationType", getPrefix(),
1970       InterpolationKind_toString(mInterpolationType));
1971   }
1972 
1973   if (isSetCompression() == true)
1974   {
1975     stream.writeAttribute("compression", getPrefix(),
1976       CompressionKind_toString(mCompression));
1977   }
1978 
1979   if (isSetSamplesLength() == true)
1980   {
1981     stream.writeAttribute("samplesLength", getPrefix(), mSamplesLength);
1982   }
1983 
1984   SBase::writeExtensionAttributes(stream);
1985 }
1986 
1987 /** @endcond */
1988 
1989 
1990 
1991 /** @cond doxygenLibsbmlInternal */
1992 
1993 /*
1994 * Writes the array data as a text element
1995 */
1996 void
setElementText(const std::string & text)1997 SampledField::setElementText(const std::string& text)
1998 {
1999   mSamples = text;
2000   SBMLErrorLog* log = getErrorLog();
2001   if (log)
2002   {
2003     if (mCompression == SPATIAL_COMPRESSIONKIND_UNCOMPRESSED)
2004     {
2005       stringstream strStream(text);
2006       double val;
2007 
2008       while (strStream >> val)
2009       {
2010         if (strStream.peek() == ',') {
2011           strStream.get();
2012         }
2013         if (strStream.peek() == ';') {
2014           strStream.get();
2015         }
2016       }
2017       if (strStream.fail() && !strStream.eof())
2018       {
2019         stringstream ss_msg;
2020         ss_msg << "A <SampledField>";
2021         if (isSetId())
2022         {
2023           ss_msg << " with id '" << getId() << "'";
2024         }
2025         ss_msg << " has a compression type of 'uncompressed', but contains non-numeric elements.";
2026 
2027         log->logPackageError("spatial",
2028           SpatialSampledFieldSamplesMustBeNumeric,
2029           getPackageVersion(), getLevel(), getVersion(), ss_msg.str());
2030       }
2031     }
2032     else if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
2033     {
2034       size_t doubleslen;
2035       double ival;
2036       double* doublesVector = readSamplesFromString<double>(mSamples, doubleslen);
2037       for (size_t i = 0; i < doubleslen; i++)
2038       {
2039         if (modf(doublesVector[i], &ival) != 0) //Maybe also check to make sure it's in the -128 to 127 range?
2040         {
2041           stringstream ss_msg;
2042           ss_msg << "A <SampledField>";
2043           if (isSetId())
2044           {
2045             ss_msg << " with id '" << getId() << "'";
2046           }
2047           ss_msg << " has a compression type of 'deflated', but has an entry with the value '" << doublesVector[i];
2048           ss_msg << "', which is not an integer.";
2049 
2050           log->logPackageError("spatial",
2051             SpatialSampledFieldCompressedSamplesMustBeInts,
2052             getPackageVersion(), getLevel(), getVersion(), ss_msg.str());
2053         }
2054       }
2055       free(doublesVector);
2056     }
2057   }
2058 }
2059 
store() const2060 void SampledField::store() const
2061 {
2062   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
2063   {
2064     if (mSamplesCompressed == NULL) {
2065       mSamplesCompressed = readSamplesFromString<int>(mSamples, mSamplesCompressedLength);
2066     }
2067   }
2068   else
2069   {
2070     if (mSamplesUncompressed == NULL) {
2071       mSamplesUncompressed = readSamplesFromString<double>(mSamples, mSamplesUncompressedLength);
2072       size_t alt_length;
2073       free(mSamplesUncompressedInt);
2074       mSamplesUncompressedInt = readSamplesFromString<int>(mSamples, alt_length);
2075       if (alt_length != mSamplesUncompressedLength)
2076       {
2077         free(mSamplesUncompressedInt);
2078         mSamplesUncompressedInt = NULL;
2079       }
2080     }
2081   }
2082 }
2083 
uncompressInternal(string & sampleString,size_t & length) const2084 void SampledField::uncompressInternal(string& sampleString, size_t& length) const
2085 {
2086   freeUncompressed();
2087   store();
2088 
2089   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
2090   {
2091     if (mSamplesCompressed == NULL)
2092     {
2093       sampleString = "";
2094       length = 0;
2095       return;
2096     }
2097     char* csamples = (char*)malloc(sizeof(char) * mSamplesCompressedLength);
2098     int* result;
2099     for (unsigned int i = 0; i < mSamplesCompressedLength; ++i)
2100     {
2101       csamples[i] = (char)mSamplesCompressed[i];
2102     }
2103     uncompress_data(csamples, mSamplesCompressedLength, result, length);
2104     free(csamples);
2105 
2106     if (result == NULL)
2107     {
2108       sampleString = "";
2109       length = 0;
2110       return;
2111     }
2112 
2113     sampleString = charIntsToString(result, length);
2114     free(result);
2115     return;
2116   }
2117   else
2118   {
2119     sampleString = mSamples;
2120     length = mSamplesUncompressedLength;
2121   }
2122 }
2123 
2124 /**
2125 *  Returns the data of this image as uncompressed array of integers
2126 *
2127 * @param data the output array of integers (it will be allocated using
2128 *             malloc and will have to be freed using free)
2129 * @param length the output length of the array
2130 *
2131 */
2132 void
getUncompressedData(double * & data,size_t & length)2133 SampledField::getUncompressedData(double*& data, size_t& length)
2134 {
2135   store();
2136   length = getUncompressedLength();
2137   if (length == 0)
2138   {
2139     return;
2140   }
2141   copySampleArrays(data, length, mSamplesUncompressed, mSamplesUncompressedLength);
2142   return;
2143 }
2144 
2145 int
uncompress()2146 SampledField::uncompress()
2147 {
2148   if (mCompression == SPATIAL_COMPRESSIONKIND_DEFLATED)
2149   {
2150     uncompressInternal(mSamples, mSamplesUncompressedLength);
2151     mCompression = SPATIAL_COMPRESSIONKIND_UNCOMPRESSED;
2152     store();
2153     setSamplesLength(mSamplesUncompressedLength);
2154   }
2155 
2156   return setCompression(SPATIAL_COMPRESSIONKIND_UNCOMPRESSED);
2157 }
2158 
compress(int level)2159 int SampledField::compress(int level)
2160 {
2161   freeCompressed();
2162   unsigned char* result; int length;
2163   int ret = compress_data(const_cast<char*>(mSamples.c_str()), mSamples.length(), level, result, length);
2164 
2165   if (ret == LIBSBML_OPERATION_SUCCESS)
2166   {
2167       mSamples = arrayToString(result, length);
2168       copySampleArrays(mSamplesCompressed, mSamplesCompressedLength, result, length);
2169 
2170       free(result);
2171 
2172       setSamplesLength(mSamplesCompressedLength);
2173       return setCompression(SPATIAL_COMPRESSIONKIND_DEFLATED);
2174   }
2175   return ret;
2176 }
2177 
2178 unsigned int
getUncompressedLength() const2179 SampledField::getUncompressedLength() const
2180 {
2181   store();
2182   if (mSamplesUncompressed == NULL) {
2183     string uncompressedString;
2184     uncompressInternal(uncompressedString, mSamplesUncompressedLength);
2185     mSamplesUncompressed = readSamplesFromString<double>(uncompressedString, mSamplesUncompressedLength);
2186   }
2187   return mSamplesUncompressedLength;
2188 }
2189 
2190 void
getUncompressed(double * outputPoints) const2191 SampledField::getUncompressed(double* outputPoints) const
2192 {
2193   store();
2194   if (outputPoints == NULL) return;
2195   if (mSamplesUncompressed == NULL) {
2196     string uncompressedString;
2197     uncompressInternal(uncompressedString, mSamplesUncompressedLength);
2198     mSamplesUncompressed = readSamplesFromString<double>(uncompressedString, mSamplesUncompressedLength);
2199   }
2200   if (mSamplesUncompressed == NULL) return;
2201   memcpy(outputPoints, mSamplesUncompressed, sizeof(double) * mSamplesUncompressedLength);
2202 }
2203 
2204 void
freeUncompressed() const2205 SampledField::freeUncompressed() const
2206 {
2207   free(mSamplesUncompressedInt);
2208   mSamplesUncompressedInt = NULL;
2209   if (mSamplesUncompressed != NULL)
2210   {
2211     free(mSamplesUncompressed);
2212   }
2213   mSamplesUncompressed = NULL;
2214   mSamplesUncompressedLength = 0;
2215 }
2216 
2217 void
freeCompressed() const2218 SampledField::freeCompressed() const
2219 {
2220   if (mSamplesCompressed != NULL)
2221   {
2222     free(mSamplesCompressed);
2223   }
2224   mSamplesCompressed = NULL;
2225   mSamplesCompressedLength = 0;
2226 }
2227 
2228 
2229 
2230 #endif /* __cplusplus */
2231 
2232 
2233 /*
2234  * Creates a new SampledField_t using the given SBML Level, Version and
2235  * &ldquo;spatial&rdquo; package version.
2236  */
2237 LIBSBML_EXTERN
2238 SampledField_t*
SampledField_create(unsigned int level,unsigned int version,unsigned int pkgVersion)2239 SampledField_create(unsigned int level,
2240   unsigned int version,
2241   unsigned int pkgVersion)
2242 {
2243   return new SampledField(level, version, pkgVersion);
2244 }
2245 
2246 
2247 /*
2248  * Creates and returns a deep copy of this SampledField_t object.
2249  */
2250 LIBSBML_EXTERN
2251 SampledField_t*
SampledField_clone(const SampledField_t * sf)2252 SampledField_clone(const SampledField_t* sf)
2253 {
2254   if (sf != NULL)
2255   {
2256     return static_cast<SampledField_t*>(sf->clone());
2257   }
2258   else
2259   {
2260     return NULL;
2261   }
2262 }
2263 
2264 
2265 /*
2266  * Frees this SampledField_t object.
2267  */
2268 LIBSBML_EXTERN
2269 void
SampledField_free(SampledField_t * sf)2270 SampledField_free(SampledField_t* sf)
2271 {
2272   if (sf != NULL)
2273   {
2274     delete sf;
2275   }
2276 }
2277 
2278 
2279 /*
2280  * Returns the value of the "id" attribute of this SampledField_t.
2281  */
2282 LIBSBML_EXTERN
2283 char*
SampledField_getId(const SampledField_t * sf)2284 SampledField_getId(const SampledField_t* sf)
2285 {
2286   if (sf == NULL)
2287   {
2288     return NULL;
2289   }
2290 
2291   return sf->getId().empty() ? NULL : safe_strdup(sf->getId().c_str());
2292 }
2293 
2294 
2295 /*
2296  * Returns the value of the "name" attribute of this SampledField_t.
2297  */
2298 LIBSBML_EXTERN
2299 char*
SampledField_getName(const SampledField_t * sf)2300 SampledField_getName(const SampledField_t* sf)
2301 {
2302   if (sf == NULL)
2303   {
2304     return NULL;
2305   }
2306 
2307   return sf->getName().empty() ? NULL : safe_strdup(sf->getName().c_str());
2308 }
2309 
2310 
2311 /*
2312  * Returns the value of the "dataType" attribute of this SampledField_t.
2313  */
2314 LIBSBML_EXTERN
2315 DataKind_t
SampledField_getDataType(const SampledField_t * sf)2316 SampledField_getDataType(const SampledField_t* sf)
2317 {
2318   if (sf == NULL)
2319   {
2320     return SPATIAL_DATAKIND_INVALID;
2321   }
2322 
2323   return sf->getDataType();
2324 }
2325 
2326 
2327 /*
2328  * Returns the value of the "dataType" attribute of this SampledField_t.
2329  */
2330 LIBSBML_EXTERN
2331 char*
SampledField_getDataTypeAsString(const SampledField_t * sf)2332 SampledField_getDataTypeAsString(const SampledField_t* sf)
2333 {
2334   return (char*)(DataKind_toString(sf->getDataType()));
2335 }
2336 
2337 
2338 /*
2339  * Returns the value of the "numSamples1" attribute of this SampledField_t.
2340  */
2341 LIBSBML_EXTERN
2342 int
SampledField_getNumSamples1(const SampledField_t * sf)2343 SampledField_getNumSamples1(const SampledField_t* sf)
2344 {
2345   return (sf != NULL) ? sf->getNumSamples1() : SBML_INT_MAX;
2346 }
2347 
2348 
2349 /*
2350  * Returns the value of the "numSamples2" attribute of this SampledField_t.
2351  */
2352 LIBSBML_EXTERN
2353 int
SampledField_getNumSamples2(const SampledField_t * sf)2354 SampledField_getNumSamples2(const SampledField_t* sf)
2355 {
2356   return (sf != NULL) ? sf->getNumSamples2() : SBML_INT_MAX;
2357 }
2358 
2359 
2360 /*
2361  * Returns the value of the "numSamples3" attribute of this SampledField_t.
2362  */
2363 LIBSBML_EXTERN
2364 int
SampledField_getNumSamples3(const SampledField_t * sf)2365 SampledField_getNumSamples3(const SampledField_t* sf)
2366 {
2367   return (sf != NULL) ? sf->getNumSamples3() : SBML_INT_MAX;
2368 }
2369 
2370 
2371 /*
2372  * Returns the value of the "interpolationType" attribute of this
2373  * SampledField_t.
2374  */
2375 LIBSBML_EXTERN
2376 InterpolationKind_t
SampledField_getInterpolationType(const SampledField_t * sf)2377 SampledField_getInterpolationType(const SampledField_t* sf)
2378 {
2379   if (sf == NULL)
2380   {
2381     return SPATIAL_INTERPOLATIONKIND_INVALID;
2382   }
2383 
2384   return sf->getInterpolationType();
2385 }
2386 
2387 
2388 /*
2389  * Returns the value of the "interpolationType" attribute of this
2390  * SampledField_t.
2391  */
2392 LIBSBML_EXTERN
2393 char*
SampledField_getInterpolationTypeAsString(const SampledField_t * sf)2394 SampledField_getInterpolationTypeAsString(const SampledField_t* sf)
2395 {
2396   return (char*)(InterpolationKind_toString(sf->getInterpolationType()));
2397 }
2398 
2399 
2400 /*
2401  * Returns the value of the "compression" attribute of this SampledField_t.
2402  */
2403 LIBSBML_EXTERN
2404 CompressionKind_t
SampledField_getCompression(const SampledField_t * sf)2405 SampledField_getCompression(const SampledField_t* sf)
2406 {
2407   if (sf == NULL)
2408   {
2409     return SPATIAL_COMPRESSIONKIND_INVALID;
2410   }
2411 
2412   return sf->getCompression();
2413 }
2414 
2415 
2416 /*
2417  * Returns the value of the "compression" attribute of this SampledField_t.
2418  */
2419 LIBSBML_EXTERN
2420 char*
SampledField_getCompressionAsString(const SampledField_t * sf)2421 SampledField_getCompressionAsString(const SampledField_t* sf)
2422 {
2423   return (char*)(CompressionKind_toString(sf->getCompression()));
2424 }
2425 
2426 
2427 /*
2428  * Returns the value of the "samplesLength" attribute of this SampledField_t.
2429  */
2430 LIBSBML_EXTERN
2431 int
SampledField_getSamplesLength(const SampledField_t * sf)2432 SampledField_getSamplesLength(const SampledField_t* sf)
2433 {
2434   return (sf != NULL) ? sf->getSamplesLength() : SBML_INT_MAX;
2435 }
2436 
2437 
2438 /*
2439  * Predicate returning @c 1 (true) if this SampledField_t's "id" attribute is
2440  * set.
2441  */
2442 LIBSBML_EXTERN
2443 int
SampledField_isSetId(const SampledField_t * sf)2444 SampledField_isSetId(const SampledField_t* sf)
2445 {
2446   return (sf != NULL) ? static_cast<int>(sf->isSetId()) : 0;
2447 }
2448 
2449 
2450 /*
2451  * Predicate returning @c 1 (true) if this SampledField_t's "name" attribute is
2452  * set.
2453  */
2454 LIBSBML_EXTERN
2455 int
SampledField_isSetName(const SampledField_t * sf)2456 SampledField_isSetName(const SampledField_t* sf)
2457 {
2458   return (sf != NULL) ? static_cast<int>(sf->isSetName()) : 0;
2459 }
2460 
2461 
2462 /*
2463  * Predicate returning @c 1 (true) if this SampledField_t's "dataType"
2464  * attribute is set.
2465  */
2466 LIBSBML_EXTERN
2467 int
SampledField_isSetDataType(const SampledField_t * sf)2468 SampledField_isSetDataType(const SampledField_t* sf)
2469 {
2470   return (sf != NULL) ? static_cast<int>(sf->isSetDataType()) : 0;
2471 }
2472 
2473 
2474 /*
2475  * Predicate returning @c 1 (true) if this SampledField_t's "numSamples1"
2476  * attribute is set.
2477  */
2478 LIBSBML_EXTERN
2479 int
SampledField_isSetNumSamples1(const SampledField_t * sf)2480 SampledField_isSetNumSamples1(const SampledField_t* sf)
2481 {
2482   return (sf != NULL) ? static_cast<int>(sf->isSetNumSamples1()) : 0;
2483 }
2484 
2485 
2486 /*
2487  * Predicate returning @c 1 (true) if this SampledField_t's "numSamples2"
2488  * attribute is set.
2489  */
2490 LIBSBML_EXTERN
2491 int
SampledField_isSetNumSamples2(const SampledField_t * sf)2492 SampledField_isSetNumSamples2(const SampledField_t* sf)
2493 {
2494   return (sf != NULL) ? static_cast<int>(sf->isSetNumSamples2()) : 0;
2495 }
2496 
2497 
2498 /*
2499  * Predicate returning @c 1 (true) if this SampledField_t's "numSamples3"
2500  * attribute is set.
2501  */
2502 LIBSBML_EXTERN
2503 int
SampledField_isSetNumSamples3(const SampledField_t * sf)2504 SampledField_isSetNumSamples3(const SampledField_t* sf)
2505 {
2506   return (sf != NULL) ? static_cast<int>(sf->isSetNumSamples3()) : 0;
2507 }
2508 
2509 
2510 /*
2511  * Predicate returning @c 1 (true) if this SampledField_t's "interpolationType"
2512  * attribute is set.
2513  */
2514 LIBSBML_EXTERN
2515 int
SampledField_isSetInterpolationType(const SampledField_t * sf)2516 SampledField_isSetInterpolationType(const SampledField_t* sf)
2517 {
2518   return (sf != NULL) ? static_cast<int>(sf->isSetInterpolationType()) : 0;
2519 }
2520 
2521 
2522 /*
2523  * Predicate returning @c 1 (true) if this SampledField_t's "compression"
2524  * attribute is set.
2525  */
2526 LIBSBML_EXTERN
2527 int
SampledField_isSetCompression(const SampledField_t * sf)2528 SampledField_isSetCompression(const SampledField_t* sf)
2529 {
2530   return (sf != NULL) ? static_cast<int>(sf->isSetCompression()) : 0;
2531 }
2532 
2533 
2534 /*
2535  * Predicate returning @c 1 (true) if this SampledField_t's "samples" attribute
2536  * is set.
2537  */
2538 LIBSBML_EXTERN
2539 int
SampledField_isSetSamples(const SampledField_t * sf)2540 SampledField_isSetSamples(const SampledField_t* sf)
2541 {
2542   return (sf != NULL) ? static_cast<int>(sf->isSetSamples()) : 0;
2543 }
2544 
2545 
2546 /*
2547  * Predicate returning @c 1 (true) if this SampledField_t's "samplesLength"
2548  * attribute is set.
2549  */
2550 LIBSBML_EXTERN
2551 int
SampledField_isSetSamplesLength(const SampledField_t * sf)2552 SampledField_isSetSamplesLength(const SampledField_t* sf)
2553 {
2554   return (sf != NULL) ? static_cast<int>(sf->isSetSamplesLength()) : 0;
2555 }
2556 
2557 
2558 /*
2559  * Sets the value of the "id" attribute of this SampledField_t.
2560  */
2561 LIBSBML_EXTERN
2562 int
SampledField_setId(SampledField_t * sf,const char * id)2563 SampledField_setId(SampledField_t* sf, const char* id)
2564 {
2565   return (sf != NULL) ? sf->setId(id) : LIBSBML_INVALID_OBJECT;
2566 }
2567 
2568 
2569 /*
2570  * Sets the value of the "name" attribute of this SampledField_t.
2571  */
2572 LIBSBML_EXTERN
2573 int
SampledField_setName(SampledField_t * sf,const char * name)2574 SampledField_setName(SampledField_t* sf, const char* name)
2575 {
2576   return (sf != NULL) ? sf->setName(name) : LIBSBML_INVALID_OBJECT;
2577 }
2578 
2579 
2580 /*
2581  * Sets the value of the "dataType" attribute of this SampledField_t.
2582  */
2583 LIBSBML_EXTERN
2584 int
SampledField_setDataType(SampledField_t * sf,DataKind_t dataType)2585 SampledField_setDataType(SampledField_t* sf, DataKind_t dataType)
2586 {
2587   return (sf != NULL) ? sf->setDataType(dataType) : LIBSBML_INVALID_OBJECT;
2588 }
2589 
2590 
2591 /*
2592  * Sets the value of the "dataType" attribute of this SampledField_t.
2593  */
2594 LIBSBML_EXTERN
2595 int
SampledField_setDataTypeAsString(SampledField_t * sf,const char * dataType)2596 SampledField_setDataTypeAsString(SampledField_t* sf, const char* dataType)
2597 {
2598   return (sf != NULL) ? sf->setDataType(dataType) : LIBSBML_INVALID_OBJECT;
2599 }
2600 
2601 
2602 /*
2603  * Sets the value of the "numSamples1" attribute of this SampledField_t.
2604  */
2605 LIBSBML_EXTERN
2606 int
SampledField_setNumSamples1(SampledField_t * sf,int numSamples1)2607 SampledField_setNumSamples1(SampledField_t* sf, int numSamples1)
2608 {
2609   return (sf != NULL) ? sf->setNumSamples1(numSamples1) :
2610     LIBSBML_INVALID_OBJECT;
2611 }
2612 
2613 
2614 /*
2615  * Sets the value of the "numSamples2" attribute of this SampledField_t.
2616  */
2617 LIBSBML_EXTERN
2618 int
SampledField_setNumSamples2(SampledField_t * sf,int numSamples2)2619 SampledField_setNumSamples2(SampledField_t* sf, int numSamples2)
2620 {
2621   return (sf != NULL) ? sf->setNumSamples2(numSamples2) :
2622     LIBSBML_INVALID_OBJECT;
2623 }
2624 
2625 
2626 /*
2627  * Sets the value of the "numSamples3" attribute of this SampledField_t.
2628  */
2629 LIBSBML_EXTERN
2630 int
SampledField_setNumSamples3(SampledField_t * sf,int numSamples3)2631 SampledField_setNumSamples3(SampledField_t* sf, int numSamples3)
2632 {
2633   return (sf != NULL) ? sf->setNumSamples3(numSamples3) :
2634     LIBSBML_INVALID_OBJECT;
2635 }
2636 
2637 
2638 /*
2639  * Sets the value of the "interpolationType" attribute of this SampledField_t.
2640  */
2641 LIBSBML_EXTERN
2642 int
SampledField_setInterpolationType(SampledField_t * sf,InterpolationKind_t interpolationType)2643 SampledField_setInterpolationType(SampledField_t* sf,
2644   InterpolationKind_t interpolationType)
2645 {
2646   return (sf != NULL) ? sf->setInterpolationType(interpolationType) :
2647     LIBSBML_INVALID_OBJECT;
2648 }
2649 
2650 
2651 /*
2652  * Sets the value of the "interpolationType" attribute of this SampledField_t.
2653  */
2654 LIBSBML_EXTERN
2655 int
SampledField_setInterpolationTypeAsString(SampledField_t * sf,const char * interpolationType)2656 SampledField_setInterpolationTypeAsString(SampledField_t* sf,
2657   const char* interpolationType)
2658 {
2659   return (sf != NULL) ? sf->setInterpolationType(interpolationType) :
2660     LIBSBML_INVALID_OBJECT;
2661 }
2662 
2663 
2664 /*
2665  * Sets the value of the "compression" attribute of this SampledField_t.
2666  */
2667 LIBSBML_EXTERN
2668 int
SampledField_setCompression(SampledField_t * sf,CompressionKind_t compression)2669 SampledField_setCompression(SampledField_t* sf,
2670   CompressionKind_t compression)
2671 {
2672   return (sf != NULL) ? sf->setCompression(compression) :
2673     LIBSBML_INVALID_OBJECT;
2674 }
2675 
2676 
2677 /*
2678  * Sets the value of the "compression" attribute of this SampledField_t.
2679  */
2680 LIBSBML_EXTERN
2681 int
SampledField_setCompressionAsString(SampledField_t * sf,const char * compression)2682 SampledField_setCompressionAsString(SampledField_t* sf,
2683   const char* compression)
2684 {
2685   return (sf != NULL) ? sf->setCompression(compression) :
2686     LIBSBML_INVALID_OBJECT;
2687 }
2688 
2689 
2690 /*
2691  * Sets the value of the "samples" attribute of this SampledField_t.
2692  */
2693 LIBSBML_EXTERN
2694 int
SampledField_setSamples(SampledField_t * sf,int * samples,size_t arrayLength)2695 SampledField_setSamples(SampledField_t* sf, int* samples, size_t arrayLength)
2696 {
2697   return (sf != NULL) ? sf->setSamples(samples, arrayLength) :
2698     LIBSBML_INVALID_OBJECT;
2699 }
2700 
2701 
2702 /*
2703  * Sets the value of the "samplesLength" attribute of this SampledField_t.
2704  */
2705 LIBSBML_EXTERN
2706 int
SampledField_setSamplesLength(SampledField_t * sf,int samplesLength)2707 SampledField_setSamplesLength(SampledField_t* sf, int samplesLength)
2708 {
2709   return (sf != NULL) ? sf->setSamplesLength(samplesLength) :
2710     LIBSBML_INVALID_OBJECT;
2711 }
2712 
2713 
2714 /*
2715  * Unsets the value of the "id" attribute of this SampledField_t.
2716  */
2717 LIBSBML_EXTERN
2718 int
SampledField_unsetId(SampledField_t * sf)2719 SampledField_unsetId(SampledField_t* sf)
2720 {
2721   return (sf != NULL) ? sf->unsetId() : LIBSBML_INVALID_OBJECT;
2722 }
2723 
2724 
2725 /*
2726  * Unsets the value of the "name" attribute of this SampledField_t.
2727  */
2728 LIBSBML_EXTERN
2729 int
SampledField_unsetName(SampledField_t * sf)2730 SampledField_unsetName(SampledField_t* sf)
2731 {
2732   return (sf != NULL) ? sf->unsetName() : LIBSBML_INVALID_OBJECT;
2733 }
2734 
2735 
2736 /*
2737  * Unsets the value of the "dataType" attribute of this SampledField_t.
2738  */
2739 LIBSBML_EXTERN
2740 int
SampledField_unsetDataType(SampledField_t * sf)2741 SampledField_unsetDataType(SampledField_t* sf)
2742 {
2743   return (sf != NULL) ? sf->unsetDataType() : LIBSBML_INVALID_OBJECT;
2744 }
2745 
2746 
2747 /*
2748  * Unsets the value of the "numSamples1" attribute of this SampledField_t.
2749  */
2750 LIBSBML_EXTERN
2751 int
SampledField_unsetNumSamples1(SampledField_t * sf)2752 SampledField_unsetNumSamples1(SampledField_t* sf)
2753 {
2754   return (sf != NULL) ? sf->unsetNumSamples1() : LIBSBML_INVALID_OBJECT;
2755 }
2756 
2757 
2758 /*
2759  * Unsets the value of the "numSamples2" attribute of this SampledField_t.
2760  */
2761 LIBSBML_EXTERN
2762 int
SampledField_unsetNumSamples2(SampledField_t * sf)2763 SampledField_unsetNumSamples2(SampledField_t* sf)
2764 {
2765   return (sf != NULL) ? sf->unsetNumSamples2() : LIBSBML_INVALID_OBJECT;
2766 }
2767 
2768 
2769 /*
2770  * Unsets the value of the "numSamples3" attribute of this SampledField_t.
2771  */
2772 LIBSBML_EXTERN
2773 int
SampledField_unsetNumSamples3(SampledField_t * sf)2774 SampledField_unsetNumSamples3(SampledField_t* sf)
2775 {
2776   return (sf != NULL) ? sf->unsetNumSamples3() : LIBSBML_INVALID_OBJECT;
2777 }
2778 
2779 
2780 /*
2781  * Unsets the value of the "interpolationType" attribute of this
2782  * SampledField_t.
2783  */
2784 LIBSBML_EXTERN
2785 int
SampledField_unsetInterpolationType(SampledField_t * sf)2786 SampledField_unsetInterpolationType(SampledField_t* sf)
2787 {
2788   return (sf != NULL) ? sf->unsetInterpolationType() : LIBSBML_INVALID_OBJECT;
2789 }
2790 
2791 
2792 /*
2793  * Unsets the value of the "compression" attribute of this SampledField_t.
2794  */
2795 LIBSBML_EXTERN
2796 int
SampledField_unsetCompression(SampledField_t * sf)2797 SampledField_unsetCompression(SampledField_t* sf)
2798 {
2799   return (sf != NULL) ? sf->unsetCompression() : LIBSBML_INVALID_OBJECT;
2800 }
2801 
2802 
2803 /*
2804  * Unsets the value of the "samples" attribute of this SampledField_t.
2805  */
2806 LIBSBML_EXTERN
2807 int
SampledField_unsetSamples(SampledField_t * sf)2808 SampledField_unsetSamples(SampledField_t* sf)
2809 {
2810   return (sf != NULL) ? sf->unsetSamples() : LIBSBML_INVALID_OBJECT;
2811 }
2812 
2813 
2814 /*
2815  * Unsets the value of the "samplesLength" attribute of this SampledField_t.
2816  */
2817 LIBSBML_EXTERN
2818 int
SampledField_unsetSamplesLength(SampledField_t * sf)2819 SampledField_unsetSamplesLength(SampledField_t* sf)
2820 {
2821   return (sf != NULL) ? sf->unsetSamplesLength() : LIBSBML_INVALID_OBJECT;
2822 }
2823 
2824 
2825 /*
2826  * Predicate returning @c 1 (true) if all the required attributes for this
2827  * SampledField_t object have been set.
2828  */
2829 LIBSBML_EXTERN
2830 int
SampledField_hasRequiredAttributes(const SampledField_t * sf)2831 SampledField_hasRequiredAttributes(const SampledField_t* sf)
2832 {
2833   return (sf != NULL) ? static_cast<int>(sf->hasRequiredAttributes()) : 0;
2834 }
2835 
2836 
2837 
2838 
2839 LIBSBML_CPP_NAMESPACE_END
2840 
2841 
2842