Source-highlight Library
/home/bettini/work/source-highlight/src-highlite/lib/srchilite/colormap.h
00001 /*
00002  * Copyright (C) 1999-2009  Lorenzo Bettini, http://www.lorenzobettini.it
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 3 of the License, or
00007  * (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  *
00018  */
00019 
00020 #ifndef COLORMAP_H
00021 #define COLORMAP_H
00022 
00023 #include <map>
00024 #include <string>
00025 #include <boost/shared_ptr.hpp>
00026 #include <sstream>
00027 
00028 using std::map;
00029 using std::string;
00030 using std::ostringstream;
00031 
00032 namespace srchilite {
00033 
00038 class ColorMap: public map<string, string> {
00039 protected:
00041     string default_color;
00042 
00043 public:
00048     void setDefault(const string &d) {
00049         default_color = d;
00050     }
00051 
00057     const string getColor(const string &key) {
00058         const_iterator it = find(key);
00059         if (it == end())
00060             return default_color;
00061         else
00062             return it->second;
00063     }
00064 
00068     const string toString() const {
00069         ostringstream s;
00070         for (const_iterator it = begin(); it != end(); ++it)
00071             s << "[" << it->first << "]=" << it->second << "\n";
00072         s << "default=" << default_color;
00073         return s.str();
00074     }
00075 };
00076 
00078 typedef boost::shared_ptr<ColorMap> ColorMapPtr;
00079 
00080 }
00081 
00082 #endif // COLORMAP_H