compartment_utils.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 API_COMPARTMENT_UTILS_H
  12. #define API_COMPARTMENT_UTILS_H
  13. #include <string>
  14. #include <map>
  15. #include <vector>
  16. #include <memory>
  17. namespace MCell {
  18. namespace API {
  19. class GeometryObject;
  20. void set_parent_and_children_compartments(
  21. std::vector<std::shared_ptr<API::GeometryObject>>& compartment_objects);
  22. // used also from data model converter
  23. static void get_compartment_names(const std::string& bngl_string, std::vector<std::string>& compartments) {
  24. size_t i = 0;
  25. bool in_compartment = false;
  26. std::string current_name;
  27. while (i < bngl_string.size()) {
  28. char c = bngl_string[i];
  29. if (c == '@') {
  30. assert(!in_compartment);
  31. in_compartment = true;
  32. }
  33. else if (in_compartment) {
  34. if ((!isalnum(c) && c != '_')) {
  35. compartments.push_back(current_name);
  36. current_name = "";
  37. in_compartment = false;
  38. }
  39. else {
  40. current_name += c;
  41. }
  42. }
  43. i++;
  44. }
  45. if (current_name != "") {
  46. compartments.push_back(current_name);
  47. }
  48. }
  49. } // namespace API
  50. } // namespace MCell
  51. #endif // API_COMPARTMENT_UTILS_H