gen_rng_state.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_RNG_STATE_H
  12. #define API_GEN_RNG_STATE_H
  13. #include "api/api_common.h"
  14. #include "api/base_data_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class RngState;
  18. class PythonExportContext;
  19. #define RNG_STATE_CTOR() \
  20. RngState( \
  21. const uint64_t randcnt_, \
  22. const uint64_t aa_, \
  23. const uint64_t bb_, \
  24. const uint64_t cc_, \
  25. const std::vector<uint64_t> randslr_, \
  26. const std::vector<uint64_t> mm_, \
  27. const uint64_t rngblocks_ \
  28. ) { \
  29. class_name = "RngState"; \
  30. randcnt = randcnt_; \
  31. aa = aa_; \
  32. bb = bb_; \
  33. cc = cc_; \
  34. randslr = randslr_; \
  35. mm = mm_; \
  36. rngblocks = rngblocks_; \
  37. postprocess_in_ctor(); \
  38. check_semantics(); \
  39. } \
  40. RngState(DefaultCtorArgType) : \
  41. GenRngState(DefaultCtorArgType()) { \
  42. set_all_attributes_as_default_or_unset(); \
  43. set_all_custom_attributes_to_default(); \
  44. }
  45. class GenRngState: public BaseDataClass {
  46. public:
  47. GenRngState() {
  48. }
  49. GenRngState(DefaultCtorArgType) {
  50. }
  51. void postprocess_in_ctor() override {}
  52. void check_semantics() const override;
  53. void set_initialized() override;
  54. void set_all_attributes_as_default_or_unset() override;
  55. std::shared_ptr<RngState> copy_rng_state() const;
  56. std::shared_ptr<RngState> deepcopy_rng_state(py::dict = py::dict()) const;
  57. virtual bool __eq__(const RngState& other) const;
  58. virtual bool eq_nonarray_attributes(const RngState& other, const bool ignore_name = false) const;
  59. bool operator == (const RngState& other) const { return __eq__(other);}
  60. bool operator != (const RngState& other) const { return !__eq__(other);}
  61. std::string to_str(const bool all_details=false, const std::string ind="") const override;
  62. std::string export_to_python(std::ostream& out, PythonExportContext& ctx) override;
  63. virtual std::string export_vec_randslr(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  64. virtual std::string export_vec_mm(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  65. // --- attributes ---
  66. uint64_t randcnt;
  67. virtual void set_randcnt(const uint64_t new_randcnt_) {
  68. if (initialized) {
  69. throw RuntimeError("Value 'randcnt' of object with name " + name + " (class " + class_name + ") "
  70. "cannot be set after model was initialized.");
  71. }
  72. cached_data_are_uptodate = false;
  73. randcnt = new_randcnt_;
  74. }
  75. virtual uint64_t get_randcnt() const {
  76. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  77. return randcnt;
  78. }
  79. uint64_t aa;
  80. virtual void set_aa(const uint64_t new_aa_) {
  81. if (initialized) {
  82. throw RuntimeError("Value 'aa' of object with name " + name + " (class " + class_name + ") "
  83. "cannot be set after model was initialized.");
  84. }
  85. cached_data_are_uptodate = false;
  86. aa = new_aa_;
  87. }
  88. virtual uint64_t get_aa() const {
  89. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  90. return aa;
  91. }
  92. uint64_t bb;
  93. virtual void set_bb(const uint64_t new_bb_) {
  94. if (initialized) {
  95. throw RuntimeError("Value 'bb' of object with name " + name + " (class " + class_name + ") "
  96. "cannot be set after model was initialized.");
  97. }
  98. cached_data_are_uptodate = false;
  99. bb = new_bb_;
  100. }
  101. virtual uint64_t get_bb() const {
  102. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  103. return bb;
  104. }
  105. uint64_t cc;
  106. virtual void set_cc(const uint64_t new_cc_) {
  107. if (initialized) {
  108. throw RuntimeError("Value 'cc' of object with name " + name + " (class " + class_name + ") "
  109. "cannot be set after model was initialized.");
  110. }
  111. cached_data_are_uptodate = false;
  112. cc = new_cc_;
  113. }
  114. virtual uint64_t get_cc() const {
  115. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  116. return cc;
  117. }
  118. std::vector<uint64_t> randslr;
  119. virtual void set_randslr(const std::vector<uint64_t> new_randslr_) {
  120. if (initialized) {
  121. throw RuntimeError("Value 'randslr' of object with name " + name + " (class " + class_name + ") "
  122. "cannot be set after model was initialized.");
  123. }
  124. cached_data_are_uptodate = false;
  125. randslr = new_randslr_;
  126. }
  127. virtual std::vector<uint64_t>& get_randslr() {
  128. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  129. return randslr;
  130. }
  131. std::vector<uint64_t> mm;
  132. virtual void set_mm(const std::vector<uint64_t> new_mm_) {
  133. if (initialized) {
  134. throw RuntimeError("Value 'mm' of object with name " + name + " (class " + class_name + ") "
  135. "cannot be set after model was initialized.");
  136. }
  137. cached_data_are_uptodate = false;
  138. mm = new_mm_;
  139. }
  140. virtual std::vector<uint64_t>& get_mm() {
  141. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  142. return mm;
  143. }
  144. uint64_t rngblocks;
  145. virtual void set_rngblocks(const uint64_t new_rngblocks_) {
  146. if (initialized) {
  147. throw RuntimeError("Value 'rngblocks' of object with name " + name + " (class " + class_name + ") "
  148. "cannot be set after model was initialized.");
  149. }
  150. cached_data_are_uptodate = false;
  151. rngblocks = new_rngblocks_;
  152. }
  153. virtual uint64_t get_rngblocks() const {
  154. cached_data_are_uptodate = false; // arrays and other data can be modified through getters
  155. return rngblocks;
  156. }
  157. // --- methods ---
  158. }; // GenRngState
  159. class RngState;
  160. py::class_<RngState> define_pybinding_RngState(py::module& m);
  161. } // namespace API
  162. } // namespace MCell
  163. #endif // API_GEN_RNG_STATE_H