lib/Configuration.h

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