COPASI API  4.16.103
Static Public Member Functions | Static Protected Member Functions | List of all members
SBMLUtils Class Reference

#include <SBMLUtils.h>

Static Public Member Functions

static void collectIds (Model *pModel, std::map< std::string, const SBase * > &ids, std::map< std::string, const SBase * > &metaIds)
 
static std::string getIdFromSBase (const SBase *s)
 

Static Protected Member Functions

template<class CType >
static std::string getId (const CType *pA, C_INT32 level=2)
 

Detailed Description

Definition at line 26 of file SBMLUtils.h.

Member Function Documentation

void SBMLUtils::collectIds ( Model *  pModel,
std::map< std::string, const SBase * > &  ids,
std::map< std::string, const SBase * > &  metaIds 
)
static

This method goes through the given SBML model and collects all ids and meta ids used in the model.

Definition at line 96 of file SBMLUtils.cpp.

References CCopasiMessage::EXCEPTION, MCSBML, and CCopasiMessage::WARNING.

Referenced by CCellDesignerImporter::convertCellDesignerLayout(), CSBMLExporter::createSBMLDocument(), and SBMLImporter::preprocessNode().

97 {
98  if (pModel != NULL)
99  {
100  // the model itself
101  SBase* pSBase = NULL;
102  std::string id;
103 
104  if (pModel->isSetId())
105  {
106  id = pModel->getId();
107 
108  if (ids.find(id) == ids.end())
109  {
110  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
111  }
112  else
113  {
115  }
116  }
117 
118  if (pModel->isSetMetaId())
119  {
120  id = pModel->getMetaId();
121 
122  if (metaIds.find(id) == metaIds.end())
123  {
124  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
125  }
126  else
127  {
128  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
129  }
130  }
131 
132  // ListOfFunctionDefinitions
133  pSBase = pModel->getListOfFunctionDefinitions();
134 
135  if (pSBase != NULL)
136  {
137  if (pSBase->isSetId())
138  {
139  id = pSBase->getId();
140 
141  if (ids.find(id) == ids.end())
142  {
143  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
144  }
145  else
146  {
148  }
149  }
150 
151  if (pSBase->isSetMetaId())
152  {
153  id = pSBase->getMetaId();
154 
155  if (metaIds.find(id) == metaIds.end())
156  {
157  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
158  }
159  else
160  {
161  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
162  }
163  }
164 
165  // all FunctionDefinitions
166  unsigned int i, iMax = pModel->getListOfFunctionDefinitions()->size();
167 
168  for (i = 0; i < iMax; ++i)
169  {
170  pSBase = pModel->getListOfFunctionDefinitions()->get(i);
171 
172  if (pSBase->isSetId())
173  {
174  id = pSBase->getId();
175 
176  if (ids.find(id) == ids.end())
177  {
178  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
179  }
180  else
181  {
183  }
184  }
185 
186  if (pSBase->isSetMetaId())
187  {
188  id = pSBase->getMetaId();
189 
190  if (metaIds.find(id) == metaIds.end())
191  {
192  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
193  }
194  else
195  {
196  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
197  }
198  }
199  }
200  }
201 
202  // ListOfUnitDefinition
203  pSBase = pModel->getListOfUnitDefinitions();
204 
205  if (pSBase != NULL)
206  {
207  if (pSBase->isSetMetaId())
208  {
209  id = pSBase->getMetaId();
210 
211  if (metaIds.find(id) == metaIds.end())
212  {
213  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
214  }
215  else
216  {
217  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
218  }
219  }
220 
221  // all UnitDefinitions
222  // for each UnitDefinition: ListOfUnits, each Unit in ListOfUnits
223  unsigned int i, iMax = pModel->getListOfUnitDefinitions()->size();
224 
225  for (i = 0; i < iMax; ++i)
226  {
227  /* UnitDefinitions have their ids in a different namespace
228  so we only consider meta ids.
229  */
230  UnitDefinition* pUDef = pModel->getUnitDefinition(i);
231  assert(pUDef != NULL);
232 
233  if (pUDef->isSetMetaId())
234  {
235  id = pUDef->getMetaId();
236 
237  if (metaIds.find(id) == metaIds.end())
238  {
239  metaIds.insert(std::pair<const std::string, const SBase*>(id, pUDef));
240  }
241  else
242  {
243  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
244  }
245  }
246 
247  ListOf* pList = pUDef->getListOfUnits();
248 
249  if (pList != NULL)
250  {
251  if (pList->isSetMetaId())
252  {
253  id = pList->getMetaId();
254 
255  if (metaIds.find(id) == metaIds.end())
256  {
257  metaIds.insert(std::pair<const std::string, const SBase*>(id, pList));
258  }
259  else
260  {
261  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
262  }
263  }
264 
265  unsigned j, jMax = pList->size();
266 
267  for (j = 0; j < jMax; ++j)
268  {
269  pSBase = pList->get(j);
270  assert(pSBase != NULL);
271 
272  if (pSBase->isSetMetaId())
273  {
274  id = pSBase->getMetaId();
275 
276  if (metaIds.find(id) == metaIds.end())
277  {
278  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
279  }
280  else
281  {
282  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
283  }
284  }
285  }
286  }
287  }
288  }
289 
290  // ListOfCompartmentTypes
291  pSBase = pModel->getListOfCompartmentTypes();
292 
293  if (pSBase != NULL)
294  {
295  if (pSBase->isSetId())
296  {
297  id = pSBase->getId();
298 
299  if (ids.find(id) == ids.end())
300  {
301  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
302  }
303  else
304  {
306  }
307  }
308 
309  if (pSBase->isSetMetaId())
310  {
311  id = pSBase->getMetaId();
312 
313  if (metaIds.find(id) == metaIds.end())
314  {
315  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
316  }
317  else
318  {
319  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
320  }
321  }
322 
323  // each compartment type
324  unsigned int i, iMax = pModel->getListOfCompartmentTypes()->size();
325 
326  for (i = 0; i < iMax; ++i)
327  {
328  pSBase = pModel->getCompartmentType(i);
329  assert(pSBase != NULL);
330 
331  if (pSBase->isSetId())
332  {
333  id = pSBase->getId();
334 
335  if (ids.find(id) == ids.end())
336  {
337  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
338  }
339  else
340  {
342  }
343  }
344 
345  if (pSBase->isSetMetaId())
346  {
347  id = pSBase->getMetaId();
348 
349  if (metaIds.find(id) == metaIds.end())
350  {
351  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
352  }
353  else
354  {
355  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
356  }
357  }
358  }
359  }
360 
361  // ListOfSpeciesTypes
362  pSBase = pModel->getListOfSpeciesTypes();
363 
364  if (pSBase != NULL)
365  {
366  if (pSBase->isSetId())
367  {
368  id = pSBase->getId();
369 
370  if (ids.find(id) == ids.end())
371  {
372  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
373  }
374  else
375  {
377  }
378  }
379 
380  if (pSBase->isSetMetaId())
381  {
382  id = pSBase->getMetaId();
383 
384  if (metaIds.find(id) == metaIds.end())
385  {
386  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
387  }
388  else
389  {
390  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
391  }
392  }
393 
394  // each species type
395  unsigned int i, iMax = pModel->getListOfSpeciesTypes()->size();
396 
397  for (i = 0; i < iMax; ++i)
398  {
399  pSBase = pModel->getSpeciesType(i);
400  assert(pSBase != NULL);
401 
402  if (pSBase->isSetId())
403  {
404  id = pSBase->getId();
405 
406  if (ids.find(id) == ids.end())
407  {
408  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
409  }
410  else
411  {
413  }
414  }
415 
416  if (pSBase->isSetMetaId())
417  {
418  id = pSBase->getMetaId();
419 
420  if (metaIds.find(id) == metaIds.end())
421  {
422  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
423  }
424  else
425  {
426  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
427  }
428  }
429  }
430  }
431 
432  // ListOfCompartments
433  pSBase = pModel->getListOfCompartments();
434 
435  if (pSBase != NULL)
436  {
437  if (pSBase->isSetId())
438  {
439  id = pSBase->getId();
440 
441  if (ids.find(id) == ids.end())
442  {
443  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
444  }
445  else
446  {
448  }
449  }
450 
451  if (pSBase->isSetMetaId())
452  {
453  id = pSBase->getMetaId();
454 
455  if (metaIds.find(id) == metaIds.end())
456  {
457  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
458  }
459  else
460  {
461  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
462  }
463  }
464 
465  // all compartments
466  unsigned int i, iMax = pModel->getListOfCompartments()->size();
467 
468  for (i = 0; i < iMax; ++i)
469  {
470  pSBase = pModel->getCompartment(i);
471  assert(pSBase != NULL);
472 
473  if (pSBase->isSetId())
474  {
475  id = pSBase->getId();
476 
477  if (ids.find(id) == ids.end())
478  {
479  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
480  }
481  else
482  {
484  }
485  }
486 
487  if (pSBase->isSetMetaId())
488  {
489  id = pSBase->getMetaId();
490 
491  if (metaIds.find(id) == metaIds.end())
492  {
493  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
494  }
495  else
496  {
497  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
498  }
499  }
500  }
501  }
502 
503  // ListOfSpecies
504  pSBase = pModel->getListOfSpecies();
505 
506  if (pSBase != NULL)
507  {
508  if (pSBase->isSetId())
509  {
510  id = pSBase->getId();
511 
512  if (ids.find(id) == ids.end())
513  {
514  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
515  }
516  else
517  {
519  }
520  }
521 
522  if (pSBase->isSetMetaId())
523  {
524  id = pSBase->getMetaId();
525 
526  if (metaIds.find(id) == metaIds.end())
527  {
528  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
529  }
530  else
531  {
532  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
533  }
534  }
535 
536  // all species
537  unsigned int i, iMax = pModel->getListOfSpecies()->size();
538 
539  for (i = 0; i < iMax; ++i)
540  {
541  pSBase = pModel->getSpecies(i);
542  assert(pSBase != NULL);
543 
544  if (pSBase->isSetId())
545  {
546  id = pSBase->getId();
547 
548  if (ids.find(id) == ids.end())
549  {
550  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
551  }
552  else
553  {
555  }
556  }
557 
558  if (pSBase->isSetMetaId())
559  {
560  id = pSBase->getMetaId();
561 
562  if (metaIds.find(id) == metaIds.end())
563  {
564  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
565  }
566  else
567  {
568  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
569  }
570  }
571  }
572  }
573 
574  // ListOfParameters
575  pSBase = pModel->getListOfParameters();
576 
577  if (pSBase != NULL)
578  {
579  if (pSBase->isSetId())
580  {
581  id = pSBase->getId();
582 
583  if (ids.find(id) == ids.end())
584  {
585  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
586  }
587  else
588  {
590  }
591  }
592 
593  if (pSBase->isSetMetaId())
594  {
595  id = pSBase->getMetaId();
596 
597  if (metaIds.find(id) == metaIds.end())
598  {
599  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
600  }
601  else
602  {
603  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
604  }
605  }
606 
607  // each parameter
608  unsigned int i, iMax = pModel->getListOfParameters()->size();
609 
610  for (i = 0; i < iMax; ++i)
611  {
612  pSBase = pModel->getParameter(i);
613  assert(pSBase != NULL);
614 
615  if (pSBase->isSetId())
616  {
617  id = pSBase->getId();
618 
619  if (ids.find(id) == ids.end())
620  {
621  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
622  }
623  else
624  {
626  }
627  }
628 
629  if (pSBase->isSetMetaId())
630  {
631  id = pSBase->getMetaId();
632 
633  if (metaIds.find(id) == metaIds.end())
634  {
635  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
636  }
637  else
638  {
639  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
640  }
641  }
642  }
643  }
644 
645  // ListOfInitialAssignments
646  pSBase = pModel->getListOfInitialAssignments();
647 
648  if (pSBase != NULL)
649  {
650  if (pSBase->isSetId())
651  {
652  id = pSBase->getId();
653 
654  if (ids.find(id) == ids.end())
655  {
656  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
657  }
658  else
659  {
661  }
662  }
663 
664  if (pSBase->isSetMetaId())
665  {
666  id = pSBase->getMetaId();
667 
668  if (metaIds.find(id) == metaIds.end())
669  {
670  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
671  }
672  else
673  {
674  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
675  }
676  }
677 
678  // each initial assignment
679  unsigned int i, iMax = pModel->getListOfInitialAssignments()->size();
680 
681  for (i = 0; i < iMax; ++i)
682  {
683  pSBase = pModel->getInitialAssignment(i);
684  assert(pSBase != NULL);
685 
686  // initial assignments have no ids
687  if (pSBase->isSetMetaId())
688  {
689  id = pSBase->getMetaId();
690 
691  if (metaIds.find(id) == metaIds.end())
692  {
693  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
694  }
695  else
696  {
697  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
698  }
699  }
700  }
701  }
702 
703  // ListOfRules
704  pSBase = pModel->getListOfRules();
705 
706  if (pSBase != NULL)
707  {
708  if (pSBase->isSetId())
709  {
710  id = pSBase->getId();
711 
712  if (ids.find(id) == ids.end())
713  {
714  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
715  }
716  else
717  {
719  }
720  }
721 
722  if (pSBase->isSetMetaId())
723  {
724  id = pSBase->getMetaId();
725 
726  if (metaIds.find(id) == metaIds.end())
727  {
728  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
729  }
730  else
731  {
732  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
733  }
734  }
735 
736  // each rule
737  unsigned int i, iMax = pModel->getListOfRules()->size();
738 
739  for (i = 0; i < iMax; ++i)
740  {
741  pSBase = pModel->getRule(i);
742  assert(pSBase != NULL);
743 
744  // rules don't have ids
745  if (pSBase->isSetMetaId())
746  {
747  id = pSBase->getMetaId();
748 
749  if (metaIds.find(id) == metaIds.end())
750  {
751  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
752  }
753  else
754  {
755  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
756  }
757  }
758  }
759  }
760 
761  // ListOfConstraints
762  pSBase = pModel->getListOfConstraints();
763 
764  if (pSBase != NULL)
765  {
766  if (pSBase->isSetId())
767  {
768  id = pSBase->getId();
769 
770  if (ids.find(id) == ids.end())
771  {
772  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
773  }
774  else
775  {
777  }
778  }
779 
780  if (pSBase->isSetMetaId())
781  {
782  id = pSBase->getMetaId();
783 
784  if (metaIds.find(id) == metaIds.end())
785  {
786  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
787  }
788  else
789  {
790  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
791  }
792  }
793 
794  // each constraint
795  unsigned int i, iMax = pModel->getListOfConstraints()->size();
796 
797  for (i = 0; i < iMax; ++i)
798  {
799  pSBase = pModel->getConstraint(i);
800  assert(pSBase != NULL);
801 
802  // constraints don't have ids
803  if (pSBase->isSetMetaId())
804  {
805  id = pSBase->getMetaId();
806 
807  if (metaIds.find(id) == metaIds.end())
808  {
809  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
810  }
811  else
812  {
813  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
814  }
815  }
816  }
817  }
818 
819  // ListOfReactions
820  pSBase = pModel->getListOfReactions();
821 
822  if (pSBase != NULL)
823  {
824  if (pSBase->isSetId())
825  {
826  id = pSBase->getId();
827 
828  if (ids.find(id) == ids.end())
829  {
830  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
831  }
832  else
833  {
835  }
836  }
837 
838  if (pSBase->isSetMetaId())
839  {
840  id = pSBase->getMetaId();
841 
842  if (metaIds.find(id) == metaIds.end())
843  {
844  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
845  }
846  else
847  {
848  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
849  }
850  }
851 
852  // all reactions
853  unsigned int i, iMax = pModel->getListOfReactions()->size();
854 
855  for (i = 0; i < iMax; ++i)
856  {
857  Reaction* pReaction = pModel->getReaction(i);
858  assert(pReaction != NULL);
859 
860  if (pReaction->isSetId())
861  {
862  id = pReaction->getId();
863 
864  if (ids.find(id) == ids.end())
865  {
866  ids.insert(std::pair<const std::string, const SBase*>(id, pReaction));
867  }
868  else
869  {
871  }
872  }
873 
874  if (pReaction->isSetMetaId())
875  {
876  id = pReaction->getMetaId();
877 
878  if (metaIds.find(id) == metaIds.end())
879  {
880  metaIds.insert(std::pair<const std::string, const SBase*>(id, pReaction));
881  }
882  else
883  {
884  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
885  }
886  }
887 
888  // for each reaction: ListOfSubstrates, each substrate, ListOfProducts, each
889  // Product, ListOfModifieres, each modifier, KineticLaw, ListOfparameters,
890  // each parameter
891  if (pReaction->getListOfReactants() != NULL)
892  {
893  pSBase = pReaction->getListOfReactants();
894 
895  if (pSBase->isSetMetaId())
896  {
897  id = pSBase->getMetaId();
898 
899  if (metaIds.find(id) == metaIds.end())
900  {
901  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
902  }
903  else
904  {
905  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
906  }
907  }
908 
909  unsigned int j, jMax = pReaction->getListOfReactants()->size();
910 
911  for (j = 0; j < jMax; ++j)
912  {
913  pSBase = pReaction->getReactant(j);
914  assert(pSBase != NULL);
915 
916  // since L2V2 species references can have ids
917  if (pSBase->isSetId())
918  {
919  id = pSBase->getId();
920 
921  if (ids.find(id) == ids.end())
922  {
923  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
924  }
925  else
926  {
928  }
929  }
930 
931  if (pSBase->isSetMetaId())
932  {
933  id = pSBase->getMetaId();
934 
935  if (metaIds.find(id) == metaIds.end())
936  {
937  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
938  }
939  else
940  {
941  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
942  }
943  }
944  }
945  }
946 
947  if (pReaction->getListOfProducts() != NULL)
948  {
949  pSBase = pReaction->getListOfProducts();
950 
951  if (pSBase->isSetMetaId())
952  {
953  id = pSBase->getMetaId();
954 
955  if (metaIds.find(id) == metaIds.end())
956  {
957  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
958  }
959  else
960  {
961  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
962  }
963  }
964 
965  unsigned int j, jMax = pReaction->getListOfProducts()->size();
966 
967  for (j = 0; j < jMax; ++j)
968  {
969  pSBase = pReaction->getProduct(j);
970  assert(pSBase != NULL);
971 
972  // since L2V2 species references can have ids
973  if (pSBase->isSetId())
974  {
975  id = pSBase->getId();
976 
977  if (ids.find(id) == ids.end())
978  {
979  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
980  }
981  else
982  {
984  }
985  }
986 
987  if (pSBase->isSetMetaId())
988  {
989  id = pSBase->getMetaId();
990 
991  if (metaIds.find(id) == metaIds.end())
992  {
993  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
994  }
995  else
996  {
997  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
998  }
999  }
1000  }
1001  }
1002 
1003  if (pReaction->getListOfModifiers() != NULL)
1004  {
1005  pSBase = pReaction->getListOfModifiers();
1006 
1007  if (pSBase->isSetMetaId())
1008  {
1009  id = pSBase->getMetaId();
1010 
1011  if (metaIds.find(id) == metaIds.end())
1012  {
1013  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1014  }
1015  else
1016  {
1017  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1018  }
1019  }
1020 
1021  unsigned int j, jMax = pReaction->getListOfModifiers()->size();
1022 
1023  for (j = 0; j < jMax; ++j)
1024  {
1025  pSBase = pReaction->getModifier(j);
1026  assert(pSBase != NULL);
1027 
1028  // since L2V2 species references can have ids
1029  if (pSBase->isSetId())
1030  {
1031  id = pSBase->getId();
1032 
1033  if (ids.find(id) == ids.end())
1034  {
1035  ids.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1036  }
1037  else
1038  {
1039  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
1040  }
1041  }
1042 
1043  if (pSBase->isSetMetaId())
1044  {
1045  id = pSBase->getMetaId();
1046 
1047  if (metaIds.find(id) == metaIds.end())
1048  {
1049  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1050  }
1051  else
1052  {
1053  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1054  }
1055  }
1056  }
1057  }
1058 
1059  KineticLaw* pKLaw = pReaction->getKineticLaw();
1060 
1061  if (pKLaw != NULL)
1062  {
1063  if (pKLaw->isSetMetaId())
1064  {
1065  id = pKLaw->getMetaId();
1066 
1067  if (metaIds.find(id) == metaIds.end())
1068  {
1069  metaIds.insert(std::pair<const std::string, const SBase*>(id, pKLaw));
1070  }
1071  else
1072  {
1073  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1074  }
1075  }
1076 
1077  pSBase = pKLaw->getListOfParameters();
1078 
1079  if (pSBase != NULL)
1080  {
1081  if (pSBase->isSetMetaId())
1082  {
1083  id = pSBase->getMetaId();
1084 
1085  if (metaIds.find(id) == metaIds.end())
1086  {
1087  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1088  }
1089  else
1090  {
1091  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1092  }
1093  }
1094 
1095  unsigned int j, jMax = pKLaw->getListOfParameters()->size();
1096 
1097  for (j = 0; j < jMax; ++j)
1098  {
1099  pSBase = pKLaw->getParameter(j);
1100  assert(pSBase != NULL);
1101 
1102  // local parameters have their ids in a
1103  // different namespace
1104  if (pSBase->isSetMetaId())
1105  {
1106  id = pSBase->getMetaId();
1107 
1108  if (metaIds.find(id) == metaIds.end())
1109  {
1110  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1111  }
1112  else
1113  {
1114  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1115  }
1116  }
1117  }
1118  }
1119  }
1120  }
1121  }
1122 
1123  // ListOfEvents
1124  pSBase = pModel->getListOfEvents();
1125 
1126  if (pSBase != NULL)
1127  {
1128  if (pSBase->isSetId())
1129  {
1130  id = pSBase->getId();
1131 
1132  if (ids.find(id) == ids.end())
1133  {
1134  ids.insert(std::pair<const std::string, const SBase*>(id, pModel));
1135  }
1136  else
1137  {
1138  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
1139  }
1140  }
1141 
1142  if (pSBase->isSetMetaId())
1143  {
1144  id = pSBase->getMetaId();
1145 
1146  if (metaIds.find(id) == metaIds.end())
1147  {
1148  metaIds.insert(std::pair<const std::string, const SBase*>(id, pModel));
1149  }
1150  else
1151  {
1152  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1153  }
1154  }
1155 
1156  // each event
1157  unsigned int i, iMax = pModel->getListOfEvents()->size();
1158 
1159  for (i = 0; i < iMax; ++i)
1160  {
1161  Event* pEvent = pModel->getEvent(i);
1162  assert(pEvent != NULL);
1163 
1164  if (pEvent->isSetId())
1165  {
1166  id = pEvent->getId();
1167 
1168  if (ids.find(id) == ids.end())
1169  {
1170  ids.insert(std::pair<const std::string, const SBase*>(id, pEvent));
1171  }
1172  else
1173  {
1174  CCopasiMessage(CCopasiMessage::EXCEPTION, MCSBML + 68, id.c_str());
1175  }
1176  }
1177 
1178  if (pEvent->isSetMetaId())
1179  {
1180  id = pEvent->getMetaId();
1181 
1182  if (metaIds.find(id) == metaIds.end())
1183  {
1184  metaIds.insert(std::pair<const std::string, const SBase*>(id, pEvent));
1185  }
1186  else
1187  {
1188  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1189  }
1190  }
1191 
1192  // in each event Trigger,Delay,ListOfEventAssignments, each event assignment
1193  if (pEvent->isSetTrigger())
1194  {
1195  pSBase = pEvent->getTrigger();
1196  assert(pSBase != NULL);
1197 
1198  if (pSBase->isSetMetaId())
1199  {
1200  id = pSBase->getMetaId();
1201 
1202  if (metaIds.find(id) == metaIds.end())
1203  {
1204  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1205  }
1206  else
1207  {
1208  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1209  }
1210  }
1211  }
1212 
1213  if (pEvent->isSetDelay())
1214  {
1215  pSBase = pEvent->getDelay();
1216  assert(pSBase != NULL);
1217 
1218  if (pSBase->isSetMetaId())
1219  {
1220  id = pSBase->getMetaId();
1221 
1222  if (metaIds.find(id) == metaIds.end())
1223  {
1224  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1225  }
1226  else
1227  {
1228  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1229  }
1230  }
1231  }
1232 
1233  if (pEvent->getListOfEventAssignments() != NULL)
1234  {
1235  pSBase = pEvent->getListOfEventAssignments();
1236 
1237  if (pSBase->isSetMetaId())
1238  {
1239  id = pSBase->getMetaId();
1240 
1241  if (metaIds.find(id) == metaIds.end())
1242  {
1243  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1244  }
1245  else
1246  {
1247  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1248  }
1249  }
1250 
1251  unsigned int j, jMax = pEvent->getListOfEventAssignments()->size();
1252 
1253  for (j = 0; j < jMax; ++j)
1254  {
1255  pSBase = pEvent->getEventAssignment(j);
1256  assert(pSBase != NULL);
1257 
1258  if (pSBase->isSetMetaId())
1259  {
1260  id = pSBase->getMetaId();
1261 
1262  if (metaIds.find(id) == metaIds.end())
1263  {
1264  metaIds.insert(std::pair<const std::string, const SBase*>(id, pSBase));
1265  }
1266  else
1267  {
1268  CCopasiMessage(CCopasiMessage::WARNING, MCSBML + 67, id.c_str());
1269  }
1270  }
1271  }
1272  }
1273  }
1274  }
1275  }
1276 }
#define MCSBML
const char * id
Definition: stdsoap2.h:1262
template<class CType >
std::string SBMLUtils::getId ( const CType *  pA,
C_INT32  level = 2 
)
staticprotected

Definition at line 81 of file SBMLUtils.cpp.

Referenced by getIdFromSBase().

82 {
83  if (!pA) return "";
84 
85  if (level == 1)
86  return pA->getName();
87  else
88  return pA->getId();
89 }
std::string SBMLUtils::getIdFromSBase ( const SBase *  s)
static

Return the sbml ID if the sbml object actually has one. If not, it returns "". It only handles core sbml objects. No layout objects yet.

Definition at line 32 of file SBMLUtils.cpp.

References getId().

Referenced by DataModelGUI::importCellDesigner(), and SBMLDocumentLoader::readListOfLayouts().

33 {
34  if (!pS) return "";
35 
36  std::string id;
37 
38  int type = pS->getTypeCode();
39 
40  switch (type)
41  {
42  case SBML_COMPARTMENT:
43  id = getId(dynamic_cast<const Compartment*>(pS));
44  break;
45  case SBML_EVENT:
46  id = getId(dynamic_cast<const Event*>(pS));
47  break;
48  case SBML_FUNCTION_DEFINITION:
49  id = getId(dynamic_cast<const FunctionDefinition*>(pS));
50  break;
51  case SBML_MODEL:
52  id = getId(dynamic_cast<const Model*>(pS));
53  break;
54  case SBML_PARAMETER:
55  id = getId(dynamic_cast<const Parameter*>(pS));
56  break;
57  case SBML_REACTION:
58  id = getId(dynamic_cast<const Reaction*>(pS));
59  break;
60  case SBML_SPECIES:
61  id = getId(dynamic_cast<const Species*>(pS));
62  break;
63  case SBML_SPECIES_REFERENCE:
64  case SBML_MODIFIER_SPECIES_REFERENCE:
65  id = "";
66  //id = getId(dynamic_cast<const SimpleSpeciesReference*>(pS));
67  //the above should work if layout support is compiled into libsbml
68  break;
69 
70  //case SBML_COMPARTMENT_TYPE:
71  //case SBML_SPECIES_TYPE:
72  default:
73  id = "";
74  }
75 
76  return id;
77 }
static std::string getId(const CType *pA, C_INT32 level=2)
Definition: SBMLUtils.cpp:81
const char * id
Definition: stdsoap2.h:1262

The documentation for this class was generated from the following files: