929 |
02 Dec 09 |
jari |
1 |
#ifndef _theplu_svndigest_colors_ |
929 |
02 Dec 09 |
jari |
2 |
#define _theplu_svndigest_colors_ |
916 |
30 Nov 09 |
jari |
3 |
|
916 |
30 Nov 09 |
jari |
// $Id$ |
916 |
30 Nov 09 |
jari |
5 |
|
916 |
30 Nov 09 |
jari |
6 |
/* |
978 |
12 Dec 09 |
peter |
Copyright (C) 2009 Jari Häkkinen, Peter Johansson |
916 |
30 Nov 09 |
jari |
8 |
|
916 |
30 Nov 09 |
jari |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
916 |
30 Nov 09 |
jari |
10 |
|
916 |
30 Nov 09 |
jari |
svndigest is free software; you can redistribute it and/or modify it |
916 |
30 Nov 09 |
jari |
under the terms of the GNU General Public License as published by |
916 |
30 Nov 09 |
jari |
the Free Software Foundation; either version 3 of the License, or |
916 |
30 Nov 09 |
jari |
(at your option) any later version. |
916 |
30 Nov 09 |
jari |
15 |
|
916 |
30 Nov 09 |
jari |
svndigest is distributed in the hope that it will be useful, but |
916 |
30 Nov 09 |
jari |
WITHOUT ANY WARRANTY; without even the implied warranty of |
916 |
30 Nov 09 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
916 |
30 Nov 09 |
jari |
General Public License for more details. |
916 |
30 Nov 09 |
jari |
20 |
|
916 |
30 Nov 09 |
jari |
You should have received a copy of the GNU General Public License |
916 |
30 Nov 09 |
jari |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
916 |
30 Nov 09 |
jari |
23 |
*/ |
916 |
30 Nov 09 |
jari |
24 |
|
916 |
30 Nov 09 |
jari |
25 |
#include <map> |
916 |
30 Nov 09 |
jari |
26 |
#include <string> |
916 |
30 Nov 09 |
jari |
27 |
#include <vector> |
916 |
30 Nov 09 |
jari |
28 |
|
916 |
30 Nov 09 |
jari |
29 |
namespace theplu { |
916 |
30 Nov 09 |
jari |
30 |
namespace svndigest { |
916 |
30 Nov 09 |
jari |
31 |
|
919 |
30 Nov 09 |
jari |
32 |
/** |
929 |
02 Dec 09 |
jari |
The author-color mapping is provided by the Colors class. |
919 |
30 Nov 09 |
jari |
34 |
|
944 |
03 Dec 09 |
jari |
The only way of setting specific colors for authors is through |
944 |
03 Dec 09 |
jari |
the configuration file. |
944 |
03 Dec 09 |
jari |
37 |
|
929 |
02 Dec 09 |
jari |
Colors use the singleton design pattern. |
919 |
30 Nov 09 |
jari |
39 |
*/ |
929 |
02 Dec 09 |
jari |
40 |
class Colors |
916 |
30 Nov 09 |
jari |
41 |
{ |
916 |
30 Nov 09 |
jari |
42 |
public: |
916 |
30 Nov 09 |
jari |
43 |
|
919 |
30 Nov 09 |
jari |
44 |
/** |
963 |
09 Dec 09 |
peter |
Same as get_color(4) but color is returned as a hexadecimal |
963 |
09 Dec 09 |
peter |
string rather than in rgb. |
963 |
09 Dec 09 |
peter |
47 |
|
963 |
09 Dec 09 |
peter |
\return color string associated with label |
963 |
09 Dec 09 |
peter |
49 |
*/ |
963 |
09 Dec 09 |
peter |
50 |
const std::string& color_str(const std::string& label); |
963 |
09 Dec 09 |
peter |
51 |
|
963 |
09 Dec 09 |
peter |
52 |
/** |
929 |
02 Dec 09 |
jari |
\brief Get RGB color for \a label |
919 |
30 Nov 09 |
jari |
54 |
|
929 |
02 Dec 09 |
jari |
If \a label has no assigned color, the next unused color is |
919 |
30 Nov 09 |
jari |
automatically assigned to \a label. The number of available |
929 |
02 Dec 09 |
jari |
unique colors is low, when all colors are used mapped with a |
929 |
02 Dec 09 |
jari |
\a label once, the colors are reused. |
919 |
30 Nov 09 |
jari |
59 |
*/ |
929 |
02 Dec 09 |
jari |
60 |
void get_color(const std::string& label, unsigned char& r, |
919 |
30 Nov 09 |
jari |
61 |
unsigned char& g, unsigned char& b); |
916 |
30 Nov 09 |
jari |
62 |
|
919 |
30 Nov 09 |
jari |
63 |
/** |
929 |
02 Dec 09 |
jari |
\brief Get an instance of Color |
919 |
30 Nov 09 |
jari |
65 |
*/ |
929 |
02 Dec 09 |
jari |
66 |
static Colors& instance(void); |
916 |
30 Nov 09 |
jari |
67 |
|
916 |
30 Nov 09 |
jari |
68 |
private: |
916 |
30 Nov 09 |
jari |
69 |
|
929 |
02 Dec 09 |
jari |
70 |
Colors(void); |
916 |
30 Nov 09 |
jari |
71 |
|
916 |
30 Nov 09 |
jari |
// Copy constructor not implemented |
929 |
02 Dec 09 |
jari |
73 |
Colors(const Colors&); |
916 |
30 Nov 09 |
jari |
74 |
|
916 |
30 Nov 09 |
jari |
// Assignment not implemented because assignment is always self-assignment |
929 |
02 Dec 09 |
jari |
76 |
Colors& operator=(const Colors&); |
916 |
30 Nov 09 |
jari |
77 |
|
916 |
30 Nov 09 |
jari |
// Destructor not implemented |
929 |
02 Dec 09 |
jari |
79 |
~Colors(void); |
916 |
30 Nov 09 |
jari |
80 |
|
929 |
02 Dec 09 |
jari |
81 |
struct color { |
916 |
30 Nov 09 |
jari |
82 |
std::string label; |
916 |
30 Nov 09 |
jari |
83 |
unsigned char r,g,b; |
963 |
09 Dec 09 |
peter |
84 |
std::string str; |
916 |
30 Nov 09 |
jari |
85 |
}; |
916 |
30 Nov 09 |
jari |
86 |
|
963 |
09 Dec 09 |
peter |
87 |
const color& get_color(const std::string& label); |
963 |
09 Dec 09 |
peter |
88 |
|
929 |
02 Dec 09 |
jari |
89 |
std::map<std::string, std::vector<color>::iterator> author_map_; |
929 |
02 Dec 09 |
jari |
90 |
std::vector<color> color_map_; |
929 |
02 Dec 09 |
jari |
91 |
static Colors* instance_; |
929 |
02 Dec 09 |
jari |
92 |
std::vector<color>::iterator next_color_; |
916 |
30 Nov 09 |
jari |
93 |
}; |
916 |
30 Nov 09 |
jari |
94 |
|
941 |
03 Dec 09 |
peter |
95 |
/** |
941 |
03 Dec 09 |
peter |
Convert a string to color rgb values. The input str must be |
941 |
03 Dec 09 |
peter |
either of length 3 or 6 and each character should be a |
941 |
03 Dec 09 |
peter |
hexadecimal. |
941 |
03 Dec 09 |
peter |
99 |
*/ |
941 |
03 Dec 09 |
peter |
100 |
void str2rgb(const std::string& str, unsigned char& r, unsigned char& g, |
941 |
03 Dec 09 |
peter |
101 |
unsigned char& b); |
941 |
03 Dec 09 |
peter |
102 |
|
941 |
03 Dec 09 |
peter |
// Convert char from hexadecimal to decimal, if char is out of |
941 |
03 Dec 09 |
peter |
// range -1 is returned. |
941 |
03 Dec 09 |
peter |
105 |
int to_decimal(int); |
941 |
03 Dec 09 |
peter |
106 |
|
916 |
30 Nov 09 |
jari |
107 |
}} // end of namespace svndigest and namespace theplu |
916 |
30 Nov 09 |
jari |
108 |
|
916 |
30 Nov 09 |
jari |
109 |
#endif |