1 /**
2 * @file RenderSBMLDocumentPlugin.cpp
3 * @brief Implementation of the RenderSBMLDocumentPlugin 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/render/extension/RenderSBMLDocumentPlugin.h>
43 #include <sbml/packages/render/validator/RenderSBMLError.h>
44 #include <sbml/packages/render/validator/RenderConsistencyValidator.h>
45 #include <sbml/packages/render/validator/RenderIdentifierConsistencyValidator.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 /*
61 * Creates a new RenderSBMLDocumentPlugin using the given URI, prefix and
62 * package namespace.
63 */
RenderSBMLDocumentPlugin(const std::string & uri,const std::string & prefix,RenderPkgNamespaces * renderns)64 RenderSBMLDocumentPlugin::RenderSBMLDocumentPlugin(const std::string& uri,
65 const std::string& prefix,
66 RenderPkgNamespaces*
67 renderns)
68 : SBMLDocumentPlugin(uri, prefix, renderns)
69 {
70 }
71
72
73 /*
74 * Copy constructor for RenderSBMLDocumentPlugin.
75 */
RenderSBMLDocumentPlugin(const RenderSBMLDocumentPlugin & orig)76 RenderSBMLDocumentPlugin::RenderSBMLDocumentPlugin(const
77 RenderSBMLDocumentPlugin& orig)
78 : SBMLDocumentPlugin( orig )
79 {
80 }
81
82
83 /*
84 * Assignment operator for RenderSBMLDocumentPlugin.
85 */
86 RenderSBMLDocumentPlugin&
operator =(const RenderSBMLDocumentPlugin & rhs)87 RenderSBMLDocumentPlugin::operator=(const RenderSBMLDocumentPlugin& rhs)
88 {
89 if (&rhs != this)
90 {
91 SBMLDocumentPlugin::operator=(rhs);
92 }
93
94 return *this;
95 }
96
97
98 /*
99 * Creates and returns a deep copy of this RenderSBMLDocumentPlugin object.
100 */
101 RenderSBMLDocumentPlugin*
clone() const102 RenderSBMLDocumentPlugin::clone() const
103 {
104 return new RenderSBMLDocumentPlugin(*this);
105 }
106
107
108 /*
109 * Destructor for RenderSBMLDocumentPlugin.
110 */
~RenderSBMLDocumentPlugin()111 RenderSBMLDocumentPlugin::~RenderSBMLDocumentPlugin()
112 {
113 }
114
115
116
117 /** @cond doxygenLibsbmlInternal */
118
119 /*
120 * Accepts the given SBMLVisitor
121 */
122 bool
accept(SBMLVisitor & v) const123 RenderSBMLDocumentPlugin::accept(SBMLVisitor& v) const
124 {
125 const SBMLDocument* sbmld = static_cast<const
126 SBMLDocument*>(this->getParentSBMLObject());
127 v.visit(*sbmld);
128 v.leave(*sbmld);
129
130 return true;
131 }
132
133 /** @endcond */
134
135
136
137 /** @cond doxygenLibsbmlInternal */
138
139 /*
140 * Predicate indicating whether 'comp' flattening has been implemented for the
141 * Render package.
142 */
143 bool
isCompFlatteningImplemented() const144 RenderSBMLDocumentPlugin::isCompFlatteningImplemented() const
145 {
146 return false;
147 }
148
149 /** @endcond */
150
151
152
153 /** @cond doxygenLibsbmlInternal */
154
155 /*
156 * Calls check consistency for any relevant Render validators.
157 */
158 unsigned int
checkConsistency()159 RenderSBMLDocumentPlugin::checkConsistency()
160 {
161 unsigned int nerrors = 0;
162 unsigned int total_errors = 0;
163
164 SBMLDocument* doc = static_cast<SBMLDocument*>(this->getParentSBMLObject());
165 SBMLErrorLog* log = doc->getErrorLog();
166
167 unsigned char applicableValidators = doc->getApplicableValidators();
168 bool id = ((applicableValidators & 0x01) ==0x01);
169 bool core = ((applicableValidators & 0x02) ==0x02);
170
171 RenderIdentifierConsistencyValidator id_validator;
172 RenderConsistencyValidator core_validator;
173
174 if (id)
175 {
176 id_validator.init();
177 nerrors = id_validator.validate(*doc);
178 total_errors += nerrors;
179 if (nerrors > 0)
180 {
181 log->add(id_validator.getFailures());
182 if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0)
183 {
184 return total_errors;
185 }
186 }
187 }
188
189 if (core)
190 {
191 core_validator.init();
192 nerrors = core_validator.validate(*doc);
193 total_errors += nerrors;
194 if (nerrors > 0)
195 {
196 log->add(core_validator.getFailures());
197 if (log->getNumFailsWithSeverity(LIBSBML_SEV_ERROR) > 0)
198 {
199 return total_errors;
200 }
201 }
202 }
203
204 return total_errors;
205 }
206
207 /** @endcond */
208
209
210
211 /** @cond doxygenLibsbmlInternal */
212
213 /*
214 * Reads the Render attributes in the top-level element.
215 */
216 void
readAttributes(const XMLAttributes & attributes,const ExpectedAttributes & expectedAttributes)217 RenderSBMLDocumentPlugin::readAttributes(const XMLAttributes& attributes,
218 const ExpectedAttributes&
219 expectedAttributes)
220 {
221 if (getSBMLDocument() != NULL && getSBMLDocument()->getLevel() < 3)
222 {
223 return;
224 }
225
226 SBMLErrorLog* log = getErrorLog();
227 unsigned int numErrs = log->getNumErrors();
228 XMLTriple tripleReqd("required", mURI, getPrefix());
229 bool assigned = attributes.readInto(tripleReqd, mRequired);
230
231 if (assigned == false)
232 {
233 if (log->getNumErrors() == numErrs + 1 &&
234 log->contains(XMLAttributeTypeMismatch))
235 {
236 log->remove(XMLAttributeTypeMismatch);
237 log->logPackageError("render", RenderAttributeRequiredMustBeBoolean,
238 getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
239 }
240 else
241 {
242 log->logPackageError("render", RenderAttributeRequiredMissing,
243 getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
244 }
245 }
246 else
247 {
248 mIsSetRequired = true;
249 if (mRequired != false)
250 {
251 log->logPackageError("render", RenderAttributeRequiredMustHaveValue,
252 getPackageVersion(), getLevel(), getVersion(), "", getLine(), getColumn());
253 }
254 }
255 }
256
257 /** @endcond */
258
259
260
261 /** @cond doxygenLibsbmlInternal */
262
263 /*
264 * Returns the value of the "attributeName" attribute of this
265 * RenderSBMLDocumentPlugin.
266 */
267 int
getAttribute(const std::string & attributeName,bool & value) const268 RenderSBMLDocumentPlugin::getAttribute(const std::string& attributeName,
269 bool& value) const
270 {
271 int return_value = SBMLDocumentPlugin::getAttribute(attributeName, value);
272
273 return return_value;
274 }
275
276 /** @endcond */
277
278
279
280 /** @cond doxygenLibsbmlInternal */
281
282 /*
283 * Returns the value of the "attributeName" attribute of this
284 * RenderSBMLDocumentPlugin.
285 */
286 int
getAttribute(const std::string & attributeName,int & value) const287 RenderSBMLDocumentPlugin::getAttribute(const std::string& attributeName,
288 int& value) const
289 {
290 int return_value = SBMLDocumentPlugin::getAttribute(attributeName, value);
291
292 return return_value;
293 }
294
295 /** @endcond */
296
297
298
299 /** @cond doxygenLibsbmlInternal */
300
301 /*
302 * Returns the value of the "attributeName" attribute of this
303 * RenderSBMLDocumentPlugin.
304 */
305 int
getAttribute(const std::string & attributeName,double & value) const306 RenderSBMLDocumentPlugin::getAttribute(const std::string& attributeName,
307 double& value) const
308 {
309 int return_value = SBMLDocumentPlugin::getAttribute(attributeName, value);
310
311 return return_value;
312 }
313
314 /** @endcond */
315
316
317
318 /** @cond doxygenLibsbmlInternal */
319
320 /*
321 * Returns the value of the "attributeName" attribute of this
322 * RenderSBMLDocumentPlugin.
323 */
324 int
getAttribute(const std::string & attributeName,unsigned int & value) const325 RenderSBMLDocumentPlugin::getAttribute(const std::string& attributeName,
326 unsigned int& value) const
327 {
328 int return_value = SBMLDocumentPlugin::getAttribute(attributeName, value);
329
330 return return_value;
331 }
332
333 /** @endcond */
334
335
336
337 /** @cond doxygenLibsbmlInternal */
338
339 /*
340 * Returns the value of the "attributeName" attribute of this
341 * RenderSBMLDocumentPlugin.
342 */
343 int
getAttribute(const std::string & attributeName,std::string & value) const344 RenderSBMLDocumentPlugin::getAttribute(const std::string& attributeName,
345 std::string& value) const
346 {
347 int return_value = SBMLDocumentPlugin::getAttribute(attributeName, value);
348
349 return return_value;
350 }
351
352 /** @endcond */
353
354
355
356 /** @cond doxygenLibsbmlInternal */
357
358 /*
359 * Predicate returning @c true if this RenderSBMLDocumentPlugin's attribute
360 * "attributeName" is set.
361 */
362 bool
isSetAttribute(const std::string & attributeName) const363 RenderSBMLDocumentPlugin::isSetAttribute(const std::string& attributeName)
364 const
365 {
366 bool value = SBMLDocumentPlugin::isSetAttribute(attributeName);
367
368 return value;
369 }
370
371 /** @endcond */
372
373
374
375 /** @cond doxygenLibsbmlInternal */
376
377 /*
378 * Sets the value of the "attributeName" attribute of this
379 * RenderSBMLDocumentPlugin.
380 */
381 int
setAttribute(const std::string & attributeName,bool value)382 RenderSBMLDocumentPlugin::setAttribute(const std::string& attributeName,
383 bool value)
384 {
385 int return_value = SBMLDocumentPlugin::setAttribute(attributeName, value);
386
387 return return_value;
388 }
389
390 /** @endcond */
391
392
393
394 /** @cond doxygenLibsbmlInternal */
395
396 /*
397 * Sets the value of the "attributeName" attribute of this
398 * RenderSBMLDocumentPlugin.
399 */
400 int
setAttribute(const std::string & attributeName,int value)401 RenderSBMLDocumentPlugin::setAttribute(const std::string& attributeName,
402 int value)
403 {
404 int return_value = SBMLDocumentPlugin::setAttribute(attributeName, value);
405
406 return return_value;
407 }
408
409 /** @endcond */
410
411
412
413 /** @cond doxygenLibsbmlInternal */
414
415 /*
416 * Sets the value of the "attributeName" attribute of this
417 * RenderSBMLDocumentPlugin.
418 */
419 int
setAttribute(const std::string & attributeName,double value)420 RenderSBMLDocumentPlugin::setAttribute(const std::string& attributeName,
421 double value)
422 {
423 int return_value = SBMLDocumentPlugin::setAttribute(attributeName, value);
424
425 return return_value;
426 }
427
428 /** @endcond */
429
430
431
432 /** @cond doxygenLibsbmlInternal */
433
434 /*
435 * Sets the value of the "attributeName" attribute of this
436 * RenderSBMLDocumentPlugin.
437 */
438 int
setAttribute(const std::string & attributeName,unsigned int value)439 RenderSBMLDocumentPlugin::setAttribute(const std::string& attributeName,
440 unsigned int value)
441 {
442 int return_value = SBMLDocumentPlugin::setAttribute(attributeName, value);
443
444 return return_value;
445 }
446
447 /** @endcond */
448
449
450
451 /** @cond doxygenLibsbmlInternal */
452
453 /*
454 * Sets the value of the "attributeName" attribute of this
455 * RenderSBMLDocumentPlugin.
456 */
457 int
setAttribute(const std::string & attributeName,const std::string & value)458 RenderSBMLDocumentPlugin::setAttribute(const std::string& attributeName,
459 const std::string& value)
460 {
461 int return_value = SBMLDocumentPlugin::setAttribute(attributeName, value);
462
463 return return_value;
464 }
465
466 /** @endcond */
467
468
469
470 /** @cond doxygenLibsbmlInternal */
471
472 /*
473 * Unsets the value of the "attributeName" attribute of this
474 * RenderSBMLDocumentPlugin.
475 */
476 int
unsetAttribute(const std::string & attributeName)477 RenderSBMLDocumentPlugin::unsetAttribute(const std::string& attributeName)
478 {
479 int value = SBMLDocumentPlugin::unsetAttribute(attributeName);
480
481 return value;
482 }
483
484 /** @endcond */
485
486
487
488
489 #endif /* __cplusplus */
490
491
492
493
494 LIBSBML_CPP_NAMESPACE_END
495
496
497