gen_count.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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_COUNT_H
  12. #define API_GEN_COUNT_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class Count;
  18. class CountTerm;
  19. class PythonExportContext;
  20. #define COUNT_CTOR() \
  21. Count( \
  22. const std::string& name_ = STR_UNSET, \
  23. const std::string& file_name_ = STR_UNSET, \
  24. std::shared_ptr<CountTerm> expression_ = nullptr, \
  25. const double multiplier_ = 1, \
  26. const double every_n_timesteps_ = 1, \
  27. const CountOutputFormat output_format_ = CountOutputFormat::AUTOMATIC_FROM_EXTENSION \
  28. ) { \
  29. class_name = "Count"; \
  30. name = name_; \
  31. file_name = file_name_; \
  32. expression = expression_; \
  33. multiplier = multiplier_; \
  34. every_n_timesteps = every_n_timesteps_; \
  35. output_format = output_format_; \
  36. postprocess_in_ctor(); \
  37. check_semantics(); \
  38. } \
  39. Count(DefaultCtorArgType) : \
  40. GenCount(DefaultCtorArgType()) { \
  41. set_all_attributes_as_default_or_unset(); \
  42. set_all_custom_attributes_to_default(); \
  43. }
  44. class GenCount: public BaseDataClass {
  45. public:
  46. GenCount() {
  47. }
  48. GenCount(DefaultCtorArgType) {
  49. }
  50. void postprocess_in_ctor() override {}
  51. void check_semantics() const override;
  52. void set_initialized() override;
  53. void set_all_attributes_as_default_or_unset() override;
  54. std::shared_ptr<Count> copy_count() const;
  55. std::shared_ptr<Count> deepcopy_count(py::dict = py::dict()) const;
  56. virtual bool __eq__(const Count& other) const;
  57. virtual bool eq_nonarray_attributes(const Count& other, const bool ignore_name = false) const;
  58. bool operator == (const Count& other) const { return __eq__(other);}
  59. bool operator != (const Count& other) const { return !__eq__(other);}
  60. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  61. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  62. // --- attributes ---
  63. std::string file_name;
  64. virtual void set_file_name(const std::string& new_file_name_) {
  65. if (initialized) {
  66. throw RuntimeError("Value 'file_name' of object with name " + name + " (class " + class_name + ") "
  67. "cannot be set after model was initialized.");
  68. }
  69. cached_data_are_uptodate = false;
  70. file_name = new_file_name_;
  71. }
  72. virtual const std::string& get_file_name() const {
  73. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  74. return file_name;
  75. }
  76. std::shared_ptr<CountTerm> expression;
  77. virtual void set_expression(std::shared_ptr<CountTerm> new_expression_) {
  78. if (initialized) {
  79. throw RuntimeError("Value 'expression' of object with name " + name + " (class " + class_name + ") "
  80. "cannot be set after model was initialized.");
  81. }
  82. cached_data_are_uptodate = false;
  83. expression = new_expression_;
  84. }
  85. virtual std::shared_ptr<CountTerm> get_expression() const {
  86. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  87. return expression;
  88. }
  89. double multiplier;
  90. virtual void set_multiplier(const double new_multiplier_) {
  91. if (initialized) {
  92. throw RuntimeError("Value 'multiplier' of object with name " + name + " (class " + class_name + ") "
  93. "cannot be set after model was initialized.");
  94. }
  95. cached_data_are_uptodate = false;
  96. multiplier = new_multiplier_;
  97. }
  98. virtual double get_multiplier() const {
  99. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  100. return multiplier;
  101. }
  102. double every_n_timesteps;
  103. virtual void set_every_n_timesteps(const double new_every_n_timesteps_) {
  104. if (initialized) {
  105. throw RuntimeError("Value 'every_n_timesteps' of object with name " + name + " (class " + class_name + ") "
  106. "cannot be set after model was initialized.");
  107. }
  108. cached_data_are_uptodate = false;
  109. every_n_timesteps = new_every_n_timesteps_;
  110. }
  111. virtual double get_every_n_timesteps() const {
  112. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  113. return every_n_timesteps;
  114. }
  115. CountOutputFormat output_format;
  116. virtual void set_output_format(const CountOutputFormat new_output_format_) {
  117. if (initialized) {
  118. throw RuntimeError("Value 'output_format' of object with name " + name + " (class " + class_name + ") "
  119. "cannot be set after model was initialized.");
  120. }
  121. cached_data_are_uptodate = false;
  122. output_format = new_output_format_;
  123. }
  124. virtual CountOutputFormat get_output_format() const {
  125. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  126. return output_format;
  127. }
  128. // --- methods ---
  129. virtual double get_current_value() = 0;
  130. }; // GenCount
  131. class Count;
  132. py::class_<Count> define_pybinding_Count(py::module& m);
  133. } // namespace API
  134. } // namespace MCell
  135. #endif // API_GEN_COUNT_H