source: OGRE/trunk/ogrenew/OgreMain/include/OgreStringConverter.h @ 692

Revision 692, 9.7 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4    (Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://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
34namespace 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        #if OGRE_COMPILER == OGRE_COMPILER_MSVC
89                /** Converts an unsigned long to a String. */
90                static String toString(unsigned long val,
91                    unsigned short width = 0, char fill = ' ',
92                    std::ios::fmtflags flags = std::ios::fmtflags(0) );
93
94        #endif
95#else
96        /** Converts a size_t to a String. */
97        static String toString(size_t val,
98            unsigned short width = 0, char fill = ' ',
99            std::ios::fmtflags flags = std::ios::fmtflags(0) );
100        /** Converts an unsigned long to a String. */
101        static String toString(unsigned long val,
102            unsigned short width = 0, char fill = ' ',
103            std::ios::fmtflags flags = std::ios::fmtflags(0) );
104#endif
105        /** Converts a long to a String. */
106        static String toString(long val,
107            unsigned short width = 0, char fill = ' ',
108            std::ios::fmtflags flags = std::ios::fmtflags(0) );
109        /** Converts a boolean to a String.
110        @param yesNo If set to true, result is 'yes' or 'no' instead of 'true' or 'false'
111        */
112        static String toString(bool val, bool yesNo = false);
113        /** Converts a Vector3 to a String.
114        @remarks
115            Format is "x y z" (i.e. 3x Real values, space delimited)
116        */
117        static String toString(const Vector3& val);
118        /** Converts a Matrix3 to a String.
119        @remarks
120            Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc.
121        */
122        static String toString(const Matrix3& val);
123        /** Converts a Matrix4 to a String.
124        @remarks
125            Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where
126            '01' means row 0 column 1 etc.
127        */
128        static String toString(const Matrix4& val);
129        /** Converts a Quaternion to a String.
130        @remarks
131            Format is "w x y z" (i.e. 4x Real values, space delimited)
132        */
133        static String toString(const Quaternion& val);
134        /** Converts a ColourValue to a String.
135        @remarks
136            Format is "r g b a" (i.e. 4x Real values, space delimited).
137        */
138        static String toString(const ColourValue& val);
139        /** Converts a StringVector to a string.
140        @remarks
141            Strings must not contain spaces since space is used as a delimeter in
142            the output.
143        */
144        static String toString(const StringVector& val);
145
146        /** Converts a String to a Real.
147        @returns
148            0.0 if the value could not be parsed, otherwise the Real version of the String.
149        */
150        static Real parseReal(const String& val);
151        /** Converts a String to a Angle.
152        @returns
153            0.0 if the value could not be parsed, otherwise the Angle version of the String.
154        */
155        static inline Radian parseAngle(const String& val) {
156                        return Angle(parseReal(val));
157                }
158        /** Converts a String to a whole number.
159        @returns
160            0.0 if the value could not be parsed, otherwise the numeric version of the String.
161        */
162        static int parseInt(const String& val);
163        /** Converts a String to a whole number.
164        @returns
165            0.0 if the value could not be parsed, otherwise the numeric version of the String.
166        */
167        static unsigned int parseUnsignedInt(const String& val);
168        /** Converts a String to a whole number.
169        @returns
170            0.0 if the value could not be parsed, otherwise the numeric version of the String.
171        */
172        static long parseLong(const String& val);
173        /** Converts a String to a whole number.
174        @returns
175            0.0 if the value could not be parsed, otherwise the numeric version of the String.
176        */
177        static unsigned long parseUnsignedLong(const String& val);
178        /** Converts a String to a boolean.
179        @remarks
180            Accepts 'true' or 'false' as input.
181        */
182        static bool parseBool(const String& val);
183        /** Parses a Vector3 out of a String.
184        @remarks
185            Format is "x y z" ie. 3 Real components, space delimited. Failure to parse returns
186            Vector3::ZERO.
187        */
188        static Vector3 parseVector3(const String& val);
189        /** Parses a Matrix3 out of a String.
190        @remarks
191            Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc.
192            Failure to parse returns Matrix3::IDENTITY.
193        */
194        static Matrix3 parseMatrix3(const String& val);
195        /** Parses a Matrix4 out of a String.
196        @remarks
197            Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where
198            '01' means row 0 column 1 etc. Failure to parse returns Matrix4::IDENTITY.
199        */
200        static Matrix4 parseMatrix4(const String& val);
201        /** Parses a Quaternion out of a String.
202        @remarks
203            Format is "w x y z" (i.e. 4x Real values, space delimited).
204            Failure to parse returns Quaternion::IDENTITY.
205
206        */
207        static Quaternion parseQuaternion(const String& val);
208        /** Parses a ColourValue out of a String.
209        @remarks
210            Format is "r g b a" (i.e. 4x Real values, space delimited), or "r g b" which implies
211            an alpha value of 1.0 (opaque). Failure to parse returns ColourValue::Black.
212        */
213        static ColourValue parseColourValue(const String& val);
214
215        /** Pareses a StringVector from a string.
216        @remarks
217            Strings must not contain spaces since space is used as a delimeter in
218            the output.
219        */
220        static StringVector parseStringVector(const String& val);
221    };
222
223
224}
225
226
227
228#endif
229
Note: See TracBrowser for help on using the repository browser.