OpenASIP  2.0
TextGenerator.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file TextGenerator.hh
26  *
27  * Declaration of TextGenerator class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note reviewed 19 May 2004 by ml, jn, ao, am
31  * @note rating: green
32  */
33 
34 #ifndef TTA_TEXT_GENERATOR_HH
35 #define TTA_TEXT_GENERATOR_HH
36 
37 #include <string>
38 #include <map>
39 #include <boost/format.hpp>
40 
41 #include "Exception.hh"
42 
43 namespace Texts {
44 
45  /**
46  * Enumeration containing all text ids.
47  *
48  * Text ids are used to achieve a right template string.
49  * In your own TextGenerator class you should define your enum like this:
50  * enum {
51  * TXT_SOMETHING = LAST__
52  * ...
53  * };
54  */
55  enum {
56  TXT_HELLO_WORLD = 0, ///< For testing. Do not remove.
69  };
70 
71  /**
72  * The class that holds template strings and formats them.
73  *
74  * Template strings are added with addText function by giving the text id
75  * and the template string. Formatted string are achieved by calling text()
76  * with text id and parameters. For example text(TXT_HELLO_WORLD, "all")
77  * returns "Hello all world".
78  */
79  class TextGenerator {
80 
81  public:
82  TextGenerator();
83  virtual ~TextGenerator();
84 
85  virtual boost::format text(int textId);
86  virtual void addText(int textId, const std::string& templateString);
87  virtual void replaceText(int textId, const std::string& newString);
88 
89  private:
90  /// value_type for map.
91  typedef std::map<int, const std::string*>::value_type ValType;
92  /// Iterator for map.
93  typedef std::map<int, const std::string*>::iterator MapIter;
94 
95  /// Copying not allowed.
97  /// Assignment not allowed.
99 
100  /// Database that contains all template strings.
101  std::map<int, const std::string*> dataBase_;
102  };
103 }
104 
105 #endif
Texts::TextGenerator::operator=
TextGenerator & operator=(const TextGenerator &)
Assignment not allowed.
Texts::TXT_UNKNOWN_COMMAND
@ TXT_UNKNOWN_COMMAND
Definition: TextGenerator.hh:64
Exception.hh
Texts::TextGenerator::text
virtual boost::format text(int textId)
Definition: TextGenerator.cc:94
Texts::TXT_ONLY_ONE_FILENAME_EXPECTED
@ TXT_ONLY_ONE_FILENAME_EXPECTED
Definition: TextGenerator.hh:62
Texts::TextGenerator::MapIter
std::map< int, const std::string * >::iterator MapIter
Iterator for map.
Definition: TextGenerator.hh:93
Texts::TXT_NO_SUCH_SETTING
@ TXT_NO_SUCH_SETTING
Definition: TextGenerator.hh:63
Texts::TextGenerator::addText
virtual void addText(int textId, const std::string &templateString)
Definition: TextGenerator.cc:118
Texts::TXT_ILLEGAL_ARGUMENT
@ TXT_ILLEGAL_ARGUMENT
Definition: TextGenerator.hh:66
Texts::TextGenerator::replaceText
virtual void replaceText(int textId, const std::string &newString)
Definition: TextGenerator.cc:132
Texts::TXT_UNKNOWN_SUBCOMMAND
@ TXT_UNKNOWN_SUBCOMMAND
Definition: TextGenerator.hh:65
Texts::TXT_ILLEGAL_ARGUMENTS
@ TXT_ILLEGAL_ARGUMENTS
Definition: TextGenerator.hh:67
Texts::TXT_ILLEGAL_INPUT_FILE
@ TXT_ILLEGAL_INPUT_FILE
Definition: TextGenerator.hh:60
Texts::TextGenerator
Definition: TextGenerator.hh:79
Texts::TextGenerator::dataBase_
std::map< int, const std::string * > dataBase_
Database that contains all template strings.
Definition: TextGenerator.hh:101
Texts::TXT_FILE_NOT_READABLE
@ TXT_FILE_NOT_READABLE
Definition: TextGenerator.hh:59
Texts
Definition: SimulatorTextGenerator.hh:48
Texts::TXT_NO_FILENAME_DEFINED
@ TXT_NO_FILENAME_DEFINED
Definition: TextGenerator.hh:61
Texts::TXT_FILE_NOT_FOUND
@ TXT_FILE_NOT_FOUND
Definition: TextGenerator.hh:57
Texts::TextGenerator::~TextGenerator
virtual ~TextGenerator()
Definition: TextGenerator.cc:79
Texts::TXT_FILE_X_NOT_FOUND
@ TXT_FILE_X_NOT_FOUND
Definition: TextGenerator.hh:58
Texts::TXT_HELLO_WORLD
@ TXT_HELLO_WORLD
For testing. Do not remove.
Definition: TextGenerator.hh:56
Texts::TextGenerator::TextGenerator
TextGenerator()
Definition: TextGenerator.cc:55
Texts::LAST__
@ LAST__
Definition: TextGenerator.hh:68
Texts::TextGenerator::ValType
std::map< int, const std::string * >::value_type ValType
value_type for map.
Definition: TextGenerator.hh:91