source: trunk/lib/Configuration.h @ 1133

Last change on this file since 1133 was 1133, checked in by Peter Johansson, 11 years ago

new function Configuration::output_blame_information. refs #330

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.4 KB
Line 
1#ifndef _theplu_svndigest_configuration_
2#define _theplu_svndigest_configuration_
3
4// $Id: Configuration.h 1133 2010-07-18 18:30:27Z peter $
5
6/*
7  Copyright (C) 2007, 2008, 2009 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2010 Peter Johansson
9
10  This file is part of svndigest, http://dev.thep.lu.se/svndigest
11
12  svndigest is free software; you can redistribute it and/or modify it
13  under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 3 of the License, or
15  (at your option) any later version.
16
17  svndigest is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with svndigest. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include "Alias.h"
27
28#include <iostream>
29#include <map>
30#include <stdexcept>
31#include <string>
32#include <utility>
33#include <vector>
34
35namespace theplu{
36namespace svndigest{
37
38  ///
39  /// Configuration class takes care of all setting defined in the
40  /// configuration file.
41  ///
42  class Configuration
43  {
44  public:
45    static Configuration& instance(void);
46
47    /**
48       \return Hexadecimal color code (e.g. 5aee4a) that is used in
49       blame output and as line colors in plots. If no color is
50       configured for \a author, an empty string is returned.
51     */
52    std::string author_str_color(const std::string& author) const;
53
54    /**
55       The map to lookup the author-color mapping set in the
56       configuration file. The color code is a six digit hexadecimal
57       number rrggbb.
58
59       \return The author-color map
60    */
61    const std::map<std::string, std::string>& author_colors(void) const;
62
63    /**
64       \return vector of parse codons for the given \a file_name
65     */
66    const std::vector<std::pair<std::string, std::string> >* 
67    codon(std::string file_name) const;
68
69    ///
70    /// @brief Aliases for Copyright
71    ///
72    const std::map<std::string, Alias>& copyright_alias(void) const;
73
74    /**
75       \return pdf, png, none, or svg
76     */
77    const std::string& image_anchor_format(void) const;
78
79    /**
80       \brief set image_anchor_format
81     */
82    void image_anchor_format(const std::string&);
83
84    /**
85       \return png, none, svg, or svgz
86     */
87    const std::string& image_format(void) const;
88
89    /**
90       \brief set image_format
91     */
92    void image_format(const std::string&);
93
94    ///
95    /// throw if stream is not a valid config
96    ///
97    /// @brief load configuration from stream
98    ///
99    void load(std::istream&);
100
101    ///
102    /// @return true if we should warn about missing copyright statement
103    ///
104    bool  missing_copyright_warning(void) const;
105
106    /**
107       \return true (default) if we wanna output blame information
108     */
109    bool output_blame_information(void) const;
110
111    ///
112    /// @return root for the trac envrionment, e.g.,
113    /// http://dev.thep.lu.se/svndigest/
114    ///
115    std::string trac_root(void) const;
116
117  private:
118    ///
119    /// Creates a Config object with default settings.
120    ///
121    /// @brief Default Constructor
122    ///
123    Configuration(void);
124    // Copy Constructor not implemented
125    Configuration(const Configuration&);
126    // assignment not implemented because assignment is always self-assignment
127    Configuration& operator=(const Configuration&);
128    // destructor not implemented
129    ~Configuration(void);
130
131    friend std::ostream& operator<<(std::ostream&, const Configuration&);
132
133    void add_codon(std::string, std::string, std::string);
134
135    void clear(void);
136    const std::pair<std::string,std::string>* dictionary(std::string lhs) const;
137    bool equal_false(const std::string&) const;
138    bool equal_true(const std::string&) const;
139    ///
140    /// @brief load deafult configuration
141    ///
142    void load(void);
143
144    void set_default(void);
145    /**
146       Translate string \a str using dictionary \a dict
147
148       \note \a str must be equal to d.first (see regexp(5)),
149       or behavior is unspecified.
150
151       \throw if a '$' character is not followed by a positive integer
152       that is not larger than number of wildcards in dictionary \a d.
153     */
154    std::string translate(const std::string& str,
155                          const std::pair<std::string, std::string>& d) const;
156   
157    void validate_dictionary(void) const;
158
159    static Configuration* instance_;
160
161    std::map<std::string, std::string> author_color_;
162    std::map<std::string, Alias> copyright_alias_;
163
164    bool missing_copyright_warning_;
165   
166    typedef std::vector<std::pair<std::string, std::string> > VectorPair;
167    typedef std::vector<std::pair<std::string, VectorPair> > String2Codons; 
168    String2Codons string2codons_;
169
170    VectorPair dictionary_;
171    std::string image_anchor_format_;
172    std::string image_format_;
173    bool output_blame_information_;
174    std::string trac_root_;
175  };
176
177  ///
178  /// @brief Output operator
179  ///
180  std::ostream& operator<<(std::ostream&, const Configuration&);
181
182  /**
183     If first character is '\n' replace it with "<NEWLINE>"
184   */
185  std::string trans_end_code(std::string);
186
187  /**
188     If last character is '\n' replace it with "<NEWLINE>"
189   */
190  std::string trans_beg_code(std::string);
191
192  /**
193     Trim \a c from beginning and end of string \a str;
194     
195     \return resulting string
196
197     \throw if first or last character of \a str is NOT character \a c
198  */
199  std::string trim(std::string str, char c);
200
201  /**
202     \brief Class for errors when reading config file.
203   */
204  class Config_error : public std::runtime_error
205  {
206  public:
207    Config_error(const std::string& line, const std::string& message);
208  };
209
210}} // end of namespace svndigest and namespace theplu
211
212#endif
213
214
Note: See TracBrowser for help on using the repository browser.