#ifndef ENV_MANAGER_HPP #define ENV_MANAGER_HPP #include #include #include 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& 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& variables) const; // add variables to the environment files. // trim whitespace from the values. void add_variables(std::map 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 m_variables; }; // utility functions std::string trim(std::string str); std::string multi2string(std::vector values); std::vector string2multi(std::string values); } // namespace dropshell #endif