source: trunk/lib/Colors.h @ 941

Last change on this file since 941 was 941, checked in by Peter Johansson, 13 years ago

refs #419. Lifted some functions/code from Colors' privacy to be reachable also from Configuration class.

  • 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 941 2009-12-03 06:05:39Z 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     Colors use the singleton design pattern.
36   */
37  class Colors
38  {
39  public:
40
41    /**
42       \brief Get RGB color for \a label
43
44       If \a label has no assigned color, the next unused color is
45       automatically assigned to \a label. The number of available
46       unique colors is low, when all colors are used mapped with a
47       \a label once, the colors are reused.
48
49       \see To be written. If a specific color is to be assigned for
50       a label, use function TBA.
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.