$darkmode
xdg.hpp File Reference
#include <filesystem>
#include <functional>
#include <string>
#include <vector>
Include dependency graph for xdg.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum class  cloe::utility::XdgError { RELATIVE_XDG_PATH , HOME_UNSET , EMPTY_DEFAULT }
 

Functions

std::filesystem::path cloe::utility::xdg_getenv_path (const std::string &env)
 
std::filesystem::path cloe::utility::xdg_path (const std::string &env, const std::filesystem::path &default_path)
 
std::vector< std::filesystem::path > cloe::utility::xdg_paths (const std::string &env, const std::string &default_paths)
 
std::filesystem::path cloe::utility::xdg_find (const std::filesystem::path &file, const std::vector< std::filesystem::path > &dirs)
 
std::vector< std::filesystem::path > cloe::utility::xdg_findall (const std::filesystem::path &file, const std::vector< std::filesystem::path > &dirs)
 
void cloe::utility::xdg_merge (const std::filesystem::path &file, const std::vector< std::filesystem::path > &dirs, bool reverse, const std::function< bool(const std::filesystem::path &)> &mergefn)
 
std::filesystem::path cloe::utility::config_home ()
 User configuration base directory, e.g., ~./config.
 
std::filesystem::path cloe::utility::data_home ()
 User data files base directory, e.g., ~/.local/share.
 
std::filesystem::path cloe::utility::cache_home ()
 User cache files base directory, e.g., ~/.cache.
 
std::filesystem::path cloe::utility::runtime_dir ()
 User runtime files base directory, e.g., /run/user/1000
 
std::vector< std::filesystem::path > cloe::utility::config_dirs ()
 Global configuration directories, e.g., /etc/xdg.
 
std::vector< std::filesystem::path > cloe::utility::data_dirs ()
 Global data files directories, e.g., /usr/local/share.
 
std::vector< std::filesystem::path > cloe::utility::all_config_dirs ()
 User and global configuration directories.
 
std::vector< std::filesystem::path > cloe::utility::all_data_dirs ()
 User and global data directories.
 
std::filesystem::path cloe::utility::user_config (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::user_data (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::user_cache (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::user_runtime (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::find_config (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::find_data (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::find_cache (const std::filesystem::path &file)
 
std::filesystem::path cloe::utility::find_runtime (const std::filesystem::path &file)
 
std::vector< std::filesystem::path > cloe::utility::find_all_config (const std::filesystem::path &file)
 
std::vector< std::filesystem::path > cloe::utility::find_all_data (const std::filesystem::path &file)
 
void cloe::utility::merge_config (const std::filesystem::path &file, const std::function< bool(const std::filesystem::path &)> &mergefn, bool reverse=false)
 
void cloe::utility::merge_data (const std::filesystem::path &file, const std::function< bool(const std::filesystem::path &)> &mergefn, bool reverse=false)
 

Detailed Description

See also
cloe/utility/xdg.cpp

This file implements the basic XDG specification, as specified here.

Inspiration for the API of this library taken from https://github.com/goulash/xdg.

Enumeration Type Documentation

◆ XdgError

This enum class contains all the exceptions that can be thrown.

Enumerator
RELATIVE_XDG_PATH 

This error is thrown when we encounter a relative path where we expect an absolute path, but only if the THROW_RELATIVE_XDG_PATH_ERROR is defined.

The XDG specification states:

All paths set in these environment variables must be absolute. If an
implementation encounters a relative path in any of these variables
it should consider the path invalid and ignore it.
HOME_UNSET 

When the HOME environment variable is unset, path expansion cannot occur, and we throw this error.

EMPTY_DEFAULT 

When no default can be provided, then an environment variable MUST be set, and we have no reasonable fallback.