source: trunk/lib/Configuration.h @ 687

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

Merged patch release 0.6.6 to trunk. Delta 0.6.6 - 0.6.5

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