Skip to content

Commit

Permalink
Const ref observable.name() and observable.model_description()
Browse files Browse the repository at this point in the history
  • Loading branch information
eidekrist committed Jun 23, 2020
1 parent 23ddc11 commit 1ce83fd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/cosim/observer/observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class observable
{
public:
/// Returns the entity's name.
virtual std::string name() const = 0;
virtual const std::string& name() const = 0;

/// Returns a description of the entity.
virtual cosim::model_description model_description() const = 0;
virtual const cosim::model_description& model_description() const = 0;

/**
* Exposes a variable for retrieval with `get_xxx()`.
Expand Down
11 changes: 7 additions & 4 deletions src/cosim/observer/file_observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class file_observer::slave_value_writer
void initialize_default()
{
if (!timeStampedFileNames_) {
const auto filePath = logDir_ / observable_->name().append(".csv");
auto name = observable_->name();
const auto filePath = logDir_ / name.append(".csv");
clear_file_contents_if_exists(filePath, fsw_);
}

Expand All @@ -179,7 +180,8 @@ class file_observer::slave_value_writer
void initialize_config(const std::vector<variable_description>& variables)
{
if (!timeStampedFileNames_) {
const auto filePath = logDir_ / observable_->name().append(".csv");
auto name = observable_->name();
const auto filePath = logDir_ / name.append(".csv");
clear_file_contents_if_exists(filePath, fsw_);
}

Expand All @@ -191,11 +193,12 @@ class file_observer::slave_value_writer
void create_log_file()
{
std::string filename;
auto name = observable_->name();
if (!timeStampedFileNames_) {
filename = observable_->name().append(".csv");
filename = name.append(".csv");
} else {
auto time_str = format_time(boost::posix_time::microsec_clock::local_time());
filename = observable_->name().append("_").append(time_str).append(".csv");
filename = name.append("_").append(time_str).append(".csv");
}

const auto filePath = logDir_ / filename;
Expand Down
8 changes: 4 additions & 4 deletions src/cosim/slave_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,12 @@ class slave_simulator::impl

impl& operator=(impl&&) noexcept = delete;

std::string name() const
const std::string& name() const
{
return name_;
}

cosim::model_description model_description() const
const cosim::model_description& model_description() const
{
return modelDescription_;
}
Expand Down Expand Up @@ -561,13 +561,13 @@ slave_simulator::slave_simulator(slave_simulator&&) noexcept = default;
slave_simulator& slave_simulator::operator=(slave_simulator&&) noexcept = default;


std::string slave_simulator::name() const
const std::string& slave_simulator::name() const
{
return pimpl_->name();
}


cosim::model_description slave_simulator::model_description() const
const cosim::model_description& slave_simulator::model_description() const
{
return pimpl_->model_description();
}
Expand Down
4 changes: 2 additions & 2 deletions src/cosim/slave_simulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class slave_simulator : public simulator
slave_simulator& operator=(slave_simulator&&) noexcept;

// `observable` methods
std::string name() const override;
cosim::model_description model_description() const override;
const std::string& name() const override;
const cosim::model_description& model_description() const override;

void expose_for_getting(variable_type type, value_reference ref) override;
double get_real(value_reference reference) const override;
Expand Down

0 comments on commit 1ce83fd

Please sign in to comment.