NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
language.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2016 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef LANGUAGE_HPP
20#define LANGUAGE_HPP
21
22#include <string>
23#include <map>
24#include <vector>
25#include <iostream>
26#include <fstream>
27
28
29#include "../io/filesystem.hpp"
30
37class Language : public FileSystem
38{
39 private:
40 std::map<std::string,std::string> mLangStrings;
41 std::string sYES;
42 std::string sNO;
43
44 std::map<std::string,std::string> getLangFileContent(const std::string& sFile) const;
45 void loadAndInsert(const std::string& sLanguageFileName);
46
47 public:
48 Language();
49 Language(const Language& _lang);
50 void loadStrings(bool bloadUserFiles = true);
51 void addToLanguage(const std::map<std::string,std::string>& _langstrings);
52 std::string getKey(const std::string& sMessage) const;
53 std::string get(const std::string& sMessage, const std::vector<std::string>& vTokens) const; //_lang.get("GREETING",vTokens);
54
63 std::string get(const std::string& sMessage) const
64 {
65 std::vector<std::string> vTokens;
66 return get(sMessage, vTokens);
67 }
68
78 std::string get(const std::string& sMessage, const std::string& sTok1) const
79 {
80 std::vector<std::string> vTokens;
81 vTokens.push_back(sTok1);
82 return get(sMessage, vTokens);
83 }
84
95 std::string get(const std::string& sMessage, const std::string& sTok1, const std::string& sTok2) const
96 {
97 std::vector<std::string> vTokens;
98 vTokens.push_back(sTok1);
99 vTokens.push_back(sTok2);
100 return get(sMessage, vTokens);
101 }
102
114 std::string get(const std::string& sMessage, const std::string& sTok1, const std::string& sTok2, const std::string& sTok3) const
115 {
116 std::vector<std::string> vTokens;
117 vTokens.push_back(sTok1);
118 vTokens.push_back(sTok2);
119 vTokens.push_back(sTok3);
120 return get(sMessage, vTokens);
121 }
122
135 std::string get(const std::string& sMessage, const std::string& sTok1, const std::string& sTok2, const std::string& sTok3, const std::string& sTok4) const
136 {
137 std::vector<std::string> vTokens;
138 vTokens.push_back(sTok1);
139 vTokens.push_back(sTok2);
140 vTokens.push_back(sTok3);
141 vTokens.push_back(sTok4);
142 return get(sMessage, vTokens);
143 }
144
158 std::string get(const std::string& sMessage, const std::string& sTok1, const std::string& sTok2, const std::string& sTok3, const std::string& sTok4, const std::string& sTok5) const
159 {
160 std::vector<std::string> vTokens;
161 vTokens.push_back(sTok1);
162 vTokens.push_back(sTok2);
163 vTokens.push_back(sTok3);
164 vTokens.push_back(sTok4);
165 vTokens.push_back(sTok5);
166 return get(sMessage, vTokens);
167 }
168
183 std::string get(const std::string& sMessage, const std::string& sTok1, const std::string& sTok2, const std::string& sTok3, const std::string& sTok4, const std::string& sTok5, const std::string& sTok6) const
184 {
185 std::vector<std::string> vTokens;
186 vTokens.push_back(sTok1);
187 vTokens.push_back(sTok2);
188 vTokens.push_back(sTok3);
189 vTokens.push_back(sTok4);
190 vTokens.push_back(sTok5);
191 vTokens.push_back(sTok6);
192 return get(sMessage, vTokens);
193 }
194
195 std::vector<std::string> getList(const std::string& sMessageScheme) const;
196
197 inline std::string YES() const
198 {
199 return sYES;
200 }
201 inline std::string NO() const
202 {
203 return sNO;
204 }
205};
206
207#endif // LANGUAGE_HPP
208
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
This class handles the internal language system and returns the language strings of the selected lang...
Definition: language.hpp:38
std::string NO() const
Definition: language.hpp:201
void addToLanguage(const std::map< std::string, std::string > &_langstrings)
This member function adds the contents of the passed language file into the internal map.
Definition: language.cpp:238
Language()
Contructor of the language class.
Definition: language.cpp:31
std::string get(const std::string &sMessage, const std::string &sTok1, const std::string &sTok2, const std::string &sTok3, const std::string &sTok4, const std::string &sTok5) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:158
std::string YES() const
Definition: language.hpp:197
std::string get(const std::string &sMessage, const std::string &sTok1, const std::string &sTok2, const std::string &sTok3, const std::string &sTok4) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:135
void loadStrings(bool bloadUserFiles=true)
This member function loads the language files to the internal map and replaces the named tokens with ...
Definition: language.cpp:164
std::string get(const std::string &sMessage, const std::string &sTok1, const std::string &sTok2, const std::string &sTok3) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:114
std::string get(const std::string &sMessage, const std::string &sTok1, const std::string &sTok2) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:95
std::string getKey(const std::string &sMessage) const
This member function searches the internal language map for an identifier, which starts similar with ...
Definition: language.cpp:257
std::string sYES
Definition: language.hpp:41
void loadAndInsert(const std::string &sLanguageFileName)
This private member function is a simple helper for Language::loadStrings().
Definition: language.cpp:143
std::vector< std::string > getList(const std::string &sMessageScheme) const
This member function returns a vector of language strings matching to the passed identifier containin...
Definition: language.cpp:349
std::string get(const std::string &sMessage, const std::string &sTok1) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:78
std::string sNO
Definition: language.hpp:42
std::map< std::string, std::string > mLangStrings
Definition: language.hpp:40
std::string get(const std::string &sMessage, const std::string &sTok1, const std::string &sTok2, const std::string &sTok3, const std::string &sTok4, const std::string &sTok5, const std::string &sTok6) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:183
std::string get(const std::string &sMessage, const std::vector< std::string > &vTokens) const
This member function returns the language string for the passed language identifier and replaces all ...
Definition: language.cpp:292
std::map< std::string, std::string > getLangFileContent(const std::string &sFile) const
This private member function decodes a single language file into a map and returns it.
Definition: language.cpp:63
std::string get(const std::string &sMessage) const
Convenience wrapper for a defined number of tokens.
Definition: language.hpp:63
Language _lang
Definition: kernel.cpp:39