dropshell/source/src/utils/envmanager.hpp
Your Name 93e563948f
Some checks failed
Dropshell Test / Build_and_Test (push) Has been cancelled
Shift things around
2025-05-17 10:18:25 +12:00

48 lines
1.4 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;
// 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