Add Selection API for thread-safe Get() operations #4843
+761
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is essentially a proposal for an external API that gets us closer to "thread safety". (I.E. it at least creates the possibility of a thread-safe Get() operation subject to a number of other assumptions (metadata loaded and read-only, engine-specific Get() implementations cooperating, etc. The core of this is a Selection class that can be used two ways, either fluent or mutating. Internally this will be passed to calls like Get() and SelectionSize() that currently operate on values built up in the Variable class with calls like Var.SetBlock(). No existing APIs will be deprecated, only a few new calls created. Examples below:
// Mutating style with Set* calls
Selection sel;
sel.SetBlock(3);
sel.SetAccuracy({0.01, 0.0, false});
std::vector data;
engine.Get(var, data, sel);
// Fluent style
std::vector data;
engine.Get(var, data, Selection::Block(3).WithAccuracy({0.01, 0.0, false}));
// Pre-allocated buffer with raw pointer
auto sel = Selection::BoundingBox({0, 0}, {10, 20});
double *data = (double *)malloc(var.SelectionSize(sel) * sizeof(double));
engine.Get(var, data, sel);
Note that nothing here is complete. The implementation for any particular engine subclass would have to come later and may not make sense for non-current engines.