source: trunk/lib/Configuration.h @ 516

Last change on this file since 516 was 516, checked in by Peter Johansson, 14 years ago

adding filename translations in Configuration class. Before checking what type parsing to use, filename is translated according to rules set in config file. Default rule (as before) is to remove trailing .in from filenames. To solve the parsing I added a simple regexp function - see utility.h

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1#ifndef _theplu_svndigest_configuration_
2#define _theplu_svndigest_configuration_
3
4// $Id: Configuration.h 516 2007-12-09 07:58:54Z peter $
5
6/*
7  Copyright (C) 2007 Peter Johansson
8
9  This file is part of svndigest, http://trac.thep.lu.se/trac/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 <string>
32#include <utility>
33#include <vector>
34
35namespace theplu{
36namespace svndigest{
37
38  ///
39  /// Configuration class takes care of all setting defined in the
40  /// configuration file.
41  ///
42  class Configuration
43  {
44  public:
45    static Configuration& instance(void);
46
47    /**
48       \return vector of parse codons for the given \a file_name
49     */
50    const std::vector<std::pair<std::string, std::string> >* 
51    codon(std::string file_name) const;
52
53    ///
54    /// @brief Aliases for Copyright
55    ///
56    const std::map<std::string, Alias>& copyright_alias(void) const;
57
58    ///
59    /// @brief load deafult configuration
60    ///
61    void load(void);
62
63    ///
64    /// throw if stream is not a valid config
65    ///
66    /// @brief load configuration from stream
67    ///
68    void load(std::istream&);
69
70    ///
71    /// @return true if we should warn about missing copyright statement
72    ///
73    bool  missing_copyright_warning(void) const;
74
75    ///
76    /// @return root for the trac envrionment, e.g.,
77    /// http://trac.thep.lu.se/trac/svndigest/
78    ///
79    std::string trac_root(void) const;
80
81  private:
82    ///
83    /// Creates a Config object with default settings.
84    ///
85    /// @brief Default Constructor
86    ///
87    Configuration(void);
88    // Copy Constructor not implemented
89    Configuration(const Configuration&);
90    // assignment not implemented because assignment is always self-assignment
91    Configuration& operator=(const Configuration&);
92
93    friend std::ostream& operator<<(std::ostream&, const Configuration&);
94
95    void add_codon(std::string, std::string, std::string);
96
97    void clear(void);
98    const std::pair<std::string,std::string>* dictionary(std::string lhs) const;
99    bool equal_false(const std::string&) const;
100    bool equal_true(const std::string&) const;
101    void set_default(void);
102    /**
103       Translate string \a str using dictionary \a dict
104
105       \note \a str must be equal to d.first, or behavior is unspecified.
106
107       \throw if a '$' character is not followed by a positive integer
108       that is not larger than number of wildcards in dictionary \a d.
109     */
110    std::string translate(const std::string& str,
111                          const std::pair<std::string, std::string>& d) const;
112   
113    static Configuration* instance_;
114
115    std::map<std::string, Alias> copyright_alias_;
116
117    bool missing_copyright_warning_;
118   
119    typedef std::vector<std::pair<std::string, std::string> > VectorPair;
120    typedef std::vector<std::pair<std::string, VectorPair> > String2Codons; 
121    String2Codons string2codons_;
122
123    VectorPair dictionary_;
124
125    std::string trac_root_;
126  };
127
128  ///
129  /// @brief Output operator
130  ///
131  std::ostream& operator<<(std::ostream&, const Configuration&);
132
133  /**
134     If first character is '\n' replace it with "<NEWLINE>"
135   */
136  std::string trans_end_code(std::string);
137
138  /**
139     If last character is '\n' replace it with "<NEWLINE>"
140   */
141  std::string trans_beg_code(std::string);
142
143}} // end of namespace svndigest and namespace theplu
144
145#endif
146
147
Note: See TracBrowser for help on using the repository browser.