Loading...
Searching...
No Matches
doc_additional_typecode_details Class Reference

## Detailed Description

  Here follow some additional general information about libSBML type codes:

- The codes are the possible return values (integers) for the following functions:
  - SBase::getTypeCode()
  - ListOf::getItemTypeCode()
  (Compatibility note: in libSBML 5, the type of return values of these functions changed from an enumeration to an integer for extensibility in the face of different programming languages.)

- Each package extension must define similar sets of values for each SBase subclass (e.g. `SBMLLayoutTypeCode_t` for the SBML Level 3 Layout extension, `SBMLFbcTypeCode_t` for the SBML Level 3 Flux Balance Constraints extension, etc.).

- The value of each package-specific type code can be duplicated between those of different packages. (This is necessary because the development of libSBML extensions for different SBML packages may be undertaken by different developers at different times; requiring the developers to coordinate their use of type codes would be nettlesome and probably doomed to failure.)

- To distinguish between the type codes of different packages, both the return value of SBase::getTypeCode() and SBase::getPackageName() must be checked. This is particularly important for functions that take an SBML type code as an argument, such as SBase::getAncestorOfType( ), which by default assumes you are handing it a core type, and will return `NULL` if the value you give it is actually from a package.

The following example code illustrates the combined use of SBase::getPackageName() and SBase::getTypeCode():

def example(item):
pkg_name = item.getPackageName()
type_code = item.getTypeCode()
if pkg_name == "core":
print("Got a " + SBMLTypeCode_toString(type_code, "core") + " object")
if type_code == SBML_MODEL:
print("This is a very, very nice model")
# Do whatever the application wants to do with the model.
elif type_code == SBML_COMPARTMENT:
print("This is a very, very nice compartment")
# Do whatever the application wants to do with the compartment.
elif type_code == SBML_SPECIES:
print("This is a very, very nice species")
# Do whatever the application wants to do with the species.
elif ...
...
elif pkg_name == "layout":
print("Got a " + SBMLTypeCode_toString(type_code, "layout") + " object")
if type_code == SBML_LAYOUT_POINT:
print("This is a very, very nice layout point")
# Do whatever the application wants to do with the layout point.
elif type_code == SBML_LAYOUT_BOUNDINGBOX:
print("This is a very, very nice layout bounding box")
# Do whatever the application wants to do with the layout bounding box.
elif ...
...
elif pkg_name == "unknown":
print("Something went wrong -- libSBML did not recognize the object type")
# Handle errors