xoreos  0.0.5
locstring.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_LOCSTRING_H
26 #define AURORA_LOCSTRING_H
27 
28 #include <map>
29 
30 #include "src/common/types.h"
31 #include "src/common/ustring.h"
32 #include "src/common/writestream.h"
33 
34 #include "src/aurora/language.h"
35 
36 namespace Common {
37  class SeekableReadStream;
38 }
39 
40 namespace Aurora {
41 
43 class LocString {
44 public:
45  LocString();
46  ~LocString();
47 
48  void clear();
49 
51  bool empty() const;
52 
54  void swap(LocString &str);
55 
57  uint32 getNumStrings() const;
58 
60  uint32 getID() const;
62  void setID(uint32 id);
63 
65  bool hasString(Language language, LanguageGender gender = kLanguageGenderCurrent) const;
66 
69 
71  void setString(Language language, LanguageGender gender, const Common::UString &str);
73  void setString(Language language, const Common::UString &str);
74 
76  const Common::UString &getStrRefString() const;
77 
79  const Common::UString &getFirstString() const;
80 
82  const Common::UString &getString() const;
83 
85  void readString(uint32 languageID, Common::SeekableReadStream &stream);
89  void readLocString(Common::SeekableReadStream &stream, uint32 id, uint32 count);
92 
94  uint32 getWrittenSize(bool withNullTerminate = false) const;
96  void writeLocString(Common::WriteStream &stream, bool withNullTerminate = false) const;
97 
98 private:
99  typedef std::map<uint32, Common::UString> StringMap;
100 
102 
104 
105 
106  bool hasString(uint32 languageID) const;
107 
108  const Common::UString &getString(uint32 languageID) const;
109 
110  void setString(uint32 languageID, const Common::UString &str);
111 };
112 
113 } // End of namespace Aurora
114 
115 #endif // AURORA_LOCSTRING_H
LanguageGender
Definition: language.h:67
StringMap _strings
Definition: locstring.h:103
void setString(Language language, LanguageGender gender, const Common::UString &str)
Set the string of that language.
Definition: locstring.cpp:95
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
A localized string.
Definition: locstring.h:43
void readLocString(Common::SeekableReadStream &stream, uint32 id, uint32 count)
Read a LocString out of a stream.
Definition: locstring.cpp:165
const Common::UString & getFirstString() const
Get the first available string.
Definition: locstring.cpp:115
uint32 getID() const
Return the string ID / StrRef.
Definition: locstring.cpp:66
uint32 getWrittenSize(bool withNullTerminate=false) const
Get the size, the string table will consume after being written.
Definition: locstring.cpp:179
const Common::UString & getStrRefString() const
Get the string the StrRef points to.
Definition: locstring.cpp:108
Language
Definition: language.h:46
std::map< uint32, Common::UString > StringMap
Definition: locstring.h:99
void setID(uint32 id)
Set the string ID / StrRef.
Definition: locstring.cpp:70
void swap(LocString &str)
Swap the contents of the LocString with this LocString&#39;s.
Definition: locstring.cpp:56
bool hasString(Language language, LanguageGender gender=kLanguageGenderCurrent) const
Does the LocString have a string of this language?
Definition: locstring.cpp:74
Basic writing stream interfaces.
Types and functions related to language.
Low-level type definitions to handle fixed width types portably.
Generic interface for a writable data stream.
Definition: writestream.h:64
uint32 _id
The string&#39;s ID / StrRef.
Definition: locstring.h:101
uint32 getNumStrings() const
Get the number of strings.
Definition: locstring.cpp:62
Unicode string handling.
const Common::UString & getString() const
Try to get the most appropriate string.
Definition: locstring.cpp:122
Pseudo value that means the current language gender.
Definition: language.h:72
void readLocSubString(Common::SeekableReadStream &stream)
Read a LocSubString (substring of a LocString in game data) out of a stream.
Definition: locstring.cpp:159
uint32_t uint32
Definition: types.h:204
bool empty() const
Is this localized string empty, without any strings whatsoever?
Definition: locstring.cpp:52
void readString(uint32 languageID, Common::SeekableReadStream &stream)
Read a string out of a stream.
Definition: locstring.cpp:142
Interface for a seekable & readable data stream.
Definition: readstream.h:265
void writeLocString(Common::WriteStream &stream, bool withNullTerminate=false) const
Write the LocString to a write stream.
Definition: locstring.cpp:193