OpenASIP 2.2
Loading...
Searching...
No Matches
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
43namespace 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.
68 LAST__
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 */
80
81 public:
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
virtual boost::format text(int textId)
virtual void replaceText(int textId, const std::string &newString)
virtual void addText(int textId, const std::string &templateString)
TextGenerator(const TextGenerator &)
Copying not allowed.
TextGenerator & operator=(const TextGenerator &)
Assignment not allowed.
std::map< int, const std::string * > dataBase_
Database that contains all template strings.
std::map< int, conststd::string * >::iterator MapIter
Iterator for map.
std::map< int, conststd::string * >::value_type ValType
value_type for map.
@ TXT_HELLO_WORLD
For testing. Do not remove.
@ TXT_ONLY_ONE_FILENAME_EXPECTED
@ TXT_ILLEGAL_INPUT_FILE
@ TXT_ILLEGAL_ARGUMENT
@ TXT_NO_SUCH_SETTING
@ TXT_FILE_X_NOT_FOUND
@ TXT_NO_FILENAME_DEFINED
@ TXT_FILE_NOT_READABLE
@ TXT_UNKNOWN_COMMAND
@ TXT_FILE_NOT_FOUND
@ TXT_UNKNOWN_SUBCOMMAND
@ TXT_ILLEGAL_ARGUMENTS