libappdirs: C++ appdirs Interface

The libappdirs library provides an interface at the C++ level to the values in ChimeraX’s Python appdirs object. You link against the library with -L$(shlibdir) -lappdirs in your Makefile. You use the library by including appdirs_cpp/AppDirs.h in your code and calling appdirs_cpp::AppDirs::get() to get a const AppDirs instance. That instance has eight const string attributes, the first six correspond to the appdirs directory attributes and have the exact same names (e.g. user_data_dir). In addition, there is the app_data_dir which is the data directory distributed with the application, and user_cache_dir_unversioned which is an unversioned variation of user_cache_dir.

The AppDirs class provides an important convenience function for generating file system paths based on the directory attributes that uses the appropriate path separator character for the operating system:

std::string AppDirs::form_path(std::initializer_list<std::string> path_components) const

Returns a path formed by joining the given strings with the appropriate path separator. Example usage:

std::string path = appdirs.form_path({appdirs.site_data_dir,
        "charge-database", "ATP.charges"});