1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 |
|
---|
26 | #ifndef __StringConverter_H__
|
---|
27 | #define __StringConverter_H__
|
---|
28 |
|
---|
29 | #include "OgrePrerequisites.h"
|
---|
30 | #include "OgreMath.h"
|
---|
31 | #include "OgreString.h"
|
---|
32 | #include "OgreStringVector.h"
|
---|
33 |
|
---|
34 | namespace Ogre {
|
---|
35 |
|
---|
36 | /** Class for converting the core Ogre data types to/from Strings.
|
---|
37 | @remarks
|
---|
38 | The code for converting values to and from strings is here as a separate
|
---|
39 | class to avoid coupling String to other datatypes (and vice-versa) which reduces
|
---|
40 | compilation dependency: important given how often the core types are used.
|
---|
41 | @par
|
---|
42 | This class is mainly used for parsing settings in text files. External applications
|
---|
43 | can also use it to interface with classes which use the StringInterface template
|
---|
44 | class.
|
---|
45 | @par
|
---|
46 | The String formats of each of the major types is listed with the methods. The basic types
|
---|
47 | like int and Real just use the underlying C runtime library atof and atoi family methods,
|
---|
48 | however custom types like Vector3, ColourValue and Matrix4 are also supported by this class
|
---|
49 | using custom formats.
|
---|
50 | @author
|
---|
51 | Steve Streeting
|
---|
52 | */
|
---|
53 | class _OgreExport StringConverter
|
---|
54 | {
|
---|
55 | public:
|
---|
56 |
|
---|
57 | /** Converts a Real to a String. */
|
---|
58 | static String toString(Real val, unsigned short precision = 6,
|
---|
59 | unsigned short width = 0, char fill = ' ',
|
---|
60 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
61 | /** Converts a Radian to a String. */
|
---|
62 | static String toString(Radian val, unsigned short precision = 6,
|
---|
63 | unsigned short width = 0, char fill = ' ',
|
---|
64 | std::ios::fmtflags flags = std::ios::fmtflags(0) )
|
---|
65 | {
|
---|
66 | return toString(val.valueAngleUnits(), precision, width, fill, flags);
|
---|
67 | }
|
---|
68 | /** Converts a Degree to a String. */
|
---|
69 | static String toString(Degree val, unsigned short precision = 6,
|
---|
70 | unsigned short width = 0, char fill = ' ',
|
---|
71 | std::ios::fmtflags flags = std::ios::fmtflags(0) )
|
---|
72 | {
|
---|
73 | return toString(val.valueAngleUnits(), precision, width, fill, flags);
|
---|
74 | }
|
---|
75 | /** Converts an int to a String. */
|
---|
76 | static String toString(int val, unsigned short width = 0,
|
---|
77 | char fill = ' ',
|
---|
78 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
79 | #if OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE
|
---|
80 | /** Converts an unsigned int to a String. */
|
---|
81 | static String toString(unsigned int val,
|
---|
82 | unsigned short width = 0, char fill = ' ',
|
---|
83 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
84 | /** Converts a size_t to a String. */
|
---|
85 | static String toString(size_t val,
|
---|
86 | unsigned short width = 0, char fill = ' ',
|
---|
87 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
88 | #else
|
---|
89 | /** Converts a size_t to a String. */
|
---|
90 | static String toString(size_t val,
|
---|
91 | unsigned short width = 0, char fill = ' ',
|
---|
92 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
93 | /** Converts an unsigned long to a String. */
|
---|
94 | static String toString(unsigned long val,
|
---|
95 | unsigned short width = 0, char fill = ' ',
|
---|
96 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
97 | #endif
|
---|
98 | /** Converts a long to a String. */
|
---|
99 | static String toString(long val,
|
---|
100 | unsigned short width = 0, char fill = ' ',
|
---|
101 | std::ios::fmtflags flags = std::ios::fmtflags(0) );
|
---|
102 | /** Converts a boolean to a String.
|
---|
103 | @param yesNo If set to true, result is 'yes' or 'no' instead of 'true' or 'false'
|
---|
104 | */
|
---|
105 | static String toString(bool val, bool yesNo = false);
|
---|
106 | /** Converts a Vector3 to a String.
|
---|
107 | @remarks
|
---|
108 | Format is "x y z" (i.e. 3x Real values, space delimited)
|
---|
109 | */
|
---|
110 | static String toString(const Vector3& val);
|
---|
111 | /** Converts a Matrix3 to a String.
|
---|
112 | @remarks
|
---|
113 | Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc.
|
---|
114 | */
|
---|
115 | static String toString(const Matrix3& val);
|
---|
116 | /** Converts a Matrix4 to a String.
|
---|
117 | @remarks
|
---|
118 | Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where
|
---|
119 | '01' means row 0 column 1 etc.
|
---|
120 | */
|
---|
121 | static String toString(const Matrix4& val);
|
---|
122 | /** Converts a Quaternion to a String.
|
---|
123 | @remarks
|
---|
124 | Format is "x y z w" (i.e. 4x Real values, space delimited)
|
---|
125 | */
|
---|
126 | static String toString(const Quaternion& val);
|
---|
127 | /** Converts a ColourValue to a String.
|
---|
128 | @remarks
|
---|
129 | Format is "r g b a" (i.e. 4x Real values, space delimited).
|
---|
130 | */
|
---|
131 | static String toString(const ColourValue& val);
|
---|
132 | /** Converts a StringVector to a string.
|
---|
133 | @remarks
|
---|
134 | Strings must not contain spaces since space is used as a delimeter in
|
---|
135 | the output.
|
---|
136 | */
|
---|
137 | static String toString(const StringVector& val);
|
---|
138 |
|
---|
139 | /** Converts a String to a Real.
|
---|
140 | @returns
|
---|
141 | 0.0 if the value could not be parsed, otherwise the Real version of the String.
|
---|
142 | */
|
---|
143 | static Real parseReal(const String& val);
|
---|
144 | /** Converts a String to a Angle.
|
---|
145 | @returns
|
---|
146 | 0.0 if the value could not be parsed, otherwise the Angle version of the String.
|
---|
147 | */
|
---|
148 | static inline Radian parseAngle(const String& val) {
|
---|
149 | return Angle(parseReal(val));
|
---|
150 | }
|
---|
151 | /** Converts a String to a whole number.
|
---|
152 | @returns
|
---|
153 | 0.0 if the value could not be parsed, otherwise the numeric version of the String.
|
---|
154 | */
|
---|
155 | static int parseInt(const String& val);
|
---|
156 | /** Converts a String to a whole number.
|
---|
157 | @returns
|
---|
158 | 0.0 if the value could not be parsed, otherwise the numeric version of the String.
|
---|
159 | */
|
---|
160 | static unsigned int parseUnsignedInt(const String& val);
|
---|
161 | /** Converts a String to a whole number.
|
---|
162 | @returns
|
---|
163 | 0.0 if the value could not be parsed, otherwise the numeric version of the String.
|
---|
164 | */
|
---|
165 | static long parseLong(const String& val);
|
---|
166 | /** Converts a String to a whole number.
|
---|
167 | @returns
|
---|
168 | 0.0 if the value could not be parsed, otherwise the numeric version of the String.
|
---|
169 | */
|
---|
170 | static unsigned long parseUnsignedLong(const String& val);
|
---|
171 | /** Converts a String to a boolean.
|
---|
172 | @remarks
|
---|
173 | Accepts 'true' or 'false' as input.
|
---|
174 | */
|
---|
175 | static bool parseBool(const String& val);
|
---|
176 | /** Parses a Vector3 out of a String.
|
---|
177 | @remarks
|
---|
178 | Format is "x y z" ie. 3 Real components, space delimited. Failure to parse returns
|
---|
179 | Vector3::ZERO.
|
---|
180 | */
|
---|
181 | static Vector3 parseVector3(const String& val);
|
---|
182 | /** Parses a Matrix3 out of a String.
|
---|
183 | @remarks
|
---|
184 | Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc.
|
---|
185 | Failure to parse returns Matrix3::IDENTITY.
|
---|
186 | */
|
---|
187 | static Matrix3 parseMatrix3(const String& val);
|
---|
188 | /** Parses a Matrix4 out of a String.
|
---|
189 | @remarks
|
---|
190 | Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where
|
---|
191 | '01' means row 0 column 1 etc. Failure to parse returns Matrix4::IDENTITY.
|
---|
192 | */
|
---|
193 | static Matrix4 parseMatrix4(const String& val);
|
---|
194 | /** Parses a Quaternion out of a String.
|
---|
195 | @remarks
|
---|
196 | Format is "x y z w" (i.e. 4x Real values, space delimited).
|
---|
197 | Failure to parse returns Quaternion::IDENTITY.
|
---|
198 |
|
---|
199 | */
|
---|
200 | static Quaternion parseQuaternion(const String& val);
|
---|
201 | /** Parses a ColourValue out of a String.
|
---|
202 | @remarks
|
---|
203 | Format is "r g b a" (i.e. 4x Real values, space delimited), or "r g b" which implies
|
---|
204 | an alpha value of 1.0 (opaque). Failure to parse returns ColourValue::Black.
|
---|
205 | */
|
---|
206 | static ColourValue parseColourValue(const String& val);
|
---|
207 |
|
---|
208 | /** Pareses a StringVector from a string.
|
---|
209 | @remarks
|
---|
210 | Strings must not contain spaces since space is used as a delimeter in
|
---|
211 | the output.
|
---|
212 | */
|
---|
213 | static StringVector parseStringVector(const String& val);
|
---|
214 | };
|
---|
215 |
|
---|
216 |
|
---|
217 | }
|
---|
218 |
|
---|
219 |
|
---|
220 |
|
---|
221 | #endif
|
---|
222 |
|
---|