bpp-core  2.2.0
FontManager.h
Go to the documentation of this file.
1 //
2 // File: FontManager.h
3 // Created by: Julien Dutheil
4 // Created on: Sat Mar 08 2008
5 //
6 
7 /*
8 Copyright or © or Copr. Bio++ Developement Team, (November 17, 2004)
9 
10 This software is a computer program whose purpose is to provide utilitary
11 classes. This file belongs to the Bio++ Project.
12 
13 This software is governed by the CeCILL license under French law and
14 abiding by the rules of distribution of free software. You can use,
15 modify and/ or redistribute the software under the terms of the CeCILL
16 license as circulated by CEA, CNRS and INRIA at the following URL
17 "http://www.cecill.info".
18 
19 As a counterpart to the access to the source code and rights to copy,
20 modify and redistribute granted by the license, users are provided only
21 with a limited warranty and the software's author, the holder of the
22 economic rights, and the successive licensors have only limited
23 liability.
24 
25 In this respect, the user's attention is drawn to the risks associated
26 with loading, using, modifying and/or developing or reproducing the
27 software by the user in light of its specific status of free software,
28 that may mean that it is complicated to manipulate, and that also
29 therefore means that it is reserved for developers and experienced
30 professionals having in-depth computer knowledge. Users are therefore
31 encouraged to load and test the software's suitability as regards their
32 requirements in conditions enabling the security of their systems and/or
33 data to be ensured and, more generally, to use and operate it in the
34 same conditions as regards security.
35 
36 The fact that you are presently reading this means that you have had
37 knowledge of the CeCILL license and that you accept its terms.
38 */
39 
40 #ifndef _FONTMANAGER_H_
41 #define _FONTMANAGER_H_
42 
43 #include "Font.h"
44 
45 // From the STL:
46 #include <vector>
47 
48 #include "../../Text/TextTools.h"
49 
50 namespace bpp
51 {
52 
58 template<class CodeType>
60 {
61 public:
63  virtual ~FontManager() {}
64 
65 public:
66 
71  virtual CodeType getCode(const Font& font) const throw (Exception) = 0;
72 
78  virtual const Font& getFont(CodeType& code) const throw (Exception) = 0;
79 
83  virtual std::vector<CodeType> getCodes() const = 0;
84 
88  virtual std::vector<Font> getFonts() const = 0;
89 
93  virtual size_t getNumberOfFonts() const = 0;
94 };
95 
96 
97 
98 template<class CodeType>
100  public virtual FontManager<CodeType>
101 {
102 private:
103  std::vector<Font> fonts_;
104  std::vector<CodeType> codes_;
105 
106 public:
108 
109 public:
110  CodeType getCode(const Font& font) const throw (Exception)
111  {
112  for (unsigned int i = 0; i < fonts_.size(); i++)
113  {
114  if (fonts_[i] == font)
115  {
116  return codes_[i];
117  }
118  }
119  throw Exception("AbstractFontManager::getCode. Unknown font: " + font.toString());
120  }
121 
122  const Font& getFont(int &code) const throw (Exception)
123  {
124  for (unsigned int i = 0; i < codes_.size(); i++)
125  {
126  if (codes_[i] == code)
127  {
128  return fonts_[i];
129  }
130  }
131  throw Exception("AbstractFontManager::getColor. No font associated to this code: " + TextTools::toString(code));
132  }
133  std::vector<CodeType> getCodes() const { return codes_; }
134  std::vector<Font> getFonts() const { return fonts_; }
135  size_t getNumberOfFonts() const { return fonts_.size(); }
136 
137 protected:
138  void registerFont_(const Font& font, int code)
139  {
140  codes_.push_back(code);
141  fonts_.push_back(font);
142  }
143 
144 };
145 
146 } // end of namespace.
147 
148 #endif //_FONTMANAGER_H_
149 
std::vector< Font > getFonts() const
Definition: FontManager.h:134
const Font & getFont(int &code) const
Definition: FontManager.h:122
Data structure for fonts.
Definition: Font.h:56
This class allows to perform a correspondence analysis.
void registerFont_(const Font &font, int code)
Definition: FontManager.h:138
virtual const Font & getFont(CodeType &code) const =0
virtual std::vector< CodeType > getCodes() const =0
size_t getNumberOfFonts() const
Definition: FontManager.h:135
static std::string toString(T t)
General template method to convert to a string.
Definition: TextTools.h:189
virtual size_t getNumberOfFonts() const =0
virtual ~FontManager()
Definition: FontManager.h:63
std::vector< CodeType > codes_
Definition: FontManager.h:104
Exception base class.
Definition: Exceptions.h:57
virtual std::vector< Font > getFonts() const =0
CodeType getCode(const Font &font) const
Definition: FontManager.h:110
Associate special fonts to a code.
Definition: FontManager.h:59
virtual CodeType getCode(const Font &font) const =0
std::vector< CodeType > getCodes() const
Definition: FontManager.h:133
std::vector< Font > fonts_
Definition: FontManager.h:103