Ogre::StringConverter Class Reference
Core » General

Class for converting the core Ogre data types to/from Strings. More...

`#include <OgreStringConverter.h>`

## Static Public Member Functions

static String | getDefaultStringLocale (void)
static bool | isNumber (const String &val)
| Checks the String is a valid number value. More...
static bool | isUseLocale ()
static Radian | parseAngle (const String &val, Radian defaultValue=Radian(0))
| Converts a String to a Angle. More...
static bool | parseBool (const String &val, bool defaultValue=0)
| Converts a String to a boolean. More...
static ColourValue | parseColourValue (const String &val, const ColourValue &defaultValue=ColourValue::Black)
| Parses a ColourValue out of a String. More...
static int | parseInt (const String &val, int defaultValue=0)
| Converts a String to a whole number. More...
static long | parseLong (const String &val, long defaultValue=0)
| Converts a String to a whole number. More...
static Matrix3 | parseMatrix3 (const String &val, const Matrix3 &defaultValue=Matrix3::IDENTITY)
| Parses a Matrix3 out of a String. More...
static Matrix4 | parseMatrix4 (const String &val, const Matrix4 &defaultValue=Matrix4::IDENTITY)
| Parses a Matrix4 out of a String. More...
static Quaternion | parseQuaternion (const String &val, const Quaternion &defaultValue=Quaternion::IDENTITY)
| Parses a Quaternion out of a String. More...
static Real | parseReal (const String &val, Real defaultValue=0)
| Converts a String to a Real. More...
static size_t | parseSizeT (const String &val, size_t defaultValue=0)
| Converts a String to size_t. More...
static StringVector | parseStringVector (const String &val)
| Parses a StringVector from a string. More...
static unsigned int | parseUnsignedInt (const String &val, unsigned int defaultValue=0)
| Converts a String to a whole number. More...
static unsigned long | parseUnsignedLong (const String &val, unsigned long defaultValue=0)
| Converts a String to a whole number. More...
static Vector2 | parseVector2 (const String &val, const Vector2 &defaultValue=Vector2::ZERO)
| Parses a Vector2 out of a String. More...
static Vector3 | parseVector3 (const String &val, const Vector3 &defaultValue=Vector3::ZERO)
| Parses a Vector3 out of a String. More...
static Vector4 | parseVector4 (const String &val, const Vector4 &defaultValue=Vector4::ZERO)
| Parses a Vector4 out of a String. More...
static void | setDefaultStringLocale (String loc)
static void | setUseLocale (bool useLocale)
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. More...
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. More...
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. More...
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. More...
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. More...
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. More...
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. More...
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. More...
static String | toString (bool val, bool yesNo=false)
| Converts a boolean to a String. More...
static String | toString (const Vector2 &val)
| Converts a Vector2 to a String. More...
static String | toString (const Vector3 &val)
| Converts a Vector3 to a String. More...
static String | toString (const Vector4 &val)
| Converts a Vector4 to a String. More...
static String | toString (const Matrix3 &val)
| Converts a Matrix3 to a String. More...
static String | toString (const Matrix4 &val)
| Converts a Matrix4 to a String. More...
static String | toString (const Quaternion &val)
| Converts a Quaternion to a String. More...
static String | toString (const ColourValue &val)
| Converts a ColourValue to a String. More...
static String | toString (const StringVector &val)
| Converts a StringVector to a string. More...

## Static Protected Attributes

static String | msDefaultStringLocale
static std::locale | msLocale
static bool | msUseLocale

## Detailed Description

Class for converting the core Ogre data types to/from Strings.

Remarks
  The code for converting values to and from strings is here as a separate class to avoid coupling String to other datatypes (and vice-versa) which reduces compilation dependency: important given how often the core types are used.

  This class is mainly used for parsing settings in text files. External applications can also use it to interface with classes which use the StringInterface template class.

  The String formats of each of the major types is listed with the methods. The basic types like int and Real just use the underlying C runtime library atof and atoi family methods, however custom types like Vector3, ColourValue and Matrix4 are also supported by this class using custom formats.

Author
  Steve Streeting

Definition at line 68 of file OgreStringConverter.h.

## Member Function Documentation

## getDefaultStringLocale()

static String Ogre::StringConverter::getDefaultStringLocale | ( | void |  | ) |

static

Definition at line 283 of file OgreStringConverter.h.

## isNumber()

static bool Ogre::StringConverter::isNumber | ( | const String & | val | ) |

static

Checks the String is a valid number value.

## isUseLocale()

static bool Ogre::StringConverter::isUseLocale | ( |  | ) |

static

Definition at line 287 of file OgreStringConverter.h.

## parseAngle()

static Radian Ogre::StringConverter::parseAngle | ( | const String & | val,
|  | Radian | defaultValue = `Radian(0)`
| ) |  |

static

Converts a String to a Angle.

Returns
  0.0 if the value could not be parsed, otherwise the Angle version of the String.

Definition at line 190 of file OgreStringConverter.h.

References Ogre::ColourValue::Black, Ogre::Matrix3::IDENTITY, Ogre::Quaternion::IDENTITY, Ogre::Matrix4::IDENTITY, Ogre::Vector4::ZERO, Ogre::Vector2::ZERO, and Ogre::Vector3::ZERO.

## parseBool()

static bool Ogre::StringConverter::parseBool | ( | const String & | val,
|  | bool | defaultValue = `0`
| ) |  |

static

Converts a String to a boolean.

Remarks
  Returns true if case-insensitive match of the start of the string matches "true", "yes" or "1", false otherwise.

## parseColourValue()

static ColourValue Ogre::StringConverter::parseColourValue | ( | const String & | val,
|  | const ColourValue & | defaultValue = `ColourValue::Black`
| ) |  |

static

Parses a ColourValue out of a String.

Remarks
  Format is "r g b a" (i.e. 4x Real values, space delimited), or "r g b" which implies an alpha value of 1.0 (opaque). Failure to parse returns ColourValue::Black.

## parseInt()

static int Ogre::StringConverter::parseInt | ( | const String & | val,
|  | int | defaultValue = `0`
| ) |  |

static

Converts a String to a whole number.

Returns
  0.0 if the value could not be parsed, otherwise the numeric version of the String.

Referenced by Ogre::DriverVersion::fromString().

## parseLong()

static long Ogre::StringConverter::parseLong | ( | const String & | val,
|  | long | defaultValue = `0`
| ) |  |

static

Converts a String to a whole number.

Returns
  0.0 if the value could not be parsed, otherwise the numeric version of the String.

## parseMatrix3()

static Matrix3 Ogre::StringConverter::parseMatrix3 | ( | const String & | val,
|  | const Matrix3 & | defaultValue = `Matrix3::IDENTITY`
| ) |  |

static

Parses a Matrix3 out of a String.

Remarks
  Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc. Failure to parse returns Matrix3::IDENTITY.

## parseMatrix4()

static Matrix4 Ogre::StringConverter::parseMatrix4 | ( | const String & | val,
|  | const Matrix4 & | defaultValue = `Matrix4::IDENTITY`
| ) |  |

static

Parses a Matrix4 out of a String.

Remarks
  Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where '01' means row 0 column 1 etc. Failure to parse returns Matrix4::IDENTITY.

## parseQuaternion()

static Quaternion Ogre::StringConverter::parseQuaternion | ( | const String & | val,
|  | const Quaternion & | defaultValue = `Quaternion::IDENTITY`
| ) |  |

static

Parses a Quaternion out of a String.

Remarks
  Format is "w x y z" (i.e. 4x Real values, space delimited). Failure to parse returns Quaternion::IDENTITY.

## parseReal()

static Real Ogre::StringConverter::parseReal | ( | const String & | val,
|  | Real | defaultValue = `0`
| ) |  |

static

Converts a String to a Real.

Returns
  0.0 if the value could not be parsed, otherwise the Real version of the String.

## parseSizeT()

static size_t Ogre::StringConverter::parseSizeT | ( | const String & | val,
|  | size_t | defaultValue = `0`
| ) |  |

static

Converts a String to size_t.

Returns
  defaultValue if the value could not be parsed, otherwise the numeric version of the String.

## parseStringVector()

static StringVector Ogre::StringConverter::parseStringVector | ( | const String & | val | ) |

static

Parses a StringVector from a string.

Remarks
  Strings must not contain spaces since space is used as a delimiter in the output.

## parseUnsignedInt()

static unsigned int Ogre::StringConverter::parseUnsignedInt | ( | const String & | val,
|  | unsigned int | defaultValue = `0`
| ) |  |

static

Converts a String to a whole number.

Returns
  0.0 if the value could not be parsed, otherwise the numeric version of the String.

## parseUnsignedLong()

static unsigned long Ogre::StringConverter::parseUnsignedLong | ( | const String & | val,
|  | unsigned long | defaultValue = `0`
| ) |  |

static

Converts a String to a whole number.

Returns
  0.0 if the value could not be parsed, otherwise the numeric version of the String.

## parseVector2()

static Vector2 Ogre::StringConverter::parseVector2 | ( | const String & | val,
|  | const Vector2 & | defaultValue = `Vector2::ZERO`
| ) |  |

static

Parses a Vector2 out of a String.

Remarks
  Format is "x y" ie. 2 Real components, space delimited. Failure to parse returns Vector2::ZERO.

## parseVector3()

static Vector3 Ogre::StringConverter::parseVector3 | ( | const String & | val,
|  | const Vector3 & | defaultValue = `Vector3::ZERO`
| ) |  |

static

Parses a Vector3 out of a String.

Remarks
  Format is "x y z" ie. 3 Real components, space delimited. Failure to parse returns Vector3::ZERO.

## parseVector4()

static Vector4 Ogre::StringConverter::parseVector4 | ( | const String & | val,
|  | const Vector4 & | defaultValue = `Vector4::ZERO`
| ) |  |

static

Parses a Vector4 out of a String.

Remarks
  Format is "x y z w" ie. 4 Real components, space delimited. Failure to parse returns Vector4::ZERO.

## setDefaultStringLocale()

static void Ogre::StringConverter::setDefaultStringLocale | ( | String | loc | ) |

static

Definition at line 277 of file OgreStringConverter.h.

## setUseLocale()

static void Ogre::StringConverter::setUseLocale | ( | bool | useLocale | ) |

static

Definition at line 285 of file OgreStringConverter.h.

## toString() [1/17]

static String Ogre::StringConverter::toString | ( | Real | val,
|  | unsigned short | precision = `6`,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a Real to a String.

## toString() [2/17]

static String Ogre::StringConverter::toString | ( | double | val,
|  | unsigned short | precision = `6`,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a double to a String.

## toString() [3/17]

static String Ogre::StringConverter::toString | ( | Radian | val,
|  | unsigned short | precision = `6`,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a Radian to a String.

Definition at line 88 of file OgreStringConverter.h.

References Ogre::Radian::valueAngleUnits().

## toString() [4/17]

static String Ogre::StringConverter::toString | ( | Degree | val,
|  | unsigned short | precision = `6`,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a Degree to a String.

Definition at line 95 of file OgreStringConverter.h.

References Ogre::Degree::valueAngleUnits().

## toString() [5/17]

static String Ogre::StringConverter::toString | ( | int | val,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts an int to a String.

## toString() [6/17]

static String Ogre::StringConverter::toString | ( | size_t | val,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a size_t to a String.

## toString() [7/17]

static String Ogre::StringConverter::toString | ( | unsigned long | val,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts an unsigned long to a String.

## toString() [8/17]

static String Ogre::StringConverter::toString | ( | long | val,
|  | unsigned short | width = `0`,
|  | char | fill = `' '`,
|  | std::ios::fmtflags | flags = `std::ios::fmtflags(0)`
| ) |  |

static

Converts a long to a String.

## toString() [9/17]

static String Ogre::StringConverter::toString | ( | bool | val,
|  | bool | yesNo = `false`
| ) |  |

static

Converts a boolean to a String.

Parameters

  yesNo | If set to true, result is 'yes' or 'no' instead of 'true' or 'false'

## toString() [10/17]

static String Ogre::StringConverter::toString | ( | const Vector2 & | val | ) |

static

Converts a Vector2 to a String.

Remarks
  Format is "x y" (i.e. 2x Real values, space delimited)

## toString() [11/17]

static String Ogre::StringConverter::toString | ( | const Vector3 & | val | ) |

static

Converts a Vector3 to a String.

Remarks
  Format is "x y z" (i.e. 3x Real values, space delimited)

## toString() [12/17]

static String Ogre::StringConverter::toString | ( | const Vector4 & | val | ) |

static

Converts a Vector4 to a String.

Remarks
  Format is "x y z w" (i.e. 4x Real values, space delimited)

## toString() [13/17]

static String Ogre::StringConverter::toString | ( | const Matrix3 & | val | ) |

static

Converts a Matrix3 to a String.

Remarks
  Format is "00 01 02 10 11 12 20 21 22" where '01' means row 0 column 1 etc.

## toString() [14/17]

static String Ogre::StringConverter::toString | ( | const Matrix4 & | val | ) |

static

Converts a Matrix4 to a String.

Remarks
  Format is "00 01 02 03 10 11 12 13 20 21 22 23 30 31 32 33" where '01' means row 0 column 1 etc.

## toString() [15/17]

static String Ogre::StringConverter::toString | ( | const Quaternion & | val | ) |

static

Converts a Quaternion to a String.

Remarks
  Format is "w x y z" (i.e. 4x Real values, space delimited)

## toString() [16/17]

static String Ogre::StringConverter::toString | ( | const ColourValue & | val | ) |

static

Converts a ColourValue to a String.

Remarks
  Format is "r g b a" (i.e. 4x Real values, space delimited).

## toString() [17/17]

static String Ogre::StringConverter::toString | ( | const StringVector & | val | ) |

static

Converts a StringVector to a string.

Remarks
  Strings must not contain spaces since space is used as a delimiter in the output.

## Member Data Documentation

## msDefaultStringLocale

String Ogre::StringConverter::msDefaultStringLocale

static protected

Definition at line 291 of file OgreStringConverter.h.

## msLocale

std::locale Ogre::StringConverter::msLocale

static protected

Definition at line 292 of file OgreStringConverter.h.

## msUseLocale

bool Ogre::StringConverter::msUseLocale

static protected

Definition at line 293 of file OgreStringConverter.h.

The documentation for this class was generated from the following file:

- OgreStringConverter.h

Copyright © 2012 Torus Knot Software Ltd
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.