gen_component.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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_COMPONENT_H
  12. #define API_GEN_COMPONENT_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Component;
  18. class ComponentType;
  19. class PythonExportContext;
  20. #define COMPONENT_CTOR() \
  21. Component( \
  22. std::shared_ptr<ComponentType> component_type_, \
  23. const std::string& state_ = "STATE_UNSET", \
  24. const int bond_ = BOND_UNBOUND \
  25. ) { \
  26. class_name = "Component"; \
  27. component_type = component_type_; \
  28. state = state_; \
  29. bond = bond_; \
  30. postprocess_in_ctor(); \
  31. check_semantics(); \
  32. } \
  33. Component(DefaultCtorArgType) : \
  34. GenComponent(DefaultCtorArgType()) { \
  35. set_all_attributes_as_default_or_unset(); \
  36. set_all_custom_attributes_to_default(); \
  37. }
  38. class GenComponent: public BaseDataClass {
  39. public:
  40. GenComponent() {
  41. }
  42. GenComponent(DefaultCtorArgType) {
  43. }
  44. void postprocess_in_ctor() override {}
  45. void check_semantics() const override;
  46. void set_initialized() override;
  47. void set_all_attributes_as_default_or_unset() override;
  48. std::shared_ptr<Component> copy_component() const;
  49. std::shared_ptr<Component> deepcopy_component(py::dict = py::dict()) const;
  50. virtual bool __eq__(const Component& other) const;
  51. virtual bool eq_nonarray_attributes(const Component& other, const bool ignore_name = false) const;
  52. bool operator == (const Component& other) const { return __eq__(other);}
  53. bool operator != (const Component& other) const { return !__eq__(other);}
  54. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  55. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  56. // --- attributes ---
  57. std::shared_ptr<ComponentType> component_type;
  58. virtual void set_component_type(std::shared_ptr<ComponentType> new_component_type_) {
  59. if (initialized) {
  60. throw RuntimeError("Value 'component_type' of object with name " + name + " (class " + class_name + ") "
  61. "cannot be set after model was initialized.");
  62. }
  63. cached_data_are_uptodate = false;
  64. component_type = new_component_type_;
  65. }
  66. virtual std::shared_ptr<ComponentType> get_component_type() const {
  67. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  68. return component_type;
  69. }
  70. std::string state;
  71. virtual void set_state(const std::string& new_state_) {
  72. if (initialized) {
  73. throw RuntimeError("Value 'state' of object with name " + name + " (class " + class_name + ") "
  74. "cannot be set after model was initialized.");
  75. }
  76. cached_data_are_uptodate = false;
  77. state = new_state_;
  78. }
  79. virtual const std::string& get_state() const {
  80. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  81. return state;
  82. }
  83. int bond;
  84. virtual void set_bond(const int new_bond_) {
  85. if (initialized) {
  86. throw RuntimeError("Value 'bond' of object with name " + name + " (class " + class_name + ") "
  87. "cannot be set after model was initialized.");
  88. }
  89. cached_data_are_uptodate = false;
  90. bond = new_bond_;
  91. }
  92. virtual int get_bond() const {
  93. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  94. return bond;
  95. }
  96. // --- methods ---
  97. virtual std::string to_bngl_str() const = 0;
  98. }; // GenComponent
  99. class Component;
  100. py::class_<Component> define_pybinding_Component(py::module& m);
  101. } // namespace API
  102. } // namespace MCell
  103. #endif // API_GEN_COMPONENT_H