55 lines
1.8 KiB
C++
55 lines
1.8 KiB
C++
#ifndef ENV_MANAGER_HPP
|
|
#define ENV_MANAGER_HPP
|
|
|
|
#include <string>
|
|
#include <map>
|
|
#include <vector>
|
|
namespace dropshell {
|
|
|
|
// envmanager is a class that manages the environment files for the application.
|
|
// it is responsible for loading the environment files, and providing a class to access the variables.
|
|
// it can also save the environment files.
|
|
class envmanager {
|
|
public:
|
|
envmanager(std::string path);
|
|
~envmanager();
|
|
|
|
// load all variables from the environment file
|
|
bool load();
|
|
|
|
// save all variables to the environment file
|
|
void save();
|
|
|
|
// get variables from the environment files. Trim whitespace from the values.
|
|
// keys are case-sensitive.
|
|
std::string get_variable(std::string key) const;
|
|
void get_all_variables(std::map<std::string, std::string>& variables) const;
|
|
|
|
// get variables, but replace patterns ${var} and $var with the actual environment variable in the returned string.
|
|
// trim whitespace from the values.
|
|
std::string get_variable_substituted(std::string key) const;
|
|
void get_all_variables_substituted(std::map<std::string, std::string>& variables) const;
|
|
|
|
// add variables to the environment files.
|
|
// trim whitespace from the values.
|
|
void add_variables(std::map<std::string, std::string> variables);
|
|
void set_variable(std::string key, std::string value);
|
|
void clear_variables();
|
|
|
|
private:
|
|
std::string expand_patterns(std::string str) const;
|
|
|
|
private:
|
|
std::string m_path;
|
|
std::map<std::string, std::string> m_variables;
|
|
};
|
|
|
|
// utility functions
|
|
std::string trim(std::string str);
|
|
std::string multi2string(std::vector<std::string> values);
|
|
std::vector<std::string> string2multi(std::string values);
|
|
|
|
} // namespace dropshell
|
|
|
|
#endif
|