OgreStringConverter.h
Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004     (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2013 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 
00029 #ifndef __StringConverter_H__
00030 #define __StringConverter_H__
00031 
00032 #include "OgrePrerequisites.h"
00033 #include "OgreStringVector.h"
00034 #include "OgreColourValue.h"
00035 #include "OgreMath.h"
00036 #include "OgreMatrix3.h"
00037 #include "OgreMatrix4.h"
00038 #include "OgreQuaternion.h"
00039 #include "OgreVector2.h"
00040 #include "OgreVector3.h"
00041 #include "OgreVector4.h"
00042 
00043 namespace Ogre {
00044 
00068     class _OgreExport StringConverter
00069     {
00070     public:
00071 
00073         static String toString(Real val, unsigned short precision = 6, 
00074             unsigned short width = 0, char fill = ' ', 
00075             std::ios::fmtflags flags = std::ios::fmtflags(0));
00076 #if OGRE_DOUBLE_PRECISION == 1
00077 
00078         static String toString(float val, unsigned short precision = 6,
00079                                unsigned short width = 0, char fill = ' ',
00080                                std::ios::fmtflags flags = std::ios::fmtflags(0));
00081 #else
00082 
00083         static String toString(double val, unsigned short precision = 6,
00084                                unsigned short width = 0, char fill = ' ',
00085                                std::ios::fmtflags flags = std::ios::fmtflags(0));
00086 #endif
00087 
00088         static String toString(Radian val, unsigned short precision = 6, 
00089             unsigned short width = 0, char fill = ' ', 
00090             std::ios::fmtflags flags = std::ios::fmtflags(0))
00091         {
00092             return toString(val.valueAngleUnits(), precision, width, fill, flags);
00093         }
00095         static String toString(Degree val, unsigned short precision = 6, 
00096             unsigned short width = 0, char fill = ' ', 
00097             std::ios::fmtflags flags = std::ios::fmtflags(0))
00098         {
00099             return toString(val.valueAngleUnits(), precision, width, fill, flags);
00100         }
00102         static String toString(int val, unsigned short width = 0, 
00103             char fill = ' ', 
00104             std::ios::fmtflags flags = std::ios::fmtflags(0));
00105 #if OGRE_PLATFORM != OGRE_PLATFORM_NACL &&  ( OGRE_ARCH_TYPE == OGRE_ARCHITECTURE_64 || OGRE_PLATFORM == OGRE_PLATFORM_APPLE || OGRE_PLATFORM == OGRE_PLATFORM_APPLE_IOS )
00106 
00107         static String toString(unsigned int val, 
00108             unsigned short width = 0, char fill = ' ', 
00109             std::ios::fmtflags flags = std::ios::fmtflags(0));
00111         static String toString(size_t val, 
00112             unsigned short width = 0, char fill = ' ', 
00113             std::ios::fmtflags flags = std::ios::fmtflags(0));
00114         #if OGRE_COMPILER == OGRE_COMPILER_MSVC
00115 
00116         static String toString(unsigned long val, 
00117             unsigned short width = 0, char fill = ' ', 
00118             std::ios::fmtflags flags = std::ios::fmtflags(0));
00119         #endif
00120 #else
00121 
00122         static String toString(size_t val, 
00123             unsigned short width = 0, char fill = ' ', 
00124             std::ios::fmtflags flags = std::ios::fmtflags(0));
00126         static String toString(unsigned long val, 
00127             unsigned short width = 0, char fill = ' ', 
00128             std::ios::fmtflags flags = std::ios::fmtflags(0));
00129 #endif
00130 
00131         static String toString(long val, 
00132             unsigned short width = 0, char fill = ' ', 
00133             std::ios::fmtflags flags = std::ios::fmtflags(0));
00137         static String toString(bool val, bool yesNo = false);
00142         static String toString(const Vector2& val);
00147         static String toString(const Vector3& val);
00152         static String toString(const Vector4& val);
00157         static String toString(const Matrix3& val);
00163         static String toString(const Matrix4& val);
00168         static String toString(const Quaternion& val);
00173         static String toString(const ColourValue& val);
00179         static String toString(const StringVector& val);
00180 
00185         static Real parseReal(const String& val, Real defaultValue = 0);
00190         static inline Radian parseAngle(const String& val, Radian defaultValue = Radian(0)) {
00191             return Angle(parseReal(val, defaultValue.valueRadians()));
00192         }
00197         static int parseInt(const String& val, int defaultValue = 0);
00202         static unsigned int parseUnsignedInt(const String& val, unsigned int defaultValue = 0);
00207         static long parseLong(const String& val, long defaultValue = 0);
00212         static unsigned long parseUnsignedLong(const String& val, unsigned long defaultValue = 0);
00217         static size_t parseSizeT(const String& val, size_t defaultValue = 0);
00223         static bool parseBool(const String& val, bool defaultValue = 0);
00229         static Vector2 parseVector2(const String& val, const Vector2& defaultValue = Vector2::ZERO);
00235         static Vector3 parseVector3(const String& val, const Vector3& defaultValue = Vector3::ZERO);
00241         static Vector4 parseVector4(const String& val, const Vector4& defaultValue = Vector4::ZERO);
00247         static Matrix3 parseMatrix3(const String& val, const Matrix3& defaultValue = Matrix3::IDENTITY);
00253         static Matrix4 parseMatrix4(const String& val, const Matrix4& defaultValue = Matrix4::IDENTITY);
00259         static Quaternion parseQuaternion(const String& val, const Quaternion& defaultValue = Quaternion::IDENTITY);
00265         static ColourValue parseColourValue(const String& val, const ColourValue& defaultValue = ColourValue::Black);
00266 
00272         static StringVector parseStringVector(const String& val);
00274         static bool isNumber(const String& val);
00275 
00276         //-----------------------------------------------------------------------
00277         static void setDefaultStringLocale(String loc)
00278         {
00279             msDefaultStringLocale = loc;
00280             msLocale = std::locale(msDefaultStringLocale.c_str());
00281         }
00282         //-----------------------------------------------------------------------
00283         static String getDefaultStringLocale(void) { return msDefaultStringLocale; }
00284         //-----------------------------------------------------------------------
00285         static void setUseLocale(bool useLocale) { msUseLocale = useLocale; }
00286         //-----------------------------------------------------------------------
00287         static bool isUseLocale() { return msUseLocale; }
00288         //-----------------------------------------------------------------------
00289 
00290     protected:
00291         static String msDefaultStringLocale;
00292         static std::locale msLocale;
00293         static bool msUseLocale;
00294     };
00295 
00299 }
00300 
00301 
00302 
00303 #endif
00304 

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:47