Subversion Repositories public

Rev

Rev 69 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
69 luk 1
 
2
/// inotify cron configuration header
3
/**
4
 * \file incroncfg.h
5
 *
6
 * incron configuration
7
 *
100 luk 8
 * Copyright (C) 2007, 2008 Lukas Jelinek, <lukas@aiken.cz>
69 luk 9
 *
10
 * This program is free software; you can use it, redistribute
11
 * it and/or modify it under the terms of the GNU General Public
12
 * License, version 2 (see LICENSE-GPL).
13
 *  
14
 */
15
 
16
 
17
#ifndef INCRONCFG_H_
18
#define INCRONCFG_H_
19
 
20
 
100 luk 21
#include <cstring>
69 luk 22
#include <map>
23
 
24
/// Configuration class.
25
/**
26
 * This class provides access to values loaded from
27
 * a configuration file (either a explicitly specified one
28
 * or the default one).
29
 */
30
class IncronCfg
31
{
32
public:
33
 
34
  /// Initializes default configuration values.
35
  static void Init();
36
 
37
  /// Loads configuration values.
38
  /**
39
   * This method attempts to load configuration values
40
   * from the specified file. If it fails (e.g. the file
41
   * doesn't exist) the default file is read. As the last
42
   * resort (for the case the default file can't be loaded)
43
   * the hard-wired values are used.
44
   *
45
   * \param[in] rPath configuration file path
46
   */
47
  static void Load(const std::string& rPath);
48
 
49
  /// Retrieves a configuration value.
50
  /**
51
   * This method attempts to find the appropriate configuration
52
   * value for the given key and stores it into the given
53
   * variable.
54
   *
55
   * \param[in] rKey value key
56
   * \param[out] rVal retrieved value
57
   * \return true = success, false = failure (invalid key)
58
   */
59
  static bool GetValue(const std::string& rKey, std::string& rVal);
60
 
61
  /// Retrieves a configuration value.
62
  /**
63
   * This method attempts to find the appropriate configuration
64
   * value for the given key and stores it into the given
65
   * variable.
66
   *
67
   * \param[in] rKey value key
68
   * \param[out] rVal retrieved value
69
   * \return true = success, false = failure (invalid key)
70
   */
71
  static bool GetValue(const std::string& rKey, int& rVal);
72
 
73
  /// Retrieves a configuration value.
74
  /**
75
   * This method attempts to find the appropriate configuration
76
   * value for the given key and stores it into the given
77
   * variable.
78
   *
79
   * \param[in] rKey value key
80
   * \param[out] rVal retrieved value
81
   * \return true = success, false = failure (invalid key)
82
   */
83
  static bool GetValue(const std::string& rKey, unsigned& rVal);
84
 
85
  /// Retrieves a configuration value.
86
  /**
87
   * This method attempts to find the appropriate configuration
88
   * value for the given key and stores it into the given
89
   * variable.
90
   *
91
   * \param[in] rKey value key
92
   * \param[out] rVal retrieved value
93
   * \return true = success, false = failure (invalid key)
94
   */
95
  static bool GetValue(const std::string& rKey, bool& rVal);
96
 
97
  /// Builds a file path.
98
  /**
99
   * This function composes a path from a base path and a file name.
100
   *
101
   * \param[in] rPath base path
102
   * \param[in] rName file name
103
   * \return full path
104
   */
105
  static std::string BuildPath(const std::string& rPath, const std::string& rName);
106
 
107
protected:
108
  /// Parses a line a attempts to get a key and a value.
109
  /**
110
   * \param[in] s text line
111
   * \param[out] rKey key
112
   * \param[out] rVal value
113
   * \return true = success, false = failure
114
   */
115
  static bool ParseLine(const char* s, std::string& rKey, std::string& rVal);
116
 
117
  /// Checks whether a line is a comment.
118
  /**
119
   * \param[in] s text line
120
   * \return true = comment, false = otherwise
121
   */
122
  static bool IsComment(const char* s);
123
 
124
private:
125
  static std::map<std::string, std::string> m_values;
126
  static std::map<std::string, std::string> m_defaults;
127
};
128
 
129
#endif /*INCRONCFG_H_*/