gen_elementary_molecule.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2021 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #ifndef API_GEN_ELEMENTARY_MOLECULE_H
  12. #define API_GEN_ELEMENTARY_MOLECULE_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class ElementaryMolecule;
  18. class Component;
  19. class ElementaryMoleculeType;
  20. class PythonExportContext;
  21. #define ELEMENTARY_MOLECULE_CTOR() \
  22. ElementaryMolecule( \
  23. std::shared_ptr<ElementaryMoleculeType> elementary_molecule_type_, \
  24. const std::vector<std::shared_ptr<Component>> components_ = std::vector<std::shared_ptr<Component>>(), \
  25. const std::string& compartment_name_ = STR_UNSET \
  26. ) { \
  27. class_name = "ElementaryMolecule"; \
  28. elementary_molecule_type = elementary_molecule_type_; \
  29. components = components_; \
  30. compartment_name = compartment_name_; \
  31. postprocess_in_ctor(); \
  32. check_semantics(); \
  33. } \
  34. ElementaryMolecule(DefaultCtorArgType) : \
  35. GenElementaryMolecule(DefaultCtorArgType()) { \
  36. set_all_attributes_as_default_or_unset(); \
  37. set_all_custom_attributes_to_default(); \
  38. }
  39. class GenElementaryMolecule: public BaseDataClass {
  40. public:
  41. GenElementaryMolecule() {
  42. }
  43. GenElementaryMolecule(DefaultCtorArgType) {
  44. }
  45. void postprocess_in_ctor() override {}
  46. void check_semantics() const override;
  47. void set_initialized() override;
  48. void set_all_attributes_as_default_or_unset() override;
  49. std::shared_ptr<ElementaryMolecule> copy_elementary_molecule() const;
  50. std::shared_ptr<ElementaryMolecule> deepcopy_elementary_molecule(py::dict = py::dict()) const;
  51. virtual bool __eq__(const ElementaryMolecule& other) const;
  52. virtual bool eq_nonarray_attributes(const ElementaryMolecule& other, const bool ignore_name = false) const;
  53. bool operator == (const ElementaryMolecule& other) const { return __eq__(other);}
  54. bool operator != (const ElementaryMolecule& other) const { return !__eq__(other);}
  55. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  56. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  57. virtual std::string export_vec_components(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  58. // --- attributes ---
  59. std::shared_ptr<ElementaryMoleculeType> elementary_molecule_type;
  60. virtual void set_elementary_molecule_type(std::shared_ptr<ElementaryMoleculeType> new_elementary_molecule_type_) {
  61. if (initialized) {
  62. throw RuntimeError("Value 'elementary_molecule_type' of object with name " + name + " (class " + class_name + ") "
  63. "cannot be set after model was initialized.");
  64. }
  65. cached_data_are_uptodate = false;
  66. elementary_molecule_type = new_elementary_molecule_type_;
  67. }
  68. virtual std::shared_ptr<ElementaryMoleculeType> get_elementary_molecule_type() const {
  69. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  70. return elementary_molecule_type;
  71. }
  72. std::vector<std::shared_ptr<Component>> components;
  73. virtual void set_components(const std::vector<std::shared_ptr<Component>> new_components_) {
  74. if (initialized) {
  75. throw RuntimeError("Value 'components' of object with name " + name + " (class " + class_name + ") "
  76. "cannot be set after model was initialized.");
  77. }
  78. cached_data_are_uptodate = false;
  79. components = new_components_;
  80. }
  81. virtual std::vector<std::shared_ptr<Component>>& get_components() {
  82. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  83. return components;
  84. }
  85. std::string compartment_name;
  86. virtual void set_compartment_name(const std::string& new_compartment_name_) {
  87. if (initialized) {
  88. throw RuntimeError("Value 'compartment_name' of object with name " + name + " (class " + class_name + ") "
  89. "cannot be set after model was initialized.");
  90. }
  91. cached_data_are_uptodate = false;
  92. compartment_name = new_compartment_name_;
  93. }
  94. virtual const std::string& get_compartment_name() const {
  95. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  96. return compartment_name;
  97. }
  98. // --- methods ---
  99. virtual std::string to_bngl_str(const bool with_compartment = true) const = 0;
  100. }; // GenElementaryMolecule
  101. class ElementaryMolecule;
  102. py::class_<ElementaryMolecule> define_pybinding_ElementaryMolecule(py::module& m);
  103. } // namespace API
  104. } // namespace MCell
  105. #endif // API_GEN_ELEMENTARY_MOLECULE_H