Handling search of config file in multiple directories, additional debug messages
[vlp.git] / src / global / vlp / ConfigurationFinder.h
1 #ifndef __VLP_CONFIGURATIONFINDER_H
2 #define __VLP_CONFIGURATIONFINDER_H
3
4 #include <string>
5 #include <vector>
6
7 #include "config.h"
8
9 /**
10  * @file
11  * @brief Configuration file finding utilities
12  * @author Rafał Długołęcki
13  */
14
15 namespace loglan {
16 namespace vlp {
17
18 #if defined(WIN32) || defined(_WIN32) 
19 # define VLP_CONFIG_PATH_SEPARATOR "\\"
20 #else
21 # define VLP_CONFIG_PATH_SEPARATOR "/"
22 #endif
23
24 class ConfigurationFinder {
25 private:
26         std::vector<std::string> searchDirs;
27
28         /**
29          * Adds directory to the list of search directories
30          */
31         void addSearchDir(std::string dir);
32 public:
33         /**
34          * Default name of configuration file
35          */
36         static const constexpr char * DEFAULT_CONFIG_FILENAME = "vlp.cfg";
37
38         ConfigurationFinder();
39
40         /**
41          * Initializes list of search directories
42          */
43         void initSearchDirs();
44
45         /**
46          * Finds config file in possible config directories
47          *
48          * Search is made in following steps:
49          *  1. Check existence of filename in current execution path dir
50          *  2. If not found, check in user home directory, e.g:
51          *      - C:/Documents and Settings/Username
52          *      - ~/
53          *  3. If not found, check in system config directory (build dependent),
54          *     e.g.:
55          *      - /usr/local/etc/loglan/
56          *      - /etc/loglan/
57          *
58          * @param filename name of the file to search for
59          * @return path to the filename
60          *
61          */
62         std::string findConfig(std::string filename = DEFAULT_CONFIG_FILENAME);
63
64         /**
65          * Gets path to user local settings directory
66          *
67          * @return directory of user settings
68          */
69         virtual std::string getUserConfigurationDir() = 0;
70
71         /**
72          * Gets path to system-wide settings directory
73          *
74          * @return directory of user settings
75          */
76         std::string getSystemConfigurationDir();
77 };
78
79 }
80 }
81
82
83 #endif /* __VLP_CONFIGURATIONFINDER_H */