source: trunk/lib/Configuration.cc @ 229

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

Modified behaviour of Configuration. Fixes #114, #115, #116

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[229]1// $Id: Configuration.cc 229 2007-03-25 20:16:07Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of svndigest, http://lev.thep.lu.se/trac/svndigest
7
8  svndigest is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  svndigest is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "Configuration.h"
25
26#include "utility.h"
27
28#include <cassert>
29#include <fstream>
30#include <map>
31#include <string>
32#include <sstream>
33
34namespace theplu{
35namespace svndigest{
36
37  Configuration::Configuration(void)
38  {
39    set_default();
40  }
41
42
43  Configuration::Configuration(std::istream& is)
44  {
45    assert(is.good());
46    set_default();
47
48    std::string line;
49    std::string section;
50    std::string tmp;
51    while (getline(is, line)) {
52      line = ltrim(line);
53      if (line.empty() || line[0]=='#')
54        continue;
55      std::stringstream ss(line);
56      if (line[0] == '[') {
57        getline(ss, tmp, '[');
58        getline(ss, section, ']');
59      }
60      else if (section == "copyright-alias"){
61        getline(ss, tmp, '=');
62        std::string key = trim(tmp);
63        getline(ss, tmp);
64        std::string name = trim(tmp);
65        copyright_alias_[key] = name;
66      }
67    }
68  }
69
70
71  void Configuration::set_default(void)
72  {
73    copyright_alias_.clear();
74  }
75
76
77  std::ostream& operator<<(std::ostream& os, const Configuration& conf)
78  {
79    os << "### This file configures various behaviors for svndigest\n"
80       << "### The commented-out below are intended to demonstrate how to use\n" 
81       << "### this file.\n"
82       << "\n"
83       << "### Section for setting aliases used in copyright update\n"
84       << "[copyright-alias]\n"
85       << "# jdoe = John Doe\n";
86   
87    typedef std::map<std::string, std::string> map; 
88    for (map::const_iterator i=conf.copyright_alias().begin();
89         i!=conf.copyright_alias().end(); ++i) {
90      os << i->first << " = " << i->second << " \n";
91    }
92    return os;
93  }
94
95
96}} // end of namespace svndigest and namespace theplu
Note: See TracBrowser for help on using the repository browser.