source: trunk/lib/Colors.h @ 963

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

fixes #420 - use same color in blame output as in plots.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1#ifndef _theplu_svndigest_colors_
2#define _theplu_svndigest_colors_
3
4// $Id: Colors.h 963 2009-12-09 02:58:28Z peter $
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-color mapping is provided by the Colors class.
34
35     The only way of setting specific colors for authors is through
36     the configuration file.
37
38     Colors use the singleton design pattern.
39   */
40  class Colors
41  {
42  public:
43
44    /**
45       Same as get_color(4) but color is returned as a hexadecimal
46       string rather than in rgb.
47
48       \return color string associated with label
49     */
50    const std::string& color_str(const std::string& label);
51
52    /**
53       \brief Get RGB color for \a label
54
55       If \a label has no assigned color, the next unused color is
56       automatically assigned to \a label. The number of available
57       unique colors is low, when all colors are used mapped with a
58       \a label once, the colors are reused.
59     */
60    void get_color(const std::string& label, unsigned char& r,
61                    unsigned char& g, unsigned char& b);
62
63    /**
64       \brief Get an instance of Color
65     */
66    static Colors& instance(void);
67
68  private:
69
70    Colors(void);
71
72    // Copy constructor not implemented
73    Colors(const Colors&);
74
75    // Assignment not implemented because assignment is always self-assignment
76    Colors& operator=(const Colors&);
77
78    // Destructor not implemented
79    ~Colors(void);
80
81    struct color {
82      std::string label;
83      unsigned char r,g,b;
84      std::string str;
85    };
86
87    const color& get_color(const std::string& label);
88
89    std::map<std::string, std::vector<color>::iterator> author_map_;
90    std::vector<color> color_map_;
91    static Colors* instance_;
92    std::vector<color>::iterator next_color_;
93  };
94
95  /**
96     Convert a string to color rgb values. The input str must be
97     either of length 3 or 6 and each character should be a
98     hexadecimal.
99   */
100  void str2rgb(const std::string& str, unsigned char& r, unsigned char& g,
101               unsigned char& b);
102
103  // Convert char from hexadecimal to decimal, if char is out of
104  // range -1 is returned.
105  int to_decimal(int);
106
107}} // end of namespace svndigest and namespace theplu
108
109#endif
Note: See TracBrowser for help on using the repository browser.