Bayeux  3.4.1
Core Foundation library for SuperNEMO
color.h
Go to the documentation of this file.
1 /* Author(s): Francois Mauger <mauger@lpccaen.in2p3.fr>
3  * Creation date: 2010-03-23
4  * Last modified: 2014-02-12
5  *
6  * License:
7  *
8  * Description:
9  *
10  * Utilities for color manipulation.
11  *
12  * History:
13  *
14  */
15 
16 #ifndef GEOMTOOLS_COLOR_H
17 #define GEOMTOOLS_COLOR_H 1
18 
19 // Standard library:
20 #include <iostream>
21 #include <string>
22 #include <map>
23 
24 // Third party:
25 // - Boost:
26 #include <boost/cstdint.hpp>
27 #include <boost/scoped_ptr.hpp>
28 
29 namespace geomtools {
30 
32  class color
33  {
34  public:
35 
36  static const int COLOR_TEST = 0;
37 
39  // May collide with some macros from ncurses.h
40  enum code_type {
46  COLOR_RED = 1,
55  };
56 
57  static const std::string & invalid();
58  static const std::string & transparent();
59  static const std::string & white();
60  static const std::string & black();
61  static const std::string & grey();
62  static const std::string & red();
63  static const std::string & green();
64  static const std::string & blue();
65  static const std::string & magenta();
66  static const std::string & cyan();
67  static const std::string & brown();
68  static const std::string & yellow();
69  static const std::string & orange();
70  static const std::string & default_color();
71 
73  struct constants
74  {
75  std::string invalid;
76  std::string transparent;
77  std::string white;
78  std::string black;
79  std::string grey;
80  std::string red;
81  std::string green;
82  std::string blue;
83  std::string magenta;
84  std::string cyan;
85  std::string brown;
86  std::string yellow;
87  std::string orange;
88  std::string default_color;
89 
91  constants();
92 
94  static const constants & instance();
95  };
96 
97  public:
98 
99  int32_t code;
100  std::string name;
101  int32_t red_amount;
102  int32_t green_amount;
103  int32_t blue_amount;
104  int32_t alpha_amount;
105 
106  public:
107 
109  color();
110 
112  color(code_type, const std::string &,
113  int32_t, int32_t, int32_t, int32_t = 0);
114 
116  typedef std::map<std::string, code_type> color_map_type;
117 
119  class color_db
120  {
121  public:
122 
124  color_db();
125 
127  virtual ~color_db();
128 
129  //bool has_color(const string & id_) const;
130 
132  code_type get_color(const std::string & a_color_id) const;
133 
134  //void register_color(color, const string & id_);
135 
136  //void dump_colors(ostream & out_ = clog);
137 
138  private:
139 
140  color_map_type map_of_colors_;
141 
142  };
143 
145  typedef boost::scoped_ptr<color_db> scoped_color_db_type;
146 
147  public:
148 
150  static const color_db & get_color_db();
151 
153  static code_type get_color(const std::string & a_name);
154 
156  struct context {
157 
163  //ENCODING_BY_COLOR = 4,
164  };
165 
167  context();
168 
170  void reset();
171 
173  bool is_activated() const;
174 
176  void deactivate();
177 
179  bool encoded_by_code() const;
180 
183 
186 
188  bool encoded_by_value() const;
189 
191  void set_color_value(double);
192 
194  double get_color_value() const;
195 
197  bool encoded_by_name() const;
198 
200  void set_color_name(const std::string &);
201 
203  const std::string & get_color_name() const;
204 
205  /*
207  bool encoded_by_color() const;
208 
210  void set_color(const color &);
211 
213  const color & get_color() const;
214  */
215 
217  std::string str() const;
218 
219  private:
220 
222  encoding_type _encoding_;
223  color::code_type _color_code_;
224  double _color_value_;
225  std::string _color_name_;
226  double _transparency_;
227 
228  };
229 
230  };
231 
232 } // end of namespace geomtools
233 
234 #endif // GEOMTOOLS_COLOR_H
235 
236 /*
237 ** Local Variables: --
238 ** mode: c++ --
239 ** c-file-style: "gnu" --
240 ** tab-width: 2 --
241 ** End: --
242 */
code_type
Color code for gnuplot (x11 terminal)
Definition: color.h:40
Definition: color.h:44
Definition: color.h:41
void set_color_name(const std::string &)
Set the color name.
Definition: color.h:43
void set_color_value(double)
Set the color value.
std::string green
Definition: color.h:81
static const std::string & yellow()
virtual ~color_db()
Destructor.
bool is_activated() const
Check activation status.
std::string red
Definition: color.h:80
color()
Constructor.
double get_color_value() const
Return the color value.
std::map< std::string, code_type > color_map_type
Definition: color.h:116
std::string cyan
Definition: color.h:84
std::string str() const
Generate a string.
static const std::string & brown()
Definition: color.h:47
static const std::string & orange()
void deactivate()
Deactivate.
void set_color_code(color::code_type)
Set the color code.
std::string blue
Definition: color.h:82
std::string grey
Definition: color.h:79
std::string white
Definition: color.h:77
static code_type get_color(const std::string &a_name)
Get color code from label.
static const std::string & transparent()
std::string name
Color name.
Definition: color.h:100
Color register.
Definition: color.h:119
int32_t green_amount
Green channel (RGB encoding)
Definition: color.h:102
Definition: color.h:50
static const int COLOR_TEST
Definition: color.h:36
Definition: color.h:53
std::string transparent
Definition: color.h:76
std::string orange
Definition: color.h:87
boost::scoped_ptr< color_db > scoped_color_db_type
Type of smart pointer on color register.
Definition: color.h:145
Definition: color.h:45
static const std::string & cyan()
int32_t blue_amount
Blue channel (RGB encoding)
Definition: color.h:103
std::string brown
Definition: color.h:85
std::string invalid
Definition: color.h:75
encoding_type
Definition: color.h:158
static const std::string & green()
int32_t alpha_amount
Alpha channel.
Definition: color.h:104
static const std::string & blue()
static const std::string & default_color()
std::string yellow
Definition: color.h:86
bool encoded_by_code() const
Check if color is encoded by code.
std::string magenta
Definition: color.h:83
Definition: color.h:48
Definition: color.h:51
Color.
Definition: color.h:32
Definition: color.h:54
static const color_db & get_color_db()
Get the global color register.
static const constants & instance()
Singleton.
Color context object.
Definition: color.h:156
const std::string & get_color_name() const
Return the color name.
int32_t code
Color code.
Definition: color.h:99
color::code_type get_color_code() const
Return the color code.
bool encoded_by_name() const
Check if color is encoded by name.
static const std::string & black()
Definition: color.h:46
static const std::string & white()
Color labels.
Definition: color.h:73
static const std::string & red()
std::string black
Definition: color.h:78
bool encoded_by_value() const
Check if color is encoded by value.
static const std::string & invalid()
Definition: color.h:52
Definition: color.h:49
std::string default_color
Definition: color.h:88
static const std::string & magenta()
static const std::string & grey()
int32_t red_amount
Red channel (RGB encoding)
Definition: color.h:101
Top-level namespace of the Bayeux/geomtools module library.
Definition: electromagnetic_field_manager.h:39
code_type get_color(const std::string &a_color_id) const
Get color code from label.