Source-highlight Library
colormap.h
1 /*
2  * Copyright (C) 1999-2009 Lorenzo Bettini, http://www.lorenzobettini.it
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  *
18  */
19 
20 #ifndef COLORMAP_H
21 #define COLORMAP_H
22 
23 #include <map>
24 #include <string>
25 #include <boost/shared_ptr.hpp>
26 #include <sstream>
27 
28 using std::map;
29 using std::string;
30 using std::ostringstream;
31 
32 namespace srchilite {
33 
38 class ColorMap: public map<string, string> {
39 protected:
41  string default_color;
42 
43 public:
48  void setDefault(const string &d) {
49  default_color = d;
50  }
51 
57  const string getColor(const string &key) {
58  const_iterator it = find(key);
59  if (it == end())
60  return default_color;
61  else
62  return it->second;
63  }
64 
68  const string toString() const {
69  ostringstream s;
70  for (const_iterator it = begin(); it != end(); ++it)
71  s << "[" << it->first << "]=" << it->second << "\n";
72  s << "default=" << default_color;
73  return s.str();
74  }
75 };
76 
78 typedef boost::shared_ptr<ColorMap> ColorMapPtr;
79 
80 }
81 
82 #endif // COLORMAP_H
string default_color
when no color corresponds to the requested one
Definition: colormap.h:41
C++ class: doctemplate.h.
Definition: bufferedoutput.cpp:13
const string toString() const
Returns a string representation of the map.
Definition: colormap.h:68
const string getColor(const string &key)
Definition: colormap.h:57
boost::shared_ptr< ColorMap > ColorMapPtr
shared pointer for ColorMap
Definition: colormap.h:78
void setDefault(const string &d)
Sets the default color.
Definition: colormap.h:48
Simple map for colors (maps a color constant string to the corresponding color of the output format) ...
Definition: colormap.h:38