Skip to content

Commit

Permalink
Avoid using pointers in c++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
Popov-Dmitriy-Ivanovich committed Dec 23, 2023
1 parent 5d8156a commit d48bb1b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/core/algorithms/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ class Algorithm {
[[nodiscard]] std::unordered_set<std::string_view> GetPossibleOptions() const;
[[nodiscard]] std::string_view GetDescription(std::string_view option_name) const;

std::unordered_map<std::string_view, std::unique_ptr<config::OptValue>> GetOptValues() {
std::unordered_map<std::string_view, std::unique_ptr<config::OptValue>> opt_values;
std::unordered_map<std::string_view, config::OptValue> GetOptValues() {
std::unordered_map<std::string_view, config::OptValue> opt_values;
for (auto& [name, option] : possible_options_) {
if (option->IsSet()) {
opt_values[name] = option->GetOptValue();
opt_values.try_emplace(name, option->GetOptValue());
}
}
return opt_values;
Expand Down
2 changes: 1 addition & 1 deletion src/core/config/ioption.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IOption {
[[nodiscard]] virtual std::string_view GetDescription() const = 0;
[[nodiscard]] virtual std::type_index GetTypeIndex() const = 0;
virtual ~IOption() = default;
virtual std::unique_ptr<OptValue> GetOptValue() = 0;
virtual OptValue GetOptValue() = 0;
};

} // namespace config
5 changes: 2 additions & 3 deletions src/core/config/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ class Option : public IOption {
return *this;
}

std::unique_ptr<OptValue> GetOptValue() override {
return std::make_unique<OptValue>(
OptValue{std::type_index(typeid(T)), boost::any(*value_ptr_)});
OptValue GetOptValue() override {
return OptValue{std::type_index(typeid(T)), boost::any(*value_ptr_)};
}

private:
Expand Down
1 change: 1 addition & 0 deletions src/python_bindings/opt_to_py.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "opt_to_py.h"

namespace {
namespace py = pybind11;
using ConvFunction = std::function<py::object(boost::any)>;
Expand Down
2 changes: 1 addition & 1 deletion src/python_bindings/py_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class PyAlgorithmBase {
if (name == config::names::kTable) {
continue;
}
res[std::string(name)] = opt_to_py(value_info->type, value_info->value);
res[std::string(name)] = opt_to_py(value_info.type, value_info.value);
}
return res;
}
Expand Down

0 comments on commit d48bb1b

Please sign in to comment.