Skip to content
New issue

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

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

Already on GitHub? # to your account

[REQ] Accessing the parent Cell from a State #31

Open
jsoulier opened this issue Jan 14, 2025 · 4 comments
Open

[REQ] Accessing the parent Cell from a State #31

jsoulier opened this issue Jan 14, 2025 · 4 comments
Labels
enhancement New feature or request

Comments

@jsoulier
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Yes.

I'd like a way to print the latitude and longitude of the State from the loggers. Currently, I'm writing the lat/long into each State and printing it from there. Since the data is constant (as it is based on the cell position), it should be stored in the Cell instead. However, I can't access the Cell from the State.

Describe the solution you'd like
A way of accessing the parent Cell from a State during printing. Maybe instead of using stream operators, an explicit std::string getString(const State& state, const Cell& parentCell) in the State class would work?

Describe alternatives you've considered

  1. Storing the lat/long directly in the States

Thanks

@jsoulier jsoulier added the enhancement New feature or request label Jan 14, 2025
@romancardenas
Copy link
Member

Can you work on a PR for this? It's been a while since I don't program in C++, but if I remember correctly, it is possible to define default implementations for these functions right? I'm thinking about backward compatibility: it would be desirable if your new getString function defaults into using stream operations.

@jsoulier
Copy link
Contributor Author

Yeah I can work on a PR. But AFAIK you can't do a default implementation because States are added as template types i.e. there's no base type for a default implementation.

@jsoulier
Copy link
Contributor Author

jsoulier commented Jan 21, 2025

Looking at it now, it would be nice to be able to reference the parent cell at all times, not just while printing. My use case is I'm computing fire spread from cell A to cell B. To compute cell B, I need params from cell A (slope, fuel, etc). Since I only have state A, I need to store slope, fuel, etc in state A. Anything const should be stored in the cells to avoid duplication.

Would storing a const ref to the cell from the state be acceptable? In the state ctor, it could take a cell reference and optionally store that. This would mean removing the default ctor or using pointers instead and allow null cell pointers

@romancardenas
Copy link
Member

Give it a try. It should be OK if you don't touch the cell reference. A const pointer should work. Be careful with circular references though, they usually are the source of problems.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants