source: trunk/lib/Configuration.h @ 978

Last change on this file since 978 was 978, checked in by Peter Johansson, 13 years ago

refs #429. Convert copyright statements to UTF-8

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