base_data_class.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 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 LIBMCELL_API_BASE_DATA_CLASS_H_
  12. #define LIBMCELL_API_BASE_DATA_CLASS_H_
  13. #include "api/api_common.h"
  14. #include "api/base_export_class.h"
  15. namespace MCell {
  16. namespace API {
  17. class PythonExportContext;
  18. // base class for all classes that hold the model input data
  19. class BaseDataClass: public BaseExportClass {
  20. public:
  21. BaseDataClass()
  22. : class_name(STR_UNSET), name(STR_UNSET), initialized(false), cached_data_are_uptodate(false) {
  23. }
  24. virtual ~BaseDataClass() {
  25. }
  26. // we are storing class name for reporting
  27. std::string class_name;
  28. virtual void set_class_name(const std::string& class_name_) {
  29. class_name = class_name_;
  30. }
  31. virtual const std::string& get_class_name() const {
  32. return class_name;
  33. }
  34. // every object defined by the MCell API might have its name
  35. std::string name;
  36. virtual void set_name(const std::string& name_) {
  37. cached_data_are_uptodate = false;
  38. name = name_;
  39. }
  40. virtual const std::string& get_name() const {
  41. cached_data_are_uptodate = false; // might be modified in theory
  42. return name;
  43. }
  44. bool initialized;
  45. virtual void set_initialized() = 0;
  46. // attribute used when some caching is employed
  47. mutable bool cached_data_are_uptodate;
  48. // this method is used to identify this particular object in error messages
  49. virtual std::string get_object_name() const {
  50. return get_class_name() + " '" + get_name() + "'";
  51. }
  52. // empty implementation, to be overridden in actual derived classes
  53. virtual void postprocess_in_ctor() { };
  54. // empty implementation, to be overridden in actual derived classes
  55. virtual void check_semantics() const { };
  56. // empty implementation, to be overridden in actual derived classes
  57. virtual std::string to_str(const bool all_details=false, const std::string ind="") const {
  58. assert(false);
  59. return "String dump for a derived class is not implemented.";
  60. }
  61. // initialization for custom constructors
  62. virtual void set_all_attributes_as_default_or_unset() {
  63. name = STR_UNSET;
  64. initialized = false;
  65. cached_data_are_uptodate = false;
  66. };
  67. // calls virtual method, usually no need to override
  68. virtual void dump() const {
  69. std::cout << to_str() << "\n";
  70. }
  71. };
  72. } // namespace API
  73. } // namespace MCell
  74. #endif /* LIBMCELL_API_BASE_DATA_CLASS_H_ */