Program Listing for File data.hpp

Return to documentation for file (src/navtk/utils/data.hpp)

#pragma once

#include <fstream>
#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <navtk/errors.hpp>

#define NAVTK_DATA_DIR_ENV_VAR "NAVTK_DATA_DIR"

#define NAVTK_DATA_FILE_ENV_VAR_PREFIX "NAVTK_"

#define NAVTK_DATA_FILE_ENV_VAR_SUFFIX "_PATH"

#define NAVTK_OS_DATA_DIR_SUBFOLDER_NAME "navtk"

namespace navtk {
namespace utils {

// This is exposed in the API rather than forward-declared because it's used by the Python bindings
// to reimplement navtk::utils::open_data_file in terms of Python file objects rather than
// ifstreams.
namespace detail {

void visit_possible_file_paths(ErrorMode error_mode,
                               const std::string& label,
                               const std::string& basename,
                               std::function<bool(const std::string&)> try_path);

}  // namespace detail


// The odd quoting syntax in this docstring ``%%APPDATA% `` is a workaround for a bug in Exhale
// that swallows the leading % in Windows environment variable names otherwise.
std::shared_ptr<std::ifstream> open_data_file(ErrorMode error_mode,
                                              const std::string& label,
                                              const std::string& basename,
                                              std::ios_base::openmode mode = std::ios_base::in);

#ifndef NEED_DOXYGEN_EXHALE_WORKAROUND

std::shared_ptr<std::ifstream> open_data_file(const std::string& label,
                                              const std::string& basename,
                                              std::ios_base::openmode mode = std::ios_base::in);
#endif

}  // namespace utils
}  // namespace navtk