source: trunk/lib/Configuration.h @ 768

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

Merged patch release 0.6.7 to trunk. Delta 0.6.7 - 0.6.6

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