1 // Copyright 2020 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // https://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef RASTER_TO_GTIFF_UTILS_H_ 16 #define RASTER_TO_GTIFF_UTILS_H_ 17 18 #include <optional> 19 #include <string> 20 21 #include "absl/strings/string_view.h" 22 23 namespace gdal::sandbox::utils { 24 25 // RAII wrapper that creates temporary file and automatically unlinks it 26 class TempFile { 27 public: 28 explicit TempFile(absl::string_view prefix); 29 TempFile(const TempFile&) = delete; 30 TempFile& operator=(const TempFile&) = delete; 31 TempFile(TempFile&&) = delete; 32 TempFile& operator=(TempFile&&) = delete; 33 ~TempFile(); 34 35 bool HasValue() const; 36 int GetFd() const; 37 std::string GetPath() const; 38 39 private: 40 std::optional<std::pair<std::string, int>> file_data_ = std::nullopt; 41 }; 42 43 // Helper function to retrieve potential proj.db path from environment variable 44 std::optional<std::string> FindProjDbPath(); 45 46 // Tries to get test folder path from the TEST_SRCDIR environment variable and 47 // uses CWD path otherwise to join it with the testdata_path 48 std::string GetTestDataPath(absl::string_view testdata_path); 49 50 } // namespace gdal::sandbox::utils 51 52 #endif // RASTER_TO_GTIFF_UTILS_H_ 53