base_introspection_class.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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_INTROSPECTION_CLASS_H_
  12. #define LIBMCELL_API_BASE_INTROSPECTION_CLASS_H_
  13. #include "api/api_common.h"
  14. #include "base_data_class.h"
  15. namespace MCell {
  16. class World;
  17. namespace API {
  18. // base class for all classes that hold the model input data
  19. class BaseIntrospectionClass: public BaseDataClass {
  20. public:
  21. BaseIntrospectionClass()
  22. : world(nullptr) {
  23. name = INTROSPECTED_OBJECT;
  24. // - introspected objects are assumed to be initialized because they are returned
  25. // by API methods and this does not depend on model initialization
  26. // - this flag is checked in set_* methods and must be true to avoid ignoring writes to attributes
  27. initialized = true;
  28. }
  29. virtual ~BaseIntrospectionClass() {
  30. }
  31. void check_initialization() const {
  32. if (world == nullptr) {
  33. throw RuntimeError(
  34. "Object of class " + class_name + " was not correctly initialized. "
  35. "Introspection objects cannot be created independently. they must always be retrieved through "
  36. "methods of the " + NAME_CLASS_MODEL + " class."
  37. );
  38. }
  39. }
  40. void set_all_attributes_as_default_or_unset() {
  41. BaseDataClass::set_all_attributes_as_default_or_unset();
  42. world = nullptr;
  43. }
  44. // internal World pointer
  45. World* world;
  46. };
  47. } // namespace API
  48. } // namespace MCell
  49. #endif /* LIBMCELL_API_BASE_INTROSPECTION_CLASS_H_ */