OGRE  1.9.0
OgreStringConverter.h
Go to the documentation of this file.
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-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28
29#ifndef __StringConverter_H__
30#define __StringConverter_H__
31
32#include "OgrePrerequisites.h"
33#include "OgreStringVector.h"
34#include "OgreColourValue.h"
35#include "OgreMath.h"
36#include "OgreMatrix3.h"
37#include "OgreMatrix4.h"
38#include "OgreQuaternion.h"
39#include "OgreVector2.h"
40#include "OgreVector3.h"
41#include "OgreVector4.h"
42
43namespace Ogre {
44
69 {
70 public:
71
73 static String toString(Real val, unsigned short precision = 6,
74 unsigned short width = 0, char fill = ' ',
75 std::ios::fmtflags flags = std::ios::fmtflags(0));
76#if OGRE_DOUBLE_PRECISION == 1
78 static String toString(float val, unsigned short precision = 6,
79 unsigned short width = 0, char fill = ' ',
80 std::ios::fmtflags flags = std::ios::fmtflags(0));
81#else
83 static String toString(double val, unsigned short precision = 6,
84 unsigned short width = 0, char fill = ' ',
85 std::ios::fmtflags flags = std::ios::fmtflags(0));
86#endif
88 static String toString(Radian val, unsigned short precision = 6,
89 unsigned short width = 0, char fill = ' ',
90 std::ios::fmtflags flags = std::ios::fmtflags(0))
91 {
92 return toString(val.valueAngleUnits(), precision, width, fill, flags);
93 }
95 static String toString(Degree val, unsigned short precision = 6,
96 unsigned short width = 0, char fill = ' ',
97 std::ios::fmtflags flags = std::ios::fmtflags(0))
98 {
99 return toString(val.valueAngleUnits(), precision, width, fill, flags);
100 }
102 static String toString(int val, unsigned short width = 0,
103 char fill = ' ',
104 std::ios::fmtflags flags = std::ios::fmtflags(0));
105#if OGRE_PLATFORM != OGRE_PLATFORM_NACL && ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS )
107 static String toString(unsigned int val,
108 unsigned short width = 0, char fill = ' ',
109 std::ios::fmtflags flags = std::ios::fmtflags(0));
111 static String toString(size_t val,
112 unsigned short width = 0, char fill = ' ',
113 std::ios::fmtflags flags = std::ios::fmtflags(0));
114 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
116 static String toString(unsigned long val,
117 unsigned short width = 0, char fill = ' ',
118 std::ios::fmtflags flags = std::ios::fmtflags(0));
119 #endif
120#else
122 static String toString(size_t val,
123 unsigned short width = 0, char fill = ' ',
124 std::ios::fmtflags flags = std::ios::fmtflags(0));
126 static String toString(unsigned long val,
127 unsigned short width = 0, char fill = ' ',
128 std::ios::fmtflags flags = std::ios::fmtflags(0));
129#endif
131 static String toString(long val,
132 unsigned short width = 0, char fill = ' ',
133 std::ios::fmtflags flags = std::ios::fmtflags(0));
137 static String toString(bool val, bool yesNo = false);
142 static String toString(const Vector2& val);
147 static String toString(const Vector3& val);
152 static String toString(const Vector4& val);
157 static String toString(const Matrix3& val);
163 static String toString(const Matrix4& val);
168 static String toString(const Quaternion& val);
173 static String toString(const ColourValue& val);
179 static String toString(const StringVector& val);
180
185 static Real parseReal(const String& val, Real defaultValue = 0);
190 static inline Radian parseAngle(const String& val, Radian defaultValue = Radian(0)) {
191 return Angle(parseReal(val, defaultValue.valueRadians()));
192 }
197 static int parseInt(const String& val, int defaultValue = 0);
202 static unsigned int parseUnsignedInt(const String& val, unsigned int defaultValue = 0);
207 static long parseLong(const String& val, long defaultValue = 0);
212 static unsigned long parseUnsignedLong(const String& val, unsigned long defaultValue = 0);
217 static size_t parseSizeT(const String& val, size_t defaultValue = 0);
223 static bool parseBool(const String& val, bool defaultValue = 0);
229 static Vector2 parseVector2(const String& val, const Vector2& defaultValue = Vector2::ZERO);
235 static Vector3 parseVector3(const String& val, const Vector3& defaultValue = Vector3::ZERO);
241 static Vector4 parseVector4(const String& val, const Vector4& defaultValue = Vector4::ZERO);
247 static Matrix3 parseMatrix3(const String& val, const Matrix3& defaultValue = Matrix3::IDENTITY);
253 static Matrix4 parseMatrix4(const String& val, const Matrix4& defaultValue = Matrix4::IDENTITY);
259 static Quaternion parseQuaternion(const String& val, const Quaternion& defaultValue = Quaternion::IDENTITY);
265 static ColourValue parseColourValue(const String& val, const ColourValue& defaultValue = ColourValue::Black);
266
274 static bool isNumber(const String& val);
275
276 //-----------------------------------------------------------------------
278 {
279 msDefaultStringLocale = loc;
280 msLocale = std::locale(msDefaultStringLocale.c_str());
281 }
282 //-----------------------------------------------------------------------
283 static String getDefaultStringLocale(void) { return msDefaultStringLocale; }
284 //-----------------------------------------------------------------------
285 static void setUseLocale(bool useLocale) { msUseLocale = useLocale; }
286 //-----------------------------------------------------------------------
287 static bool isUseLocale() { return msUseLocale; }
288 //-----------------------------------------------------------------------
289
290 protected:
292 static std::locale msLocale;
293 static bool msUseLocale;
294 };
295
299}
300
301
302
303#endif
304
#define _OgreExport
Wrapper class which identifies a value as the currently default angle type, as defined by Math::setAn...
Definition OgreMath.h:151
Class representing colour.
Wrapper class which indicates a given angle value is in Degrees.
Definition OgreMath.h:99
A 3x3 matrix which can represent rotations around axes.
Definition OgreMatrix3.h:69
Class encapsulating a standard 4x4 homogeneous matrix.
Definition OgreMatrix4.h:79
Implementation of a Quaternion, i.e.
Wrapper class which indicates a given angle value is in Radians.
Definition OgreMath.h:48
Reference-counted shared pointer, used for objects where implicit destruction is required.
Class for converting the core Ogre data types to/from Strings.
static StringVector parseStringVector(const String &val)
Parses a StringVector from a string.
static Vector2 parseVector2(const String &val, const Vector2 &defaultValue=Vector2::ZERO)
Parses a Vector2 out of a String.
static size_t parseSizeT(const String &val, size_t defaultValue=0)
Converts a String to size_t.
static ColourValue parseColourValue(const String &val, const ColourValue &defaultValue=ColourValue::Black)
Parses a ColourValue out of a String.
static String toString(size_t val, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a size_t to a String.
static String toString(long val, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a long to a String.
static String toString(int val, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts an int to a String.
static String toString(const ColourValue &val)
Converts a ColourValue to a String.
static long parseLong(const String &val, long defaultValue=0)
Converts a String to a whole number.
static String toString(Real val, unsigned short precision=6, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a Real to a String.
static String msDefaultStringLocale
static String toString(const Vector3 &val)
Converts a Vector3 to a String.
static String toString(const Vector4 &val)
Converts a Vector4 to a String.
static Matrix3 parseMatrix3(const String &val, const Matrix3 &defaultValue=Matrix3::IDENTITY)
Parses a Matrix3 out of a String.
static Vector3 parseVector3(const String &val, const Vector3 &defaultValue=Vector3::ZERO)
Parses a Vector3 out of a String.
static String toString(const Vector2 &val)
Converts a Vector2 to a String.
static std::locale msLocale
static unsigned long parseUnsignedLong(const String &val, unsigned long defaultValue=0)
Converts a String to a whole number.
static void setUseLocale(bool useLocale)
static int parseInt(const String &val, int defaultValue=0)
Converts a String to a whole number.
static Vector4 parseVector4(const String &val, const Vector4 &defaultValue=Vector4::ZERO)
Parses a Vector4 out of a String.
static unsigned int parseUnsignedInt(const String &val, unsigned int defaultValue=0)
Converts a String to a whole number.
static bool parseBool(const String &val, bool defaultValue=0)
Converts a String to a boolean.
static bool isNumber(const String &val)
Checks the String is a valid number value.
static Real parseReal(const String &val, Real defaultValue=0)
Converts a String to a Real.
static Matrix4 parseMatrix4(const String &val, const Matrix4 &defaultValue=Matrix4::IDENTITY)
Parses a Matrix4 out of a String.
static String toString(const Quaternion &val)
Converts a Quaternion to a String.
static String toString(const Matrix4 &val)
Converts a Matrix4 to a String.
static String toString(unsigned long val, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts an unsigned long to a String.
static String toString(Radian val, unsigned short precision=6, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a Radian to a String.
static String toString(bool val, bool yesNo=false)
Converts a boolean to a String.
static String toString(const StringVector &val)
Converts a StringVector to a string.
static String toString(double val, unsigned short precision=6, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a double to a String.
static String getDefaultStringLocale(void)
static String toString(Degree val, unsigned short precision=6, unsigned short width=0, char fill=' ', std::ios::fmtflags flags=std::ios::fmtflags(0))
Converts a Degree to a String.
static Quaternion parseQuaternion(const String &val, const Quaternion &defaultValue=Quaternion::IDENTITY)
Parses a Quaternion out of a String.
static Radian parseAngle(const String &val, Radian defaultValue=Radian(0))
Converts a String to a Angle.
static String toString(const Matrix3 &val)
Converts a Matrix3 to a String.
static void setDefaultStringLocale(String loc)
Standard 2-dimensional vector.
Definition OgreVector2.h:52
Standard 3-dimensional vector.
Definition OgreVector3.h:52
4-dimensional homogeneous vector.
Definition OgreVector4.h:46
Real valueAngleUnits() const
Definition OgreMath.h:722
Real valueAngleUnits() const
Definition OgreMath.h:732
_StringBase String