From df379471dd2b6bf5f83ceb79c023e9aa595a7325 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 18 Jul 2019 12:19:13 -0500 Subject: [PATCH] Adding Cell accessors for name. --- include/openmc/cell.h | 8 ++++++++ src/cell.cpp | 19 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/openmc/cell.h b/include/openmc/cell.h index aadd038d30..0b219baa19 100644 --- a/include/openmc/cell.h +++ b/include/openmc/cell.h @@ -134,6 +134,14 @@ public: //! all instances is set. void set_temperature(double T, int32_t instance = -1); + //! Get the name of a cell + //! \return Cell name + std::string name() const; + + //! Set the temperature of a cell instance + //! \param[in] name Cell name + void set_name(const std::string& name); + //---------------------------------------------------------------------------- // Data members diff --git a/src/cell.cpp b/src/cell.cpp index 1242c650f5..c339a54c1f 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -252,6 +252,18 @@ Cell::set_temperature(double T, int32_t instance) } } +std::string +Cell::name() const +{ + return name_; +} + +void +Cell::set_name(const std::string& name) +{ + name_ = name; +} + //============================================================================== // CSGCell implementation //============================================================================== @@ -1085,13 +1097,14 @@ openmc_cell_get_temperature(int32_t index, const int32_t* instance, double* T) //! Get the name of a cell extern "C" int -openmc_cell_get_name(int32_t index, const char*& name) { +openmc_cell_get_name(int32_t index, char*& name) { if (index < 0 || index >= model::cells.size()) { strcpy(openmc_err_msg, "Index in cells array is out of bounds."); return OPENMC_E_OUT_OF_BOUNDS; } - name = model::cells[index]->name_.c_str(); + auto name_str = model::cells[index]->name_; + strcpy(name, name_str.c_str()); return 0; } @@ -1105,7 +1118,7 @@ openmc_cell_set_name(int32_t index, const char* name) { } std::string name_str(name); - model::cells[index]->name_ = name_str; + model::cells[index]->set_name(name_str); return 0; }