Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Sender constructors and expose ability to Courier::Sender::set_parent_pointer #43

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions include/btwxt/grid-axis.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ class GridAxis : public Courier::Sender {
extrapolation_limits = limits;
check_extrapolation_limits();
}

void set_courier(std::shared_ptr<Courier::Courier> courier_in)
{
courier = std::move(courier_in);
}
std::shared_ptr<Courier::Courier> get_courier() { return courier; };


// Getters
[[nodiscard]] const std::vector<double>& get_values() const { return values; }
[[nodiscard]] std::size_t get_length() const { return values.size(); }
Expand Down
2 changes: 2 additions & 0 deletions include/btwxt/regular-grid-interpolator.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ class RegularGridInterpolator {

std::shared_ptr<Courier::Courier> get_courier();

void set_parent_pointer(Courier::Sender* parent_pointer);

private:
std::unique_ptr<RegularGridInterpolatorImplementation> implementation;
};
Expand Down
3 changes: 1 addition & 2 deletions src/grid-axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ GridAxis::GridAxis(std::vector<double> values_in,
std::pair<double, double> extrapolation_limits,
std::string name,
const std::shared_ptr<Courier::Courier>& courier_in)
: Courier::Sender(std::move(name), courier_in)
: Courier::Sender("GridAxis", std::move(name), courier_in)
, values(std::move(values_in))
, interpolation_method(interpolation_method)
, extrapolation_method(extrapolation_method)
, extrapolation_limits(std::move(extrapolation_limits))
, cubic_spacing_ratios(
2, std::vector<double>(std::max(static_cast<int>(values.size()) - 1, 0), 1.0))
{
class_name = "GridAxis";
if (values.empty()) {
send_error("Cannot create grid axis from a zero-length vector.");
}
Expand Down
5 changes: 2 additions & 3 deletions src/regular-grid-interpolator-implementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RegularGridInterpolatorImplementation::RegularGridInterpolatorImplementation(
const std::vector<GridPointDataSet>& grid_point_data_sets,
std::string name,
const std::shared_ptr<Courier::Courier>& courier)
: Courier::Sender(std::move(name), courier)
: Courier::Sender("RegularGridInterpolator", std::move(name), courier)
, grid_axes(grid_axes)
, grid_point_data_sets(grid_point_data_sets)
, number_of_grid_point_data_sets(grid_point_data_sets.size())
Expand All @@ -44,7 +44,6 @@ RegularGridInterpolatorImplementation::RegularGridInterpolatorImplementation(
, interpolation_coefficients(number_of_grid_axes, std::vector<double>(2, 0.))
, cubic_slope_coefficients(number_of_grid_axes, std::vector<double>(2, 0.))
{
class_name = "RegularGridInterpolator";
setup();
}

Expand Down Expand Up @@ -349,7 +348,7 @@ void RegularGridInterpolatorImplementation::setup()
void RegularGridInterpolatorImplementation::set_axes_parent_pointers()
{
for (auto& grid_axis : grid_axes) {
grid_axis.parent_pointer = this;
grid_axis.set_parent_pointer(this);
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/regular-grid-interpolator-implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ class RegularGridInterpolatorImplementation : public Courier::Sender {
return grid_axes[axis_index].get_extrapolation_limits();
};

[[nodiscard]] inline std::shared_ptr<Courier::Courier> get_courier() const { return courier; };

[[nodiscard]] inline std::size_t get_number_of_grid_axes() const
{
return number_of_grid_axes;
Expand Down
5 changes: 5 additions & 0 deletions src/regular-grid-interpolator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,9 @@ std::shared_ptr<Courier::Courier> RegularGridInterpolator::get_courier()
return implementation->get_courier();
}

void RegularGridInterpolator::set_parent_pointer(Courier::Sender* parent_pointer_in)
{
implementation->set_parent_pointer(parent_pointer_in);
}

} // namespace Btwxt
31 changes: 31 additions & 0 deletions test/btwxt-tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,37 @@ TEST_F(Grid2DFixture, courier_modify_context)
EXPECT_STDOUT(EXPECT_THROW(interpolator.get_target(), std::runtime_error);, expected_error)
}

TEST_F(Grid2DFixture, courier_parent_pointer)
{
class ParentClass : public Courier::Sender {
public:
explicit ParentClass(std::string name_in,
const std::shared_ptr<Courier::Courier>& courier_in =
std::make_shared<Courier::DefaultCourier>())
: Courier::Sender("ParentClass", std::move(name_in), courier_in)
{
}
RegularGridInterpolator rgi;
};

ParentClass my_parent_object("My Parent Object", interpolator.get_courier());
my_parent_object.rgi = interpolator;
my_parent_object.rgi.set_parent_pointer(&my_parent_object);

std::string expected_error = " [ERROR] ParentClass 'My Parent Object': "
"RegularGridInterpolator 'Test RGI': The current target "
"was requested, but no target has been set.\n";
EXPECT_STDOUT(EXPECT_THROW(my_parent_object.rgi.get_target(), std::runtime_error);
, expected_error)
std::dynamic_pointer_cast<CourierWithContext>(my_parent_object.rgi.get_courier())->context =
"Context 1";
expected_error = " [ERROR] Context 1: ParentClass 'My Parent Object': RegularGridInterpolator "
"'Test RGI': The current target "
"was requested, but no target has been set.\n";
EXPECT_STDOUT(EXPECT_THROW(my_parent_object.rgi.get_target(), std::runtime_error);
, expected_error)
}

TEST_F(Grid2DFixture, unique_courier_per_rgi_instance)
{
std::vector<double> returned_target;
Expand Down
2 changes: 1 addition & 1 deletion vendor/courier
Loading