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 a singleton pattern to register the gdal driver once in one place #4628
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
733a332
fixes #4623
kevinkreiser 56c6a5e
Merge remote-tracking branch 'origin/master' into kk_initgdalsingleton
kevinkreiser c8ff6d9
lint
kevinkreiser 6b81a83
changelog and unbreak gdal off
kevinkreiser da5c7de
Update CMakeLists.txt
kevinkreiser 82e11dd
technically dont need these but we're relying on them happening somew…
kevinkreiser File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,23 @@ | |
using namespace valhalla::baldr::json; | ||
|
||
namespace { | ||
|
||
// allows us to only ever register the driver once per process without having to put it | ||
// in every executable that might call into this code | ||
struct gdal_singleton_t { | ||
static const gdal_singleton_t& get() { | ||
static const gdal_singleton_t instance; | ||
return instance; | ||
} | ||
|
||
private: | ||
gdal_singleton_t() { | ||
#ifdef ENABLE_GDAL | ||
GDALRegister_GTiff(); | ||
#endif | ||
} | ||
}; | ||
|
||
using rgba_t = std::tuple<float, float, float>; | ||
|
||
using namespace valhalla; | ||
|
@@ -169,7 +186,7 @@ std::string serializeGeoTIFF(Api& request, const std::shared_ptr<const GriddedDa | |
char** geotiff_options = NULL; | ||
geotiff_options = CSLSetNameValue(geotiff_options, "COMPRESS", "PACKBITS"); | ||
|
||
// TODO: check if there's an easy way to only instantiate the driver once | ||
gdal_singleton_t::get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this first time this is called (per process) the constructor above is called and the driver registration happens. subsequent calls are no-ops |
||
auto driver_manager = GetGDALDriverManager(); | ||
auto geotiff_driver = driver_manager->GetDriverByName("GTiff"); | ||
auto geotiff_dataset = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought it would be better to default turning it ON if we can and if we couldnt we simply report that was the case. if you tell it you definitely dont want it by setting it to OFF then we dont even try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm but doesn’t OFF still want to pull in GDAL::GDAL in tyr’s cmakelists? That’s what that variable was for, though you could handle that with a cmake expression in tyr as well, that’s probably more explicit than the previous var
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep will do that real quick