This commit is contained in:
47
source/src/utils/envmanager.hpp
Normal file
47
source/src/utils/envmanager.hpp
Normal file
@ -0,0 +1,47 @@
|
||||
#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;
|
||||
|
||||
// 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 m_path;
|
||||
std::map<std::string, std::string> m_variables;
|
||||
};
|
||||
|
||||
// utility functions
|
||||
std::string trim(std::string str);
|
||||
std::string dequote(std::string str);
|
||||
std::string multi2string(std::vector<std::string> values);
|
||||
std::vector<std::string> string2multi(std::string values);
|
||||
|
||||
} // namespace dropshell
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user