source: trunk/lib/Colours.h @ 919

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

Addresses #75. Colours are dynamically assigned to authors. Removed white from the colour map.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1#ifndef _theplu_svndigest_colours_
2#define _theplu_svndigest_colours_
3
4// $Id: Colours.h 919 2009-11-30 23:03:31Z 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    // Assignment not implemented because assignment is always self-assignment
68    Colours& operator=(const Colours&);
69
70    // Destructor not implemented
71    ~Colours(void);
72
73    struct colour {
74      std::string label;
75      unsigned char r,g,b;
76    };
77
78    std::map<std::string, std::vector<colour>::iterator> author_map_;
79    std::vector<colour> colour_map_;
80    static Colours* instance_;
81    std::vector<colour>::iterator next_colour_;
82  };
83
84}} // end of namespace svndigest and namespace theplu
85
86#endif
Note: See TracBrowser for help on using the repository browser.