YggdrasilWM  0.1.1
A tiny window manager coded in C++
ConfigFileHandler.hpp
Go to the documentation of this file.
1 
28 #ifndef YGGDRASILWM_CONFIGFILEHANDLER_H
29 #define YGGDRASILWM_CONFIGFILEHANDLER_H
30 #include <string>
31 #include <fstream>
32 #include <iostream>
33 #include "json/json.h"
41 public:
53  explicit ConfigFileHandler(const std::string& configPath);
62  void readConfig();
70  void writeConfig(const Json::Value& root);
76  const Json::Value &getRoot();
77  std::string getConfigPath();
78 private:
79  static const std::vector<std::string> defaultPaths;
80  std::string configPath_;
81  Json::Value root_;
87  static std::string findConfigFile();
94  static bool fileExists(const std::string &path);
101  static std::string expandEnvironmentVariables(const std::string &path);
102 };
103 
104 #endif //YGGDRASILWM_CONFIGFILEHANDLER_H
Handle file I/O and JSON parsing for the configuration file. If no path is provided,...
Definition: ConfigFileHandler.hpp:40
void readConfig()
Read the configuration file Store the JSon root object in Json::Value root_ Throws exceptions in case...
Definition: ConfigFileHandler.cpp:75
Json::Value root_
Definition: ConfigFileHandler.hpp:81
~ConfigFileHandler()
Definition: ConfigFileHandler.cpp:54
const Json::Value & getRoot()
Get the root JSON object.
Definition: ConfigFileHandler.cpp:101
ConfigFileHandler()
Construct a new ConfigFileHandler object without a path.
Definition: ConfigFileHandler.cpp:36
std::string configPath_
Definition: ConfigFileHandler.hpp:80
void writeConfig(const Json::Value &root)
Write the configuration file Store the JSon root object in the configPath file Throws exceptions in c...
Definition: ConfigFileHandler.cpp:87
static std::string expandEnvironmentVariables(const std::string &path)
Expand environment variables in a path.
Definition: ConfigFileHandler.cpp:67
static const std::vector< std::string > defaultPaths
Definition: ConfigFileHandler.hpp:79
static std::string findConfigFile()
Find the configuration file in the default paths.
Definition: ConfigFileHandler.cpp:59
std::string getConfigPath()
Definition: ConfigFileHandler.cpp:103
static bool fileExists(const std::string &path)
Check if a file exists by trying to open it.
Definition: ConfigFileHandler.cpp:55