xoreos  0.0.5
language.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_LANGUAGE_H
26 #define AURORA_LANGUAGE_H
27 
28 #include <map>
29 #include <vector>
30 
31 #include "src/common/types.h"
32 #include "src/common/singleton.h"
33 #include "src/common/encoding.h"
34 
35 #include "src/aurora/types.h"
36 
37 namespace Common {
38  class UString;
39 
40  class SeekableReadStream;
41  class MemoryReadStream;
42 }
43 
44 namespace Aurora {
45 
46 enum Language {
60 
62  kLanguageDebug = 0xFFFFFFFD,
63  kLanguageChinese = 0xFFFFFFFE,
64  kLanguageInvalid = 0xFFFFFFFF
65 };
66 
70 
73 };
74 
114 class LanguageManager : public Common::Singleton<LanguageManager> {
115 public:
116  struct Declaration {
118 
122  };
123 
124  LanguageManager();
126 
127  // .--- Managed language methods
129  void clear();
130 
133  void addLanguage(Language language, uint32 id, Common::Encoding encoding);
137  void addLanguage(Language language, uint32 id, Common::Encoding encoding,
138  Common::Encoding encodingLocString);
141  void addLanguage(const Declaration &languageDeclaration);
144  void addLanguages(const Declaration *languageDeclarations, size_t count);
145 
147  std::vector<Language> getLanguages() const;
148 
155  uint32 getLanguageID(Language language) const;
156 
164  uint32 getLanguageID(Language language, LanguageGender gender) const;
165 
171  Language getLanguage(uint32 languageID) const;
172 
178  Language getLanguage(uint32 languageID, LanguageGender &gender) const;
179 
186  Language getLanguageGendered(uint32 languageID) const;
187 
189  Common::Encoding getEncoding(Language language) const;
192  // '---
193 
194  // .--- Current language
196  void setCurrentLanguage(Language language);
198  void setCurrentLanguage(Language languageText, Language languageVoice);
200  void setCurrentLanguageText(Language language);
202  void setCurrentLanguageVoice(Language language);
204  void setCurrentGender(LanguageGender gender);
205 
212 
217  // '---
218 
219  // .--- Static language utility methods
221  static Common::UString getLanguageName(Language language);
222 
224  static Language parseLanguage(const Common::UString &str);
225 
227  static uint32 convertLanguageIDToGendered(uint32 languageID, LanguageGender gender);
229  static uint32 convertLanguageIDToUngendered(uint32 languageID);
230 
232  static LanguageGender getLanguageGender(uint32 languageID);
233 
235  static uint32 swapLanguageGender(uint32 languageID);
236 
255  // '---
256 
257 private:
258  typedef std::map<uint32 , Declaration> LanguageByID;
259  typedef std::map<Language, Declaration> LanguageByLanguage;
260 
263 
267 
268  const Declaration *find(Language language) const;
269  const Declaration *find(uint32 id) const;
270 };
271 
272 } // End of namespace Aurora
273 
275 #define LangMan ::Aurora::LanguageManager::instance()
276 
277 #endif // AURORA_LANGUAGE_H
LanguageGender
Definition: language.h:67
Language _currentLanguageVoice
Definition: language.h:265
void setCurrentLanguageText(Language language)
Change the current language, for text only.
Definition: language.cpp:200
Class and macro for implementing singletons.
void setCurrentLanguage(Language language)
Change the current language, setting both text and voice to the same language.
Definition: language.cpp:178
Definition: 2dafile.h:39
const Declaration * find(Language language) const
Definition: language.cpp:104
A class holding an UTF-8 string.
Definition: ustring.h:48
LanguageByLanguage _langByLang
Definition: language.h:262
The global language manager.
Definition: language.h:114
Language
Definition: language.h:46
static uint32 convertLanguageIDToGendered(uint32 languageID, LanguageGender gender)
Convert an ungendered language ID to a gendered language ID.
Definition: language.cpp:220
uint32 getLanguageID(Language language) const
Construct the internal language ID for an ungendered use of a language.
Definition: language.cpp:120
static Common::MemoryReadStream * preParseColorCodes(Common::SeekableReadStream &stream)
Pre-parse and fix color codes found in UI and dialogue strings in Aurora games.
Definition: language.cpp:283
std::map< uint32, Declaration > LanguageByID
Definition: language.h:258
LanguageGender getCurrentGender() const
Return the gender modulating the current language.
Definition: language.cpp:208
Common::Encoding getEncodingLocString(Language language) const
Return the encoding used for the given language, for reading an embedded LocString string...
Definition: language.cpp:170
Language getCurrentLanguageText() const
Return the current language for text.
Definition: language.cpp:192
Language getCurrentLanguageVoice() const
Return the current language for voices.
Definition: language.cpp:196
static Common::UString getLanguageName(Language language)
Return the human readable name of a language.
Definition: language.cpp:254
Generic template base class for implementing the singleton design pattern.
Definition: singleton.h:61
static LanguageGender getLanguageGender(uint32 languageID)
Return the gender of this gendered language ID.
Definition: language.cpp:240
Language getLanguage(uint32 languageID) const
Decode the internal language ID for an ungendered use of a language.
Definition: language.cpp:139
void addLanguages(const Declaration *languageDeclarations, size_t count)
Add several supported language for the current game to the LanguageManager, together with their inter...
Definition: language.cpp:90
Language _currentLanguageText
Definition: language.h:264
Simple memory based &#39;stream&#39;, which implements the ReadStream interface for a plain memory block...
Definition: memreadstream.h:66
Utility functions for working with differing string encodings.
Encoding
Definition: encoding.h:37
Low-level type definitions to handle fixed width types portably.
static uint32 swapLanguageGender(uint32 languageID)
Swap the gender of this gendered language ID.
Definition: language.cpp:247
void setCurrentLanguageVoice(Language language)
Change the current language, for voice only.
Definition: language.cpp:204
Common::Encoding getEncoding(Language language) const
Return the encoding used for the given language.
Definition: language.cpp:162
void addLanguage(Language language, uint32 id, Common::Encoding encoding)
Add a supported language for the current game to the LanguageManager, together with its internal (ung...
Definition: language.cpp:57
Common::Encoding getCurrentEncodingLocString() const
Return the encoding for the current text language, for reading an embedded LocString string...
Definition: language.cpp:216
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
std::vector< Language > getLanguages() const
Return all declared supported languages for the current game.
Definition: language.cpp:95
std::map< Language, Declaration > LanguageByLanguage
Definition: language.h:259
LanguageGender _currentGender
Definition: language.h:266
Pseudo value that means the current language gender.
Definition: language.h:72
Common::Encoding getCurrentEncoding() const
Return the encoding for the current text language.
Definition: language.cpp:212
uint32_t uint32
Definition: types.h:204
Pseudo value that means either traditional or simplified Chinese.
Definition: language.h:63
Common::Encoding encodingLocString
Definition: language.h:121
Pseudo value for debug strings.
Definition: language.h:62
Language getLanguageGendered(uint32 languageID) const
Decode the internal language ID for a gendered use of a language (and ignore the language gender)...
Definition: language.cpp:157
void clear()
Clear all managed languages from the LanguageManager.
Definition: language.cpp:47
static Language parseLanguage(const Common::UString &str)
Parse this string into a language.
Definition: language.cpp:264
LanguageByID _langByID
Definition: language.h:261
Interface for a seekable & readable data stream.
Definition: readstream.h:265
static uint32 convertLanguageIDToUngendered(uint32 languageID)
Convert a gendered language ID to an ungendered language ID.
Definition: language.cpp:233
void setCurrentGender(LanguageGender gender)
Change the gender modulating the current language.
Definition: language.cpp:188