|
bpp-core
2.1.0
|
00001 // 00002 // File: ColorSet.h 00003 // Created by: Julien Dutheil 00004 // Created on: Mon Apr 14 2008 00005 // 00006 00007 /* 00008 Copyright or © or Copr. CNRS, (November 17, 2008) 00009 00010 This software is a computer program whose purpose is to provide utilitary 00011 classes. This file belongs to the Bio++ Project. 00012 00013 This software is governed by the CeCILL license under French law and 00014 abiding by the rules of distribution of free software. You can use, 00015 modify and/ or redistribute the software under the terms of the CeCILL 00016 license as circulated by CEA, CNRS and INRIA at the following URL 00017 "http://www.cecill.info". 00018 00019 As a counterpart to the access to the source code and rights to copy, 00020 modify and redistribute granted by the license, users are provided only 00021 with a limited warranty and the software's author, the holder of the 00022 economic rights, and the successive licensors have only limited 00023 liability. 00024 00025 In this respect, the user's attention is drawn to the risks associated 00026 with loading, using, modifying and/or developing or reproducing the 00027 software by the user in light of its specific status of free software, 00028 that may mean that it is complicated to manipulate, and that also 00029 therefore means that it is reserved for developers and experienced 00030 professionals having in-depth computer knowledge. Users are therefore 00031 encouraged to load and test the software's suitability as regards their 00032 requirements in conditions enabling the security of their systems and/or 00033 data to be ensured and, more generally, to use and operate it in the 00034 same conditions as regards security. 00035 00036 The fact that you are presently reading this means that you have had 00037 knowledge of the CeCILL license and that you accept its terms. 00038 */ 00039 00040 #ifndef _COLORSET_H_ 00041 #define _COLORSET_H_ 00042 00043 #include "RgbColor.h" 00044 #include "../Utils/MapTools.h" 00045 00046 // From the STL: 00047 #include <vector> 00048 00049 namespace bpp 00050 { 00051 00055 class ColorSet 00056 { 00057 public: 00058 ColorSet() {} 00059 virtual ~ColorSet() {} 00060 00061 public: 00062 00070 virtual const RGBColor& getColor(const std::string& name) const throw (Exception) = 0; 00071 00079 virtual const RGBColor& getColor(unsigned int index) const throw (IndexOutOfBoundsException) = 0; 00080 00084 virtual std::vector<std::string> getColorNames() const = 0; 00085 00089 virtual size_t getNumberOfColors() const = 0; 00090 }; 00091 00092 00098 class AbstractColorSet: 00099 public ColorSet 00100 { 00101 protected: 00102 std::map<std::string, RGBColor> colors_; 00103 00104 public: 00105 AbstractColorSet(): colors_() {} 00106 virtual ~AbstractColorSet() {} 00107 00108 public: 00109 const RGBColor& getColor(const std::string& name) const throw (Exception) 00110 { 00111 std::map<std::string, RGBColor>::const_iterator it = colors_.find(name); 00112 if (it != colors_.end()) return it->second; 00113 else throw Exception("AbstractColorSet::getColor(name): no color with name " + name); 00114 } 00115 00116 const RGBColor& getColor(unsigned int index) const throw (IndexOutOfBoundsException) 00117 { 00118 if (index >= colors_.size()) throw IndexOutOfBoundsException("AbstractColorSet::getColor(index): invalid index.", index, 0, colors_.size() - 1); 00119 std::map<std::string, RGBColor>::const_iterator it = colors_.begin(); 00120 for (unsigned int i = 0; i < index; i++) it++; 00121 return it->second; 00122 } 00123 00124 std::vector<std::string> getColorNames() const { return MapTools::getKeys(colors_); } 00125 00126 size_t getNumberOfColors() const { return colors_.size(); } 00127 }; 00128 00129 } // end of namespace bpp; 00130 00131 #endif //_COLORSET_H_ 00132