source: trunk/lib/Colours.h @ 928

Last change on this file since 928 was 928, checked in by Jari Häkkinen, 13 years ago

Addresses #413. Same colour for authors for all blame output and plots. Colours from config used.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.3 KB
Line 
1#ifndef _theplu_svndigest_colours_
2#define _theplu_svndigest_colours_
3
4// $Id: Colours.h 928 2009-12-02 07:43:57Z jari $
5
6/*
7  Copyright (C) 2009 Jari Häkkinen
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 <map>
26#include <string>
27#include <vector>
28
29namespace theplu {
30namespace svndigest {
31
32  /**
33     The author-colour mapping is provided by the Colours class.
34
35     Colours use the singleton design pattern.
36   */
37  class Colours
38  {
39  public:
40
41    /**
42       \brief Get RGB colour for \a label
43
44       If \a label has no assigned colour, the next unused colour is
45       automatically assigned to \a label. The number of available
46       unique colours is low, when all colours are used mapped with a
47       \a label once, the colours are reused.
48
49       \see To be written. If a specific colour is to be assigned for
50       a label, use function TBA.
51     */
52    void get_colour(const std::string& label, unsigned char& r,
53                    unsigned char& g, unsigned char& b);
54
55    /**
56       \brief Get an instance of Colour
57     */
58    static Colours& instance(void);
59
60  private:
61
62    Colours(void);
63
64    // Copy constructor not implemented
65    Colours(const Colours&);
66
67    // Convert char from hexadecimal to decimal, if char is out of
68    // range -1 is returned.
69    int to_decimal(int);
70
71    // Assignment not implemented because assignment is always self-assignment
72    Colours& operator=(const Colours&);
73
74    // Destructor not implemented
75    ~Colours(void);
76
77    struct colour {
78      std::string label;
79      unsigned char r,g,b;
80    };
81
82    std::map<std::string, std::vector<colour>::iterator> author_map_;
83    std::vector<colour> colour_map_;
84    static Colours* instance_;
85    std::vector<colour>::iterator next_colour_;
86  };
87
88}} // end of namespace svndigest and namespace theplu
89
90#endif
Note: See TracBrowser for help on using the repository browser.