229 |
25 Mar 07 |
peter |
1 |
#ifndef _theplu_svndigest_configuration_ |
229 |
25 Mar 07 |
peter |
2 |
#define _theplu_svndigest_configuration_ |
229 |
25 Mar 07 |
peter |
3 |
|
229 |
25 Mar 07 |
peter |
// $Id$ |
229 |
25 Mar 07 |
peter |
5 |
|
229 |
25 Mar 07 |
peter |
6 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2007 Peter Johansson |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2008, 2009 Jari Häkkinen, Peter Johansson |
1515 |
26 Sep 12 |
peter |
Copyright (C) 2010, 2011, 2012 Peter Johansson |
229 |
25 Mar 07 |
peter |
10 |
|
687 |
04 Aug 08 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
229 |
25 Mar 07 |
peter |
12 |
|
229 |
25 Mar 07 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
229 |
25 Mar 07 |
peter |
under the terms of the GNU General Public License as published by |
693 |
11 Sep 08 |
jari |
the Free Software Foundation; either version 3 of the License, or |
229 |
25 Mar 07 |
peter |
(at your option) any later version. |
229 |
25 Mar 07 |
peter |
17 |
|
229 |
25 Mar 07 |
peter |
svndigest is distributed in the hope that it will be useful, but |
229 |
25 Mar 07 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
229 |
25 Mar 07 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
229 |
25 Mar 07 |
peter |
General Public License for more details. |
229 |
25 Mar 07 |
peter |
22 |
|
229 |
25 Mar 07 |
peter |
You should have received a copy of the GNU General Public License |
693 |
11 Sep 08 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
229 |
25 Mar 07 |
peter |
25 |
*/ |
229 |
25 Mar 07 |
peter |
26 |
|
303 |
11 May 07 |
peter |
27 |
#include "Alias.h" |
1502 |
28 Aug 12 |
peter |
28 |
#include "utility.h" |
303 |
11 May 07 |
peter |
29 |
|
264 |
30 Apr 07 |
peter |
30 |
#include <iostream> |
306 |
12 May 07 |
peter |
31 |
#include <map> |
522 |
25 Dec 07 |
peter |
32 |
#include <stdexcept> |
229 |
25 Mar 07 |
peter |
33 |
#include <string> |
274 |
02 May 07 |
peter |
34 |
#include <utility> |
508 |
08 Dec 07 |
peter |
35 |
#include <vector> |
229 |
25 Mar 07 |
peter |
36 |
|
229 |
25 Mar 07 |
peter |
37 |
namespace theplu{ |
229 |
25 Mar 07 |
peter |
38 |
namespace svndigest{ |
229 |
25 Mar 07 |
peter |
39 |
|
274 |
02 May 07 |
peter |
40 |
/// |
274 |
02 May 07 |
peter |
/// Configuration class takes care of all setting defined in the |
274 |
02 May 07 |
peter |
/// configuration file. |
274 |
02 May 07 |
peter |
43 |
/// |
229 |
25 Mar 07 |
peter |
44 |
class Configuration |
229 |
25 Mar 07 |
peter |
45 |
{ |
229 |
25 Mar 07 |
peter |
46 |
public: |
289 |
08 May 07 |
peter |
47 |
static Configuration& instance(void); |
264 |
30 Apr 07 |
peter |
48 |
|
510 |
08 Dec 07 |
peter |
49 |
/** |
928 |
02 Dec 09 |
jari |
\return Hexadecimal color code (e.g. 5aee4a) that is used in |
928 |
02 Dec 09 |
jari |
blame output and as line colors in plots. If no color is |
928 |
02 Dec 09 |
jari |
configured for \a author, an empty string is returned. |
815 |
08 Aug 09 |
peter |
53 |
*/ |
815 |
08 Aug 09 |
peter |
54 |
std::string author_str_color(const std::string& author) const; |
815 |
08 Aug 09 |
peter |
55 |
|
815 |
08 Aug 09 |
peter |
56 |
/** |
928 |
02 Dec 09 |
jari |
The map to lookup the author-color mapping set in the |
928 |
02 Dec 09 |
jari |
configuration file. The color code is a six digit hexadecimal |
928 |
02 Dec 09 |
jari |
number rrggbb. |
928 |
02 Dec 09 |
jari |
60 |
|
928 |
02 Dec 09 |
jari |
\return The author-color map |
928 |
02 Dec 09 |
jari |
62 |
*/ |
928 |
02 Dec 09 |
jari |
63 |
const std::map<std::string, std::string>& author_colors(void) const; |
928 |
02 Dec 09 |
jari |
64 |
|
928 |
02 Dec 09 |
jari |
65 |
/** |
510 |
08 Dec 07 |
peter |
\return vector of parse codons for the given \a file_name |
510 |
08 Dec 07 |
peter |
67 |
*/ |
1513 |
23 Sep 12 |
peter |
68 |
const std::vector<std::pair<std::string, std::string> >* |
510 |
08 Dec 07 |
peter |
69 |
codon(std::string file_name) const; |
510 |
08 Dec 07 |
peter |
70 |
|
1378 |
14 Jun 11 |
peter |
71 |
/** |
1378 |
14 Jun 11 |
peter |
A string describing the configuration relevant for file named |
1378 |
14 Jun 11 |
peter |
\a path |
1378 |
14 Jun 11 |
peter |
74 |
*/ |
1378 |
14 Jun 11 |
peter |
75 |
std::string code(const std::string& path) const; |
1378 |
14 Jun 11 |
peter |
76 |
|
446 |
16 Aug 07 |
peter |
77 |
/// |
446 |
16 Aug 07 |
peter |
/// @brief Aliases for Copyright |
446 |
16 Aug 07 |
peter |
79 |
/// |
446 |
16 Aug 07 |
peter |
80 |
const std::map<std::string, Alias>& copyright_alias(void) const; |
446 |
16 Aug 07 |
peter |
81 |
|
986 |
13 Dec 09 |
peter |
82 |
/** |
1154 |
07 Aug 10 |
peter |
@return copyright string e.g. 'Copyright (C)' (default) |
1154 |
07 Aug 10 |
peter |
84 |
*/ |
1154 |
07 Aug 10 |
peter |
85 |
const std::string& copyright_string(void) const; |
1154 |
07 Aug 10 |
peter |
86 |
|
1154 |
07 Aug 10 |
peter |
87 |
/** |
996 |
28 Dec 09 |
peter |
\return pdf, png, none, or svg |
996 |
28 Dec 09 |
peter |
89 |
*/ |
996 |
28 Dec 09 |
peter |
90 |
const std::string& image_anchor_format(void) const; |
996 |
28 Dec 09 |
peter |
91 |
|
996 |
28 Dec 09 |
peter |
92 |
/** |
1023 |
10 Jan 10 |
peter |
\brief set image_anchor_format |
1023 |
10 Jan 10 |
peter |
94 |
*/ |
1023 |
10 Jan 10 |
peter |
95 |
void image_anchor_format(const std::string&); |
1023 |
10 Jan 10 |
peter |
96 |
|
1023 |
10 Jan 10 |
peter |
97 |
/** |
986 |
13 Dec 09 |
peter |
\return png, none, svg, or svgz |
986 |
13 Dec 09 |
peter |
99 |
*/ |
986 |
13 Dec 09 |
peter |
100 |
const std::string& image_format(void) const; |
986 |
13 Dec 09 |
peter |
101 |
|
1015 |
09 Jan 10 |
peter |
102 |
/** |
1015 |
09 Jan 10 |
peter |
\brief set image_format |
1015 |
09 Jan 10 |
peter |
104 |
*/ |
1015 |
09 Jan 10 |
peter |
105 |
void image_format(const std::string&); |
1015 |
09 Jan 10 |
peter |
106 |
|
1513 |
23 Sep 12 |
peter |
107 |
/// |
304 |
11 May 07 |
peter |
/// throw if stream is not a valid config |
304 |
11 May 07 |
peter |
109 |
/// |
264 |
30 Apr 07 |
peter |
/// @brief load configuration from stream |
1513 |
23 Sep 12 |
peter |
111 |
/// |
264 |
30 Apr 07 |
peter |
112 |
void load(std::istream&); |
229 |
25 Mar 07 |
peter |
113 |
|
229 |
25 Mar 07 |
peter |
114 |
/// |
446 |
16 Aug 07 |
peter |
/// @return true if we should warn about missing copyright statement |
229 |
25 Mar 07 |
peter |
116 |
/// |
446 |
16 Aug 07 |
peter |
117 |
bool missing_copyright_warning(void) const; |
229 |
25 Mar 07 |
peter |
118 |
|
1133 |
18 Jul 10 |
peter |
119 |
/** |
1133 |
18 Jul 10 |
peter |
\return true (default) if we wanna output blame information |
1133 |
18 Jul 10 |
peter |
121 |
*/ |
1133 |
18 Jul 10 |
peter |
122 |
bool output_blame_information(void) const; |
1133 |
18 Jul 10 |
peter |
123 |
|
1136 |
18 Jul 10 |
peter |
124 |
/** |
1136 |
18 Jul 10 |
peter |
\return true (default) if we wanna output stats for file |
1136 |
18 Jul 10 |
peter |
126 |
*/ |
1136 |
18 Jul 10 |
peter |
127 |
bool output_file(void) const; |
1136 |
18 Jul 10 |
peter |
128 |
|
1144 |
24 Jul 10 |
peter |
129 |
/** |
1144 |
24 Jul 10 |
peter |
svn properties set in config file |
1144 |
24 Jul 10 |
peter |
131 |
|
1144 |
24 Jul 10 |
peter |
This is supposed to be used only in SVNproperty class |
1144 |
24 Jul 10 |
peter |
133 |
|
1144 |
24 Jul 10 |
peter |
\return NULL if there is no prop for \a filename in config |
1144 |
24 Jul 10 |
peter |
135 |
*/ |
1513 |
23 Sep 12 |
peter |
136 |
const std::map<std::string, std::string>& |
1144 |
24 Jul 10 |
peter |
137 |
svn_properties(const std::string& filename) const; |
1144 |
24 Jul 10 |
peter |
138 |
|
1155 |
09 Aug 10 |
peter |
139 |
/** |
1155 |
09 Aug 10 |
peter |
\return size of a tab, i.e., how many spaces are ued to display |
1155 |
09 Aug 10 |
peter |
a space (in blame output) |
1155 |
09 Aug 10 |
peter |
142 |
*/ |
1155 |
09 Aug 10 |
peter |
143 |
size_t tab_size(void) const; |
1155 |
09 Aug 10 |
peter |
144 |
|
274 |
02 May 07 |
peter |
145 |
/// |
274 |
02 May 07 |
peter |
/// @return root for the trac envrionment, e.g., |
687 |
04 Aug 08 |
peter |
/// http://dev.thep.lu.se/svndigest/ |
274 |
02 May 07 |
peter |
148 |
/// |
289 |
08 May 07 |
peter |
149 |
std::string trac_root(void) const; |
274 |
02 May 07 |
peter |
150 |
|
229 |
25 Mar 07 |
peter |
151 |
private: |
1513 |
23 Sep 12 |
peter |
152 |
/// |
264 |
30 Apr 07 |
peter |
/// Creates a Config object with default settings. |
264 |
30 Apr 07 |
peter |
154 |
/// |
1513 |
23 Sep 12 |
peter |
/// @brief Default Constructor |
1513 |
23 Sep 12 |
peter |
156 |
/// |
264 |
30 Apr 07 |
peter |
157 |
Configuration(void); |
274 |
02 May 07 |
peter |
// Copy Constructor not implemented |
274 |
02 May 07 |
peter |
159 |
Configuration(const Configuration&); |
289 |
08 May 07 |
peter |
// assignment not implemented because assignment is always self-assignment |
289 |
08 May 07 |
peter |
161 |
Configuration& operator=(const Configuration&); |
556 |
16 Jan 08 |
peter |
// destructor not implemented |
556 |
16 Jan 08 |
peter |
163 |
~Configuration(void); |
264 |
30 Apr 07 |
peter |
164 |
|
508 |
08 Dec 07 |
peter |
165 |
friend std::ostream& operator<<(std::ostream&, const Configuration&); |
508 |
08 Dec 07 |
peter |
166 |
|
508 |
08 Dec 07 |
peter |
167 |
void add_codon(std::string, std::string, std::string); |
508 |
08 Dec 07 |
peter |
168 |
|
264 |
30 Apr 07 |
peter |
169 |
void clear(void); |
516 |
09 Dec 07 |
peter |
170 |
const std::pair<std::string,std::string>* dictionary(std::string lhs) const; |
1143 |
24 Jul 10 |
peter |
171 |
bool equal_false(std::string) const; |
1143 |
24 Jul 10 |
peter |
172 |
bool equal_true(std::string) const; |
1152 |
07 Aug 10 |
peter |
173 |
|
1152 |
07 Aug 10 |
peter |
174 |
/** |
1152 |
07 Aug 10 |
peter |
find first element in range, [first, last) for which |
1152 |
07 Aug 10 |
peter |
element->first matches filename. |
1152 |
07 Aug 10 |
peter |
177 |
|
1152 |
07 Aug 10 |
peter |
Iterator->first must return string, i.e., [first, last) is |
1152 |
07 Aug 10 |
peter |
often a range of pair<string, T> |
1152 |
07 Aug 10 |
peter |
180 |
|
1152 |
07 Aug 10 |
peter |
If no match is found, last is returned. |
1152 |
07 Aug 10 |
peter |
182 |
*/ |
1152 |
07 Aug 10 |
peter |
183 |
template<typename Iterator> |
1152 |
07 Aug 10 |
peter |
184 |
Iterator find_fn(Iterator first, Iterator last, |
1152 |
07 Aug 10 |
peter |
185 |
const std::string& filename) const; |
1152 |
07 Aug 10 |
peter |
186 |
|
1513 |
23 Sep 12 |
peter |
187 |
/// |
556 |
16 Jan 08 |
peter |
/// @brief load deafult configuration |
1513 |
23 Sep 12 |
peter |
189 |
/// |
556 |
16 Jan 08 |
peter |
190 |
void load(void); |
556 |
16 Jan 08 |
peter |
191 |
|
229 |
25 Mar 07 |
peter |
192 |
void set_default(void); |
516 |
09 Dec 07 |
peter |
193 |
/** |
516 |
09 Dec 07 |
peter |
Translate string \a str using dictionary \a dict |
516 |
09 Dec 07 |
peter |
195 |
|
1513 |
23 Sep 12 |
peter |
\note \a str must be equal to d.first (see regexp(5)), |
523 |
25 Dec 07 |
peter |
or behavior is unspecified. |
516 |
09 Dec 07 |
peter |
198 |
|
516 |
09 Dec 07 |
peter |
\throw if a '$' character is not followed by a positive integer |
516 |
09 Dec 07 |
peter |
that is not larger than number of wildcards in dictionary \a d. |
516 |
09 Dec 07 |
peter |
201 |
*/ |
516 |
09 Dec 07 |
peter |
202 |
std::string translate(const std::string& str, |
516 |
09 Dec 07 |
peter |
203 |
const std::pair<std::string, std::string>& d) const; |
1513 |
23 Sep 12 |
peter |
204 |
|
523 |
25 Dec 07 |
peter |
205 |
void validate_dictionary(void) const; |
523 |
25 Dec 07 |
peter |
206 |
|
264 |
30 Apr 07 |
peter |
207 |
static Configuration* instance_; |
264 |
30 Apr 07 |
peter |
208 |
|
815 |
08 Aug 09 |
peter |
209 |
std::map<std::string, std::string> author_color_; |
303 |
11 May 07 |
peter |
210 |
std::map<std::string, Alias> copyright_alias_; |
1154 |
07 Aug 10 |
peter |
211 |
std::string copyright_string_; |
229 |
25 Mar 07 |
peter |
212 |
|
446 |
16 Aug 07 |
peter |
213 |
bool missing_copyright_warning_; |
1513 |
23 Sep 12 |
peter |
214 |
|
515 |
09 Dec 07 |
peter |
215 |
typedef std::vector<std::pair<std::string, std::string> > VectorPair; |
1513 |
23 Sep 12 |
peter |
216 |
typedef std::vector<std::pair<std::string, VectorPair> > String2Codons; |
508 |
08 Dec 07 |
peter |
217 |
String2Codons string2codons_; |
508 |
08 Dec 07 |
peter |
218 |
|
515 |
09 Dec 07 |
peter |
219 |
VectorPair dictionary_; |
996 |
28 Dec 09 |
peter |
220 |
std::string image_anchor_format_; |
986 |
13 Dec 09 |
peter |
221 |
std::string image_format_; |
1133 |
18 Jul 10 |
peter |
222 |
bool output_blame_information_; |
1136 |
18 Jul 10 |
peter |
223 |
bool output_file_; |
289 |
08 May 07 |
peter |
224 |
std::string trac_root_; |
1155 |
09 Aug 10 |
peter |
225 |
size_t tab_size_; |
1144 |
24 Jul 10 |
peter |
226 |
|
1152 |
07 Aug 10 |
peter |
227 |
typedef std::map<std::string, std::string> str_map; |
1152 |
07 Aug 10 |
peter |
228 |
typedef std::pair<std::string, str_map> props; |
1152 |
07 Aug 10 |
peter |
229 |
std::vector<props> svn_props_; |
1152 |
07 Aug 10 |
peter |
230 |
const str_map empty_str_map_; |
229 |
25 Mar 07 |
peter |
231 |
}; |
229 |
25 Mar 07 |
peter |
232 |
|
229 |
25 Mar 07 |
peter |
233 |
/// |
229 |
25 Mar 07 |
peter |
/// @brief Output operator |
229 |
25 Mar 07 |
peter |
235 |
/// |
229 |
25 Mar 07 |
peter |
236 |
std::ostream& operator<<(std::ostream&, const Configuration&); |
229 |
25 Mar 07 |
peter |
237 |
|
516 |
09 Dec 07 |
peter |
238 |
/** |
516 |
09 Dec 07 |
peter |
If first character is '\n' replace it with "<NEWLINE>" |
516 |
09 Dec 07 |
peter |
240 |
*/ |
516 |
09 Dec 07 |
peter |
241 |
std::string trans_end_code(std::string); |
516 |
09 Dec 07 |
peter |
242 |
|
516 |
09 Dec 07 |
peter |
243 |
/** |
516 |
09 Dec 07 |
peter |
If last character is '\n' replace it with "<NEWLINE>" |
516 |
09 Dec 07 |
peter |
245 |
*/ |
516 |
09 Dec 07 |
peter |
246 |
std::string trans_beg_code(std::string); |
516 |
09 Dec 07 |
peter |
247 |
|
522 |
25 Dec 07 |
peter |
248 |
/** |
522 |
25 Dec 07 |
peter |
Trim \a c from beginning and end of string \a str; |
1513 |
23 Sep 12 |
peter |
250 |
|
522 |
25 Dec 07 |
peter |
\return resulting string |
522 |
25 Dec 07 |
peter |
252 |
|
522 |
25 Dec 07 |
peter |
\throw if first or last character of \a str is NOT character \a c |
522 |
25 Dec 07 |
peter |
254 |
*/ |
522 |
25 Dec 07 |
peter |
255 |
std::string trim(std::string str, char c); |
522 |
25 Dec 07 |
peter |
256 |
|
522 |
25 Dec 07 |
peter |
257 |
/** |
522 |
25 Dec 07 |
peter |
\brief Class for errors when reading config file. |
522 |
25 Dec 07 |
peter |
259 |
*/ |
522 |
25 Dec 07 |
peter |
260 |
class Config_error : public std::runtime_error |
522 |
25 Dec 07 |
peter |
261 |
{ |
522 |
25 Dec 07 |
peter |
262 |
public: |
522 |
25 Dec 07 |
peter |
263 |
Config_error(const std::string& line, const std::string& message); |
522 |
25 Dec 07 |
peter |
264 |
}; |
522 |
25 Dec 07 |
peter |
265 |
|
1152 |
07 Aug 10 |
peter |
// template implementation |
1152 |
07 Aug 10 |
peter |
267 |
|
1152 |
07 Aug 10 |
peter |
268 |
template<typename Iterator> |
1152 |
07 Aug 10 |
peter |
269 |
Iterator Configuration::find_fn(Iterator first, Iterator last, |
1152 |
07 Aug 10 |
peter |
270 |
const std::string& filename) const |
1152 |
07 Aug 10 |
peter |
271 |
{ |
1152 |
07 Aug 10 |
peter |
272 |
for( ; first!=last; ++first) { |
1502 |
28 Aug 12 |
peter |
273 |
if (fnmatch(first->first, filename)) |
1152 |
07 Aug 10 |
peter |
274 |
return first; |
1152 |
07 Aug 10 |
peter |
275 |
} |
1152 |
07 Aug 10 |
peter |
276 |
return last; |
1152 |
07 Aug 10 |
peter |
277 |
} |
1152 |
07 Aug 10 |
peter |
278 |
|
1152 |
07 Aug 10 |
peter |
279 |
|
229 |
25 Mar 07 |
peter |
280 |
}} // end of namespace svndigest and namespace theplu |
229 |
25 Mar 07 |
peter |
281 |
|
229 |
25 Mar 07 |
peter |
282 |
#endif |