source: trunk/lib/Configuration.h @ 834

Last change on this file since 834 was 815, checked in by Peter Johansson, 12 years ago

adding function author_str_color. refs #161

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.5 KB
Line 
1#ifndef _theplu_svndigest_configuration_
2#define _theplu_svndigest_configuration_
3
4// $Id: Configuration.h 815 2009-08-08 18:23:22Z peter $
5
6/*
7  Copyright (C) 2007, 2008 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. If no color is configured for \a author, an empty
49       string is returned.
50     */
51    std::string author_str_color(const std::string& author) const;
52
53    /**
54       \return vector of parse codons for the given \a file_name
55     */
56    const std::vector<std::pair<std::string, std::string> >* 
57    codon(std::string file_name) const;
58
59    ///
60    /// @brief Aliases for Copyright
61    ///
62    const std::map<std::string, Alias>& copyright_alias(void) const;
63
64    ///
65    /// throw if stream is not a valid config
66    ///
67    /// @brief load configuration from stream
68    ///
69    void load(std::istream&);
70
71    ///
72    /// @return true if we should warn about missing copyright statement
73    ///
74    bool  missing_copyright_warning(void) const;
75
76    ///
77    /// @return root for the trac envrionment, e.g.,
78    /// http://dev.thep.lu.se/svndigest/
79    ///
80    std::string trac_root(void) const;
81
82  private:
83    ///
84    /// Creates a Config object with default settings.
85    ///
86    /// @brief Default Constructor
87    ///
88    Configuration(void);
89    // Copy Constructor not implemented
90    Configuration(const Configuration&);
91    // assignment not implemented because assignment is always self-assignment
92    Configuration& operator=(const Configuration&);
93    // destructor not implemented
94    ~Configuration(void);
95
96    friend std::ostream& operator<<(std::ostream&, const Configuration&);
97
98    void add_codon(std::string, std::string, std::string);
99
100    void clear(void);
101    const std::pair<std::string,std::string>* dictionary(std::string lhs) const;
102    bool equal_false(const std::string&) const;
103    bool equal_true(const std::string&) const;
104    ///
105    /// @brief load deafult configuration
106    ///
107    void load(void);
108
109    void set_default(void);
110    /**
111       Translate string \a str using dictionary \a dict
112
113       \note \a str must be equal to d.first (see function equal),
114       or behavior is unspecified.
115
116       \throw if a '$' character is not followed by a positive integer
117       that is not larger than number of wildcards in dictionary \a d.
118     */
119    std::string translate(const std::string& str,
120                          const std::pair<std::string, std::string>& d) const;
121   
122    void validate_dictionary(void) const;
123
124    static Configuration* instance_;
125
126    std::map<std::string, std::string> author_color_;
127    std::map<std::string, Alias> copyright_alias_;
128
129    bool missing_copyright_warning_;
130   
131    typedef std::vector<std::pair<std::string, std::string> > VectorPair;
132    typedef std::vector<std::pair<std::string, VectorPair> > String2Codons; 
133    String2Codons string2codons_;
134
135    VectorPair dictionary_;
136
137    std::string trac_root_;
138  };
139
140  ///
141  /// @brief Output operator
142  ///
143  std::ostream& operator<<(std::ostream&, const Configuration&);
144
145  /**
146     If first character is '\n' replace it with "<NEWLINE>"
147   */
148  std::string trans_end_code(std::string);
149
150  /**
151     If last character is '\n' replace it with "<NEWLINE>"
152   */
153  std::string trans_beg_code(std::string);
154
155  /**
156     Trim \a c from beginning and end of string \a str;
157     
158     \return resulting string
159
160     \throw if first or last character of \a str is NOT character \a c
161  */
162  std::string trim(std::string str, char c);
163
164  /**
165     \brief Class for errors when reading config file.
166   */
167  class Config_error : public std::runtime_error
168  {
169  public:
170    Config_error(const std::string& line, const std::string& message);
171  };
172
173}} // end of namespace svndigest and namespace theplu
174
175#endif
176
177
Note: See TracBrowser for help on using the repository browser.