gen_region.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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_REGION_H
  12. #define API_GEN_REGION_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Region;
  18. class PythonExportContext;
  19. #define REGION_CTOR() \
  20. Region( \
  21. const RegionNodeType node_type_ = RegionNodeType::UNSET, \
  22. std::shared_ptr<Region> left_node_ = nullptr, \
  23. std::shared_ptr<Region> right_node_ = nullptr \
  24. ) { \
  25. class_name = "Region"; \
  26. node_type = node_type_; \
  27. left_node = left_node_; \
  28. right_node = right_node_; \
  29. postprocess_in_ctor(); \
  30. check_semantics(); \
  31. } \
  32. Region(DefaultCtorArgType) : \
  33. GenRegion(DefaultCtorArgType()) { \
  34. set_all_attributes_as_default_or_unset(); \
  35. set_all_custom_attributes_to_default(); \
  36. }
  37. class GenRegion: public BaseDataClass {
  38. public:
  39. GenRegion() {
  40. }
  41. GenRegion(DefaultCtorArgType) {
  42. }
  43. void postprocess_in_ctor() override {}
  44. void check_semantics() const override;
  45. void set_initialized() override;
  46. void set_all_attributes_as_default_or_unset() override;
  47. std::shared_ptr<Region> copy_region() const;
  48. std::shared_ptr<Region> deepcopy_region(py::dict = py::dict()) const;
  49. virtual bool __eq__(const Region& other) const;
  50. virtual bool eq_nonarray_attributes(const Region& other, const bool ignore_name = false) const;
  51. bool operator == (const Region& other) const { return __eq__(other);}
  52. bool operator != (const Region& other) const { return !__eq__(other);}
  53. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  54. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  55. // --- attributes ---
  56. RegionNodeType node_type;
  57. virtual void set_node_type(const RegionNodeType new_node_type_) {
  58. if (initialized) {
  59. throw RuntimeError("Value 'node_type' of object with name " + name + " (class " + class_name + ") "
  60. "cannot be set after model was initialized.");
  61. }
  62. cached_data_are_uptodate = false;
  63. node_type = new_node_type_;
  64. }
  65. virtual RegionNodeType get_node_type() const {
  66. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  67. return node_type;
  68. }
  69. std::shared_ptr<Region> left_node;
  70. virtual void set_left_node(std::shared_ptr<Region> new_left_node_) {
  71. if (initialized) {
  72. throw RuntimeError("Value 'left_node' of object with name " + name + " (class " + class_name + ") "
  73. "cannot be set after model was initialized.");
  74. }
  75. cached_data_are_uptodate = false;
  76. left_node = new_left_node_;
  77. }
  78. virtual std::shared_ptr<Region> get_left_node() const {
  79. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  80. return left_node;
  81. }
  82. std::shared_ptr<Region> right_node;
  83. virtual void set_right_node(std::shared_ptr<Region> new_right_node_) {
  84. if (initialized) {
  85. throw RuntimeError("Value 'right_node' of object with name " + name + " (class " + class_name + ") "
  86. "cannot be set after model was initialized.");
  87. }
  88. cached_data_are_uptodate = false;
  89. right_node = new_right_node_;
  90. }
  91. virtual std::shared_ptr<Region> get_right_node() const {
  92. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  93. return right_node;
  94. }
  95. // --- methods ---
  96. virtual std::shared_ptr<Region> __add__(std::shared_ptr<Region> other) = 0;
  97. virtual std::shared_ptr<Region> __sub__(std::shared_ptr<Region> other) = 0;
  98. virtual std::shared_ptr<Region> __mul__(std::shared_ptr<Region> other) = 0;
  99. }; // GenRegion
  100. class Region;
  101. py::class_<Region> define_pybinding_Region(py::module& m);
  102. } // namespace API
  103. } // namespace MCell
  104. #endif // API_GEN_REGION_H