LTL  2.0.x
Static Public Member Functions | Static Protected Member Functions | Static Protected Attributes | List of all members
util::StringFactory Class Reference

This class returns a number in the requested type. More...

Static Public Member Functions

static string toString (const double xd, const int width=DBL_DIG+7, const int precision=DBL_DIG, const char format= 'd')
 
static string toString (const float xd, const int width=FLT_DIG+7, const int precision=FLT_DIG, const char format= 'd')
 
static string toString (const long xd, const int width=((sizeof(long)*8)/3)+1)
 
static string toString (const int xd, const int width=((sizeof(int)*8)/3)+1)
 
static string toMinSecString (const double xd, const int precision=0)
 Return xd in dd:mm:ss[.sss] format. More...
 
static int toInt (const string &xs)
 Convert xs to integer number. More...
 
static long toLong (const string &xs)
 Convert xs to long integer number. More...
 
static float toFloat (const string &xs)
 Convert xs to float number. More...
 
static double toDouble (string xs)
 Convert xs to double number. More...
 

Static Protected Member Functions

template<class T >
static string floatToString (const T xd, const int width, const int precision, const char format)
 
template<class T >
static string intToString (const T xd, const int width)
 
static void changeFormat (ostringstream &s, const char format)
 

Static Protected Attributes

static const string factory_text
 
static const string error_text
 

Detailed Description

This class returns a number in the requested type.

In case of string output this is a right adjusted string of selected length and (if possible) precision. The string is filled with leading blanks to match width.

Member Function Documentation

template<class T >
string util::StringFactory::floatToString ( const T  xd,
const int  width,
const int  precision,
const char  format 
)
inlinestaticprotected

Convert float/double to string

Parameters
format,:char to select the floatfield format flag
  • 'd': default floating-point notation
  • 'f': fixed-point notation
  • 'e': scientific notation

References error_text, and factory_text.

template<class T >
string util::StringFactory::intToString ( const T  xd,
const int  width 
)
inlinestaticprotected

References error_text, and factory_text.

static void util::StringFactory::changeFormat ( ostringstream &  s,
const char  format 
)
staticprotected

set the floatfield format flag

Parameters
s,:ostringstream where to write
format,:char to select the floatfield format flag
  • 'd': default floating-point notation
  • 'f': fixed-point notation
  • 'e': scientific notation
static string util::StringFactory::toString ( const double  xd,
const int  width = DBL_DIG+7,
const int  precision = DBL_DIG,
const char  format = 'd' 
)
static

Convert number to string

Parameters
format,:(for double and float only) char to select the floatfield format flag
  • 'd': default floating-point notation
  • 'f': fixed-point notation
  • 'e': scientific notation
static string util::StringFactory::toString ( const float  xd,
const int  width = FLT_DIG+7,
const int  precision = FLT_DIG,
const char  format = 'd' 
)
static
static string util::StringFactory::toString ( const long  xd,
const int  width = ((sizeof(long)*8)/3)+1 
)
static
static string util::StringFactory::toString ( const int  xd,
const int  width = ((sizeof(int)*8)/3)+1 
)
static
static string util::StringFactory::toMinSecString ( const double  xd,
const int  precision = 0 
)
static

Return xd in dd:mm:ss[.sss] format.

Precision gives No second decimals.

static int util::StringFactory::toInt ( const string &  xs)
inlinestatic

Convert xs to integer number.

static long util::StringFactory::toLong ( const string &  xs)
inlinestatic

Convert xs to long integer number.

static float util::StringFactory::toFloat ( const string &  xs)
inlinestatic

Convert xs to float number.

dd:mm:ss[.sss] strings are automatically recognized.

References toDouble().

static double util::StringFactory::toDouble ( string  xs)
static

Convert xs to double number.

dd:mm:ss[.sss] strings are automatically recognized.

Referenced by toFloat().

Member Data Documentation

const string util::StringFactory::factory_text
staticprotected

Referenced by floatToString(), and intToString().

const string util::StringFactory::error_text
staticprotected

Referenced by floatToString(), and intToString().