source: trunk/lib/CopyrightVisitor.h @ 1239

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

move 'update copyright' code from File class to CopyrightVisitor? class.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1#ifndef _theplu_svndigest_copyright_visitor_
2#define _theplu_svndigest_copyright_visitor_
3
4// $Id: CopyrightVisitor.h 1239 2010-10-23 23:57:56Z peter $
5
6/*
7  Copyright (C) 2010 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 3 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 svndigest. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include "Alias.h"
26#include "NodeVisitor.h"
27
28#include <subversion-1/svn_types.h>
29
30#include <map>
31#include <set>
32#include <string>
33
34namespace theplu{
35namespace svndigest{
36
37  class Directory;
38  class File;
39
40  /**
41     Visitor for updating copyright in files.
42  */
43  class CopyrightVisitor : public NodeVisitor
44  {
45  public:
46    CopyrightVisitor(std::map<std::string, Alias>&, bool verbose,
47                     const std::map<int, svn_revnum_t>& year2rev,
48                     bool ignore_cache);
49
50    /**
51       \return false if dir.ignore or dir.svncopyright_ignore
52     */
53    bool enter(Directory& dir);
54
55    /**
56       Doing nothing
57     */
58    void leave(Directory& dir);
59
60    /**
61       Updating copyright in \a file
62     */
63    void visit(File& file);
64
65  private:
66    std::map<std::string, Alias>& alias_;
67    bool verbose_;
68    const std::map<int, svn_revnum_t>& year2rev_;
69    bool ignore_cache_;
70
71    /**
72       \return copyright block
73
74       Create a Copyright block from \a year2auth and prefix each line
75       with \a prefix.
76     */
77    std::string copyright_block(const std::map<int, std::set<Alias> >& year2auth,
78                                const std::string& prefix) const;
79
80    /**
81       Create a map from year to set of authors.
82     */
83    void create_year2alias(std::map<int, std::set<Alias> >&, const File& file);
84
85    /**
86       Look from copyright block in file \a path.
87
88       \param path file to look for copyright
89       \param block found copyright block
90       \param start_at_line line number of first line in found block
91       \param end_at_line line number of first line after found block
92
93       \return true if Copyright block is found
94     */
95    bool detect_copyright(const std::string& path, std::string& block, 
96                          size_t& start_at_line, size_t& end_at_line, 
97                          std::string& prefix) const;
98
99
100    /**
101       Update the copyright in \a file.
102     */
103    void update_copyright(const File& file);
104
105    /**
106       Doing the actual print of copyright statement
107
108       \param path to file
109       \param block new copyright block
110       \param start_at_line line number of first line in old block
111       \param end_at_line line number of first line after old block
112     */
113    void update_copyright(const std::string& path, const std::string& block,
114                          size_t start_at_line, size_t end_at_line) const;
115  };
116}} // end of namespace svndigest and namespace theplu
117
118#endif
Note: See TracBrowser for help on using the repository browser.