source: trunk/lib/Colors.h @ 944

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

Fixes #413, well it finalized the ticket.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef _theplu_svndigest_colors_
2#define _theplu_svndigest_colors_
3
4// $Id: Colors.h 944 2009-12-03 18:47:27Z 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-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       \brief Get RGB color for \a label
46
47       If \a label has no assigned color, the next unused color is
48       automatically assigned to \a label. The number of available
49       unique colors is low, when all colors are used mapped with a
50       \a label once, the colors are reused.
51     */
52    void get_color(const std::string& label, unsigned char& r,
53                    unsigned char& g, unsigned char& b);
54
55    /**
56       \brief Get an instance of Color
57     */
58    static Colors& instance(void);
59
60  private:
61
62    Colors(void);
63
64    // Copy constructor not implemented
65    Colors(const Colors&);
66
67    // Assignment not implemented because assignment is always self-assignment
68    Colors& operator=(const Colors&);
69
70    // Destructor not implemented
71    ~Colors(void);
72
73    struct color {
74      std::string label;
75      unsigned char r,g,b;
76    };
77
78    std::map<std::string, std::vector<color>::iterator> author_map_;
79    std::vector<color> color_map_;
80    static Colors* instance_;
81    std::vector<color>::iterator next_color_;
82  };
83
84  /**
85     Convert a string to color rgb values. The input str must be
86     either of length 3 or 6 and each character should be a
87     hexadecimal.
88   */
89  void str2rgb(const std::string& str, unsigned char& r, unsigned char& g,
90               unsigned char& b);
91
92  // Convert char from hexadecimal to decimal, if char is out of
93  // range -1 is returned.
94  int to_decimal(int);
95
96}} // end of namespace svndigest and namespace theplu
97
98#endif
Note: See TracBrowser for help on using the repository browser.